From f8e5ac2e7f81fe5ee8646684b7090e5fe690afac Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Wed, 11 Sep 2019 11:40:37 -0700 Subject: [PATCH] Add generic get command to retrieve all resources Change-Id: I530b5ca8a4e6f2ee673f31d0300c75b566f1379d --- rsdclient/osc/v2/root.py | 38 ++++++++++++++++++++++++++++++++++++++ rsdclient/v2/client.py | 2 ++ rsdclient/v2/root.py | 30 ++++++++++++++++++++++++++++++ setup.cfg | 2 ++ 4 files changed, 72 insertions(+) create mode 100644 rsdclient/osc/v2/root.py create mode 100644 rsdclient/v2/root.py diff --git a/rsdclient/osc/v2/root.py b/rsdclient/osc/v2/root.py new file mode 100644 index 0000000..2702411 --- /dev/null +++ b/rsdclient/osc/v2/root.py @@ -0,0 +1,38 @@ +# Copyright 2019 Intel, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +import json + +from rsdclient.common import command + + +class GetResource(command.Command): + """Show the details of one RSD resource.""" + + _description = "Display the details of one RSD resource" + + def get_parser(self, prog_name): + parser = super(GetResource, self).get_parser(prog_name) + parser.add_argument( + "resource", metavar="", help="ID of the RSD resource." + ) + + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + rsd_client = self.app.client_manager.rsd + resource_detail = rsd_client.root.get(parsed_args.resource) + print("{0}".format(json.dumps(resource_detail, indent=2))) diff --git a/rsdclient/v2/client.py b/rsdclient/v2/client.py index 7f5c23e..42a4051 100644 --- a/rsdclient/v2/client.py +++ b/rsdclient/v2/client.py @@ -17,6 +17,7 @@ import rsd_lib from rsdclient.v2 import fabric from rsdclient.v2 import node +from rsdclient.v2 import root from rsdclient.v2 import storage_service from rsdclient.v2 import system @@ -39,6 +40,7 @@ class Client(object): self.client = rsd_lib.RSDLib(base_url, username, password, verify=verify).factory() + self.root = root.RootManager(self.client) self.node = node.NodeManager(self.client) self.storage_service = \ storage_service.StorageServiceManager(self.client) diff --git a/rsdclient/v2/root.py b/rsdclient/v2/root.py new file mode 100644 index 0000000..f2c44eb --- /dev/null +++ b/rsdclient/v2/root.py @@ -0,0 +1,30 @@ +# Copyright 2019 Intel, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +from rsdclient.common import base +from rsdclient.common import utils + + +class RootManager(base.Manager): + _resource_name = "root service" + + def __init__(self, *args, **kwargs): + super(RootManager, self).__init__(*args, **kwargs) + + def show(self, resource_uri): + resource = self.client.get_resource(resource_uri) + resource_dict = utils.extract_attr(resource) + + return resource_dict diff --git a/setup.cfg b/setup.cfg index 121025e..fec07b9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,6 +28,8 @@ openstack.cli.extension = rsd = rsdclient.osc.plugin openstack.rsd.v2 = + rsd_get = rsdclient.osc.v2.root:GetResource + rsd_node_compose = rsdclient.osc.v2.node:ComposeNode rsd_node_delete = rsdclient.osc.v2.node:DeleteNode rsd_node_show = rsdclient.osc.v2.node:ShowNode