Browse Source

Add generic Patch and Post command

Change-Id: Ic1ee2e71ca377f157be3e81306a4a625bd165f54
tags/1.0.0
Lin Yang 5 days ago
parent
commit
b76f3c9e2f
3 changed files with 74 additions and 0 deletions
  1. 66
    0
      rsdclient/osc/v2/root.py
  2. 6
    0
      rsdclient/v2/root.py
  3. 2
    0
      setup.cfg

+ 66
- 0
rsdclient/osc/v2/root.py View File

@@ -60,3 +60,69 @@ class DeleteResource(command.Command):
60 60
         for resource in parsed_args.resource:
61 61
             rsd_client.root.delete(resource)
62 62
             print("Resource {0} has been deleted.".format(resource))
63
+
64
+
65
+class PatchResource(command.Command):
66
+    """Issue HTTP PATCH to a target RSD resource."""
67
+
68
+    _description = "Issue HTTP PATCH to a target RSD resource"
69
+
70
+    def get_parser(self, prog_name):
71
+        parser = super(PatchResource, self).get_parser(prog_name)
72
+        parser.add_argument(
73
+            "resource",
74
+            metavar="<resource>",
75
+            help="ID of target RSD resource to PATCH.",
76
+        )
77
+        parser.add_argument(
78
+            "--data",
79
+            dest="data",
80
+            type=json.loads,
81
+            metavar="<data>",
82
+            help=("Payload of PATCH operation."),
83
+        )
84
+
85
+        return parser
86
+
87
+    def take_action(self, parsed_args):
88
+        self.log.debug("take_action(%s)", parsed_args)
89
+        rsd_client = self.app.client_manager.rsd
90
+        rsd_client.root.patch(parsed_args.resource, parsed_args.data)
91
+        print(
92
+            "PATCH operation to resource {0} is done.".format(
93
+                parsed_args.resource
94
+            )
95
+        )
96
+
97
+
98
+class PostResource(command.Command):
99
+    """Issue HTTP POST to a target RSD resource."""
100
+
101
+    _description = "Issue HTTP POST to a target RSD resource"
102
+
103
+    def get_parser(self, prog_name):
104
+        parser = super(PostResource, self).get_parser(prog_name)
105
+        parser.add_argument(
106
+            "resource",
107
+            metavar="<resource>",
108
+            help="ID of target RSD resource to POST.",
109
+        )
110
+        parser.add_argument(
111
+            "--data",
112
+            dest="data",
113
+            type=json.loads,
114
+            metavar="<data>",
115
+            help=("Payload of POST operation."),
116
+        )
117
+
118
+        return parser
119
+
120
+    def take_action(self, parsed_args):
121
+        self.log.debug("take_action(%s)", parsed_args)
122
+        rsd_client = self.app.client_manager.rsd
123
+        rsd_client.root.post(parsed_args.resource, parsed_args.data)
124
+        print(
125
+            "POST operation to resource {0} is done.".format(
126
+                parsed_args.resource
127
+            )
128
+        )

+ 6
- 0
rsdclient/v2/root.py View File

@@ -31,3 +31,9 @@ class RootManager(base.Manager):
31 31
 
32 32
     def delete(self, resource_uri):
33 33
         self.client._conn.delete(resource_uri)
34
+
35
+    def patch(self, target_uri, data=None):
36
+        self.client._conn.patch(target_uri, data=data)
37
+
38
+    def post(self, target_uri, data=None):
39
+        self.client._conn.post(target_uri, data=data)

+ 2
- 0
setup.cfg View File

@@ -30,6 +30,8 @@ openstack.cli.extension =
30 30
 openstack.rsd.v2 =
31 31
     rsd_get = rsdclient.osc.v2.root:GetResource
32 32
     rsd_delete = rsdclient.osc.v2.root:DeleteResource
33
+    rsd_patch = rsdclient.osc.v2.root:PatchResource
34
+    rsd_post = rsdclient.osc.v2.root:PostResource
33 35
 
34 36
     rsd_node_compose = rsdclient.osc.v2.node:ComposeNode
35 37
     rsd_node_delete = rsdclient.osc.v2.node:DeleteNode

Loading…
Cancel
Save