Merge "Add client api for enable and disable device"
This commit is contained in:
@@ -22,7 +22,7 @@ from osc_lib import utils
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_ACCELERATOR_API_VERSION = '2'
|
DEFAULT_ACCELERATOR_API_VERSION = '2.3'
|
||||||
API_VERSION_OPTION = 'os_accelerator_api_version'
|
API_VERSION_OPTION = 'os_accelerator_api_version'
|
||||||
API_NAME = 'accelerator'
|
API_NAME = 'accelerator'
|
||||||
CURRENT_API_VERSION = '2'
|
CURRENT_API_VERSION = '2'
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ class ListDevice(command.Lister):
|
|||||||
"model",
|
"model",
|
||||||
"hostname",
|
"hostname",
|
||||||
"std_board_info",
|
"std_board_info",
|
||||||
"vendor_board_info"
|
"vendor_board_info",
|
||||||
|
"status"
|
||||||
)
|
)
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
@@ -63,7 +64,8 @@ class ListDevice(command.Lister):
|
|||||||
"model",
|
"model",
|
||||||
"hostname",
|
"hostname",
|
||||||
"std_board_info",
|
"std_board_info",
|
||||||
"vendor_board_info"
|
"vendor_board_info",
|
||||||
|
"status"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
column_headers = (
|
column_headers = (
|
||||||
@@ -121,7 +123,8 @@ def _show_device(acc_client, uuid):
|
|||||||
"model",
|
"model",
|
||||||
"hostname",
|
"hostname",
|
||||||
"std_board_info",
|
"std_board_info",
|
||||||
"vendor_board_info"
|
"vendor_board_info",
|
||||||
|
"status"
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
device = acc_client.get_device(uuid)
|
device = acc_client.get_device(uuid)
|
||||||
@@ -133,3 +136,49 @@ def _show_device(acc_client, uuid):
|
|||||||
data = device.to_dict()
|
data = device.to_dict()
|
||||||
return columns, oscutils.get_dict_properties(data, columns,
|
return columns, oscutils.get_dict_properties(data, columns,
|
||||||
formatters=formatters)
|
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)
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class TestDeviceList(TestDevice):
|
|||||||
'hostname',
|
'hostname',
|
||||||
'std_board_info',
|
'std_board_info',
|
||||||
'vendor_board_info',
|
'vendor_board_info',
|
||||||
|
'status'
|
||||||
)
|
)
|
||||||
self.assertEqual(collist, columns)
|
self.assertEqual(collist, columns)
|
||||||
|
|
||||||
@@ -101,6 +102,7 @@ class TestDeviceList(TestDevice):
|
|||||||
acc_fakes.device_hostname,
|
acc_fakes.device_hostname,
|
||||||
acc_fakes.device_std_board_info,
|
acc_fakes.device_std_board_info,
|
||||||
acc_fakes.device_vendor_board_info,
|
acc_fakes.device_vendor_board_info,
|
||||||
|
'',
|
||||||
), ]
|
), ]
|
||||||
self.assertEqual(datalist, list(data))
|
self.assertEqual(datalist, list(data))
|
||||||
|
|
||||||
@@ -135,7 +137,8 @@ class TestDeviceShow(TestDevice):
|
|||||||
'model',
|
'model',
|
||||||
'hostname',
|
'hostname',
|
||||||
'std_board_info',
|
'std_board_info',
|
||||||
'vendor_board_info'
|
'vendor_board_info',
|
||||||
|
'status'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(collist, columns)
|
self.assertEqual(collist, columns)
|
||||||
@@ -150,6 +153,7 @@ class TestDeviceShow(TestDevice):
|
|||||||
acc_fakes.device_hostname,
|
acc_fakes.device_hostname,
|
||||||
acc_fakes.device_std_board_info,
|
acc_fakes.device_std_board_info,
|
||||||
acc_fakes.device_vendor_board_info,
|
acc_fakes.device_vendor_board_info,
|
||||||
|
''
|
||||||
]
|
]
|
||||||
self.assertEqual(datalist, list(data))
|
self.assertEqual(datalist, list(data))
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ openstack.accelerator.v2 =
|
|||||||
accelerator_deployable_show = cyborgclient.osc.v2.deployable:ShowDeployable
|
accelerator_deployable_show = cyborgclient.osc.v2.deployable:ShowDeployable
|
||||||
accelerator_device_list = cyborgclient.osc.v2.device:ListDevice
|
accelerator_device_list = cyborgclient.osc.v2.device:ListDevice
|
||||||
accelerator_device_show = cyborgclient.osc.v2.device:ShowDevice
|
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_list = cyborgclient.osc.v2.attribute:ListAttribute
|
||||||
accelerator_device_attribute_create = cyborgclient.osc.v2.attribute:CreateAttribute
|
accelerator_device_attribute_create = cyborgclient.osc.v2.attribute:CreateAttribute
|
||||||
accelerator_device_attribute_delete = cyborgclient.osc.v2.attribute:DeleteAttribute
|
accelerator_device_attribute_delete = cyborgclient.osc.v2.attribute:DeleteAttribute
|
||||||
|
|||||||
Reference in New Issue
Block a user