Merge "Add client api for enable and disable device"

This commit is contained in:
Zuul 2023-09-19 05:49:38 +00:00 committed by Gerrit Code Review
commit a3688d5b86
4 changed files with 60 additions and 5 deletions

View File

@ -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'

View File

@ -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="<uuid>",
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="<uuid>",
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)

View File

@ -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))

View File

@ -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