From b76f3c9e2f84a5d1537911b4e08d4b0d64cb92b7 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Wed, 11 Sep 2019 13:21:47 -0700 Subject: [PATCH] Add generic Patch and Post command Change-Id: Ic1ee2e71ca377f157be3e81306a4a625bd165f54 --- rsdclient/osc/v2/root.py | 66 ++++++++++++++++++++++++++++++++++++++++ rsdclient/v2/root.py | 6 ++++ setup.cfg | 2 ++ 3 files changed, 74 insertions(+) diff --git a/rsdclient/osc/v2/root.py b/rsdclient/osc/v2/root.py index 89b1b2d..939a6fa 100644 --- a/rsdclient/osc/v2/root.py +++ b/rsdclient/osc/v2/root.py @@ -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="", + help="ID of target RSD resource to PATCH.", + ) + parser.add_argument( + "--data", + dest="data", + type=json.loads, + metavar="", + 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="", + help="ID of target RSD resource to POST.", + ) + parser.add_argument( + "--data", + dest="data", + type=json.loads, + metavar="", + 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 + ) + ) diff --git a/rsdclient/v2/root.py b/rsdclient/v2/root.py index 22939fb..f32e14e 100644 --- a/rsdclient/v2/root.py +++ b/rsdclient/v2/root.py @@ -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) diff --git a/setup.cfg b/setup.cfg index 69d9c50..d898bee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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