Add new command to attach resource endpoint

New command 'openstack rsd node attach' to allow user to attach a
specific resource to existing composed node, or specify capacity
criteria.

Change-Id: I142fba9faf2b377c65b70420a792606f8ad7b33f
This commit is contained in:
Lin Yang
2017-09-08 11:49:07 -07:00
parent d19e8f5410
commit 93554e3c16
4 changed files with 40 additions and 0 deletions

View File

@@ -283,3 +283,30 @@ class ListNode(command.Command):
rsd_client = self.app.client_manager.rsd
node_list = rsd_client.node.list()
print(node_list)
class AttachEndpoint(command.Command):
_description = "Attach drive to existing composed node"
def get_parser(self, prog_name):
parser = super(AttachEndpoint, self).get_parser(prog_name)
parser.add_argument(
'node',
metavar='<node>',
help='ID of the node.')
parser.add_argument(
'--resource',
metavar='<resource uri>',
help='URI of the specific resource to attach to node.')
parser.add_argument(
'--capacity',
metavar='<size>',
type=int,
help='Required storage capacity in GiB.')
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
rsd_client = self.app.client_manager.rsd
rsd_client.node.attach(parsed_args.node, parsed_args.resource,
parsed_args.capacity)

View File

@@ -73,3 +73,11 @@ class NodeTest(testtools.TestCase):
self.mgr.client.get_node_collection.assert_called_once()
self.mgr.client.get_node.assert_called_once_with('/redfish/v1/Nodes/1')
self.assertEqual(str(result), expected)
def test_attach(self):
node_id = '1'
mock_node = mock.Mock()
self.client.get_node.return_value = mock_node
self.mgr.attach(node_id, 'fake uri', 10)
self.mgr.client.get_node.assert_called_once_with('/redfish/v1/Nodes/1')
mock_node.attach_endpoint.assert_called_once_with('fake uri', 10)

View File

@@ -48,3 +48,7 @@ class NodeManager(base.Manager):
node_info_table = utils.print_dict(
nodes, ["Identity", "Name", "UUID", "Description"])
return node_info_table
def attach(self, node_id, endpoint=None, capacity=None):
node = self.client.get_node(self._get_node_uri(node_id))
node.attach_endpoint(endpoint, capacity)

View File

@@ -32,6 +32,7 @@ openstack.rsd.v1 =
rsd_node_delete = rsdclient.osc.v1.node:DeleteNode
rsd_node_show = rsdclient.osc.v1.node:ShowNode
rsd_node_list = rsdclient.osc.v1.node:ListNode
rsd_node_attach = rsdclient.osc.v1.node:AttachEndpoint
rsd_storage_list = rsdclient.osc.v1.storage_service:ListStorageServices
rsd_storage_show = rsdclient.osc.v1.storage_service:ShowStorageServices