Add generic Patch and Post command
Change-Id: Ic1ee2e71ca377f157be3e81306a4a625bd165f54
This commit is contained in:
parent
087b31149c
commit
b76f3c9e2f
@ -60,3 +60,69 @@ class DeleteResource(command.Command):
|
||||
for resource in parsed_args.resource:
|
||||
rsd_client.root.delete(resource)
|
||||
print("Resource {0} has been deleted.".format(resource))
|
||||
|
||||
|
||||
class PatchResource(command.Command):
|
||||
"""Issue HTTP PATCH to a target RSD resource."""
|
||||
|
||||
_description = "Issue HTTP PATCH to a target RSD resource"
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(PatchResource, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"resource",
|
||||
metavar="<resource>",
|
||||
help="ID of target RSD resource to PATCH.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--data",
|
||||
dest="data",
|
||||
type=json.loads,
|
||||
metavar="<data>",
|
||||
help=("Payload of PATCH operation."),
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
rsd_client = self.app.client_manager.rsd
|
||||
rsd_client.root.patch(parsed_args.resource, parsed_args.data)
|
||||
print(
|
||||
"PATCH operation to resource {0} is done.".format(
|
||||
parsed_args.resource
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class PostResource(command.Command):
|
||||
"""Issue HTTP POST to a target RSD resource."""
|
||||
|
||||
_description = "Issue HTTP POST to a target RSD resource"
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(PostResource, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"resource",
|
||||
metavar="<resource>",
|
||||
help="ID of target RSD resource to POST.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--data",
|
||||
dest="data",
|
||||
type=json.loads,
|
||||
metavar="<data>",
|
||||
help=("Payload of POST operation."),
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
rsd_client = self.app.client_manager.rsd
|
||||
rsd_client.root.post(parsed_args.resource, parsed_args.data)
|
||||
print(
|
||||
"POST operation to resource {0} is done.".format(
|
||||
parsed_args.resource
|
||||
)
|
||||
)
|
||||
|
@ -31,3 +31,9 @@ class RootManager(base.Manager):
|
||||
|
||||
def delete(self, resource_uri):
|
||||
self.client._conn.delete(resource_uri)
|
||||
|
||||
def patch(self, target_uri, data=None):
|
||||
self.client._conn.patch(target_uri, data=data)
|
||||
|
||||
def post(self, target_uri, data=None):
|
||||
self.client._conn.post(target_uri, data=data)
|
||||
|
@ -30,6 +30,8 @@ openstack.cli.extension =
|
||||
openstack.rsd.v2 =
|
||||
rsd_get = rsdclient.osc.v2.root:GetResource
|
||||
rsd_delete = rsdclient.osc.v2.root:DeleteResource
|
||||
rsd_patch = rsdclient.osc.v2.root:PatchResource
|
||||
rsd_post = rsdclient.osc.v2.root:PostResource
|
||||
|
||||
rsd_node_compose = rsdclient.osc.v2.node:ComposeNode
|
||||
rsd_node_delete = rsdclient.osc.v2.node:DeleteNode
|
||||
|
Loading…
x
Reference in New Issue
Block a user