From 528144a248c81bd574c23bae5899e34217a89b53 Mon Sep 17 00:00:00 2001 From: anguoming Date: Sat, 16 Sep 2023 15:28:59 +0800 Subject: [PATCH] Add client api for enable and disable device implementation of bp/disable-enable-device add cyborg client for disable and enable device api Change-Id: I7a70a8ef62a3d943dd314773af4a2db06521c3d3 --- cyborgclient/osc/plugin.py | 2 +- cyborgclient/osc/v2/device.py | 55 ++++++++++++++++++- cyborgclient/tests/unit/osc/v2/test_device.py | 6 +- setup.cfg | 2 + 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/cyborgclient/osc/plugin.py b/cyborgclient/osc/plugin.py index 4a3cbd5..5832a6a 100644 --- a/cyborgclient/osc/plugin.py +++ b/cyborgclient/osc/plugin.py @@ -22,7 +22,7 @@ from osc_lib import utils LOG = logging.getLogger(__name__) -DEFAULT_ACCELERATOR_API_VERSION = '2' +DEFAULT_ACCELERATOR_API_VERSION = '2.3' API_VERSION_OPTION = 'os_accelerator_api_version' API_NAME = 'accelerator' CURRENT_API_VERSION = '2' diff --git a/cyborgclient/osc/v2/device.py b/cyborgclient/osc/v2/device.py index 2bba707..d913df8 100644 --- a/cyborgclient/osc/v2/device.py +++ b/cyborgclient/osc/v2/device.py @@ -51,7 +51,8 @@ class ListDevice(command.Lister): "model", "hostname", "std_board_info", - "vendor_board_info" + "vendor_board_info", + "status" ) columns = ( @@ -63,7 +64,8 @@ class ListDevice(command.Lister): "model", "hostname", "std_board_info", - "vendor_board_info" + "vendor_board_info", + "status" ) else: column_headers = ( @@ -121,7 +123,8 @@ def _show_device(acc_client, uuid): "model", "hostname", "std_board_info", - "vendor_board_info" + "vendor_board_info", + "status" ) try: device = acc_client.get_device(uuid) @@ -133,3 +136,49 @@ def _show_device(acc_client, uuid): data = device.to_dict() return columns, oscutils.get_dict_properties(data, columns, formatters=formatters) + + +class EnableDevice(command.Command): + """Enable device .""" + log = logging.getLogger(__name__ + ".EnableDevice") + + def get_parser(self, prog_name): + parser = super(EnableDevice, self).get_parser(prog_name) + parser.add_argument( + "device", + metavar="", + help=_("UUID of the device.") + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + acc_client = self.app.client_manager.accelerator + uuid = parsed_args.device + try: + acc_client.enable_device(uuid) + except sdk_exc.ResourceNotFound: + raise exc.CommandError(_('device not found: %s') % uuid) + + +class DisableDevice(command.Command): + """Disable device .""" + log = logging.getLogger(__name__ + ".DisableDevice") + + def get_parser(self, prog_name): + parser = super(DisableDevice, self).get_parser(prog_name) + parser.add_argument( + "device", + metavar="", + help=_("UUID of the device.") + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + acc_client = self.app.client_manager.accelerator + uuid = parsed_args.device + try: + acc_client.disable_device(uuid) + except sdk_exc.ResourceNotFound: + raise exc.CommandError(_('device not found: %s') % uuid) diff --git a/cyborgclient/tests/unit/osc/v2/test_device.py b/cyborgclient/tests/unit/osc/v2/test_device.py index 940e653..9902d75 100644 --- a/cyborgclient/tests/unit/osc/v2/test_device.py +++ b/cyborgclient/tests/unit/osc/v2/test_device.py @@ -88,6 +88,7 @@ class TestDeviceList(TestDevice): 'hostname', 'std_board_info', 'vendor_board_info', + 'status' ) self.assertEqual(collist, columns) @@ -101,6 +102,7 @@ class TestDeviceList(TestDevice): acc_fakes.device_hostname, acc_fakes.device_std_board_info, acc_fakes.device_vendor_board_info, + '', ), ] self.assertEqual(datalist, list(data)) @@ -135,7 +137,8 @@ class TestDeviceShow(TestDevice): 'model', 'hostname', 'std_board_info', - 'vendor_board_info' + 'vendor_board_info', + 'status' ) self.assertEqual(collist, columns) @@ -150,6 +153,7 @@ class TestDeviceShow(TestDevice): acc_fakes.device_hostname, acc_fakes.device_std_board_info, acc_fakes.device_vendor_board_info, + '' ] self.assertEqual(datalist, list(data)) diff --git a/setup.cfg b/setup.cfg index ef9e8e5..a61d398 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,6 +40,8 @@ openstack.accelerator.v2 = accelerator_deployable_show = cyborgclient.osc.v2.deployable:ShowDeployable accelerator_device_list = cyborgclient.osc.v2.device:ListDevice accelerator_device_show = cyborgclient.osc.v2.device:ShowDevice + accelerator_device_enable = cyborgclient.osc.v2.device:EnableDevice + accelerator_device_disable = cyborgclient.osc.v2.device:DisableDevice accelerator_device_attribute_list = cyborgclient.osc.v2.attribute:ListAttribute accelerator_device_attribute_create = cyborgclient.osc.v2.attribute:CreateAttribute accelerator_device_attribute_delete = cyborgclient.osc.v2.attribute:DeleteAttribute