diff --git a/rsdclient/osc/v2/system.py b/rsdclient/osc/v2/system.py new file mode 100644 index 0000000..a8d8e40 --- /dev/null +++ b/rsdclient/osc/v2/system.py @@ -0,0 +1,51 @@ +# 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 ListSystem(command.Command): + """List all systems.""" + + _description = "List all Systems" + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + rsd_client = self.app.client_manager.rsd + system_list = rsd_client.system.list() + print(system_list) + + +class ShowSystem(command.Command): + """Show system details.""" + + _description = "Display system details" + + def get_parser(self, prog_name): + parser = super(ShowSystem, self).get_parser(prog_name) + parser.add_argument( + 'system', + metavar='', + help='ID of the system.') + + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + rsd_client = self.app.client_manager.rsd + system_detail = rsd_client.system.show(parsed_args.system) + print("{0}".format(json.dumps(system_detail, indent=2))) diff --git a/rsdclient/v2/client.py b/rsdclient/v2/client.py index d3810f4..7f5c23e 100644 --- a/rsdclient/v2/client.py +++ b/rsdclient/v2/client.py @@ -18,6 +18,7 @@ import rsd_lib from rsdclient.v2 import fabric from rsdclient.v2 import node from rsdclient.v2 import storage_service +from rsdclient.v2 import system class Client(object): @@ -42,3 +43,4 @@ class Client(object): self.storage_service = \ storage_service.StorageServiceManager(self.client) self.fabric = fabric.FabricManager(self.client) + self.system = system.SystemManager(self.client) diff --git a/rsdclient/v2/system.py b/rsdclient/v2/system.py new file mode 100644 index 0000000..d1c3686 --- /dev/null +++ b/rsdclient/v2/system.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. +# + +from rsdclient.common import base +from rsdclient.common import utils + + +class SystemManager(base.Manager): + _resource_name = 'systems' + + def __init__(self, *args, **kwargs): + super(SystemManager, self).__init__(*args, **kwargs) + self.systems_path = self.client._systems_path + + def list(self): + system_collection = self.client.get_system_collection() + systems = [utils.extract_attr(self.client.get_system(system_uri)) + for system_uri in system_collection.members_identities] + system_info_table = utils.print_dict( + systems, ["Identity", "Name", "Description"]) + return system_info_table + + def show(self, system_uri): + system = self.client.get_system(system_uri) + system_dict = utils.extract_attr(system) + return system_dict diff --git a/setup.cfg b/setup.cfg index 8fd7c8d..121025e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,6 +55,9 @@ openstack.rsd.v2 = rsd_fabric_endpoint_list = rsdclient.osc.v2.fabric:ListEndpoint rsd_fabric_endpoint_show = rsdclient.osc.v2.fabric:ShowEndpoint + rsd_system_show = rsdclient.osc.v2.system:ShowSystem + rsd_system_list = rsdclient.osc.v2.system:ListSystem + [build_sphinx] all-files = 1 warning-is-error = 1