Browse Source

Add generic get command to retrieve all resources

Change-Id: I530b5ca8a4e6f2ee673f31d0300c75b566f1379d
tags/1.0.0
Lin Yang 1 week ago
parent
commit
f8e5ac2e7f
4 changed files with 72 additions and 0 deletions
  1. 38
    0
      rsdclient/osc/v2/root.py
  2. 2
    0
      rsdclient/v2/client.py
  3. 30
    0
      rsdclient/v2/root.py
  4. 2
    0
      setup.cfg

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

@@ -0,0 +1,38 @@
1
+#   Copyright 2019 Intel, Inc.
2
+#
3
+#   Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#   not use this file except in compliance with the License. You may obtain
5
+#   a copy of the License at
6
+#
7
+#        http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#   Unless required by applicable law or agreed to in writing, software
10
+#   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#   License for the specific language governing permissions and limitations
13
+#   under the License.
14
+#
15
+
16
+import json
17
+
18
+from rsdclient.common import command
19
+
20
+
21
+class GetResource(command.Command):
22
+    """Show the details of one RSD resource."""
23
+
24
+    _description = "Display the details of one RSD resource"
25
+
26
+    def get_parser(self, prog_name):
27
+        parser = super(GetResource, self).get_parser(prog_name)
28
+        parser.add_argument(
29
+            "resource", metavar="<resource>", help="ID of the RSD resource."
30
+        )
31
+
32
+        return parser
33
+
34
+    def take_action(self, parsed_args):
35
+        self.log.debug("take_action(%s)", parsed_args)
36
+        rsd_client = self.app.client_manager.rsd
37
+        resource_detail = rsd_client.root.get(parsed_args.resource)
38
+        print("{0}".format(json.dumps(resource_detail, indent=2)))

+ 2
- 0
rsdclient/v2/client.py View File

@@ -17,6 +17,7 @@ import rsd_lib
17 17
 
18 18
 from rsdclient.v2 import fabric
19 19
 from rsdclient.v2 import node
20
+from rsdclient.v2 import root
20 21
 from rsdclient.v2 import storage_service
21 22
 from rsdclient.v2 import system
22 23
 
@@ -39,6 +40,7 @@ class Client(object):
39 40
 
40 41
         self.client = rsd_lib.RSDLib(base_url, username, password,
41 42
                                      verify=verify).factory()
43
+        self.root = root.RootManager(self.client)
42 44
         self.node = node.NodeManager(self.client)
43 45
         self.storage_service = \
44 46
             storage_service.StorageServiceManager(self.client)

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

@@ -0,0 +1,30 @@
1
+#   Copyright 2019 Intel, Inc.
2
+#
3
+#   Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#   not use this file except in compliance with the License. You may obtain
5
+#   a copy of the License at
6
+#
7
+#        http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#   Unless required by applicable law or agreed to in writing, software
10
+#   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#   License for the specific language governing permissions and limitations
13
+#   under the License.
14
+#
15
+
16
+from rsdclient.common import base
17
+from rsdclient.common import utils
18
+
19
+
20
+class RootManager(base.Manager):
21
+    _resource_name = "root service"
22
+
23
+    def __init__(self, *args, **kwargs):
24
+        super(RootManager, self).__init__(*args, **kwargs)
25
+
26
+    def show(self, resource_uri):
27
+        resource = self.client.get_resource(resource_uri)
28
+        resource_dict = utils.extract_attr(resource)
29
+
30
+        return resource_dict

+ 2
- 0
setup.cfg View File

@@ -28,6 +28,8 @@ openstack.cli.extension =
28 28
     rsd = rsdclient.osc.plugin
29 29
 
30 30
 openstack.rsd.v2 =
31
+    rsd_get = rsdclient.osc.v2.root:GetResource
32
+
31 33
     rsd_node_compose = rsdclient.osc.v2.node:ComposeNode
32 34
     rsd_node_delete = rsdclient.osc.v2.node:DeleteNode
33 35
     rsd_node_show = rsdclient.osc.v2.node:ShowNode

Loading…
Cancel
Save