New command to list all endpoints of one fabric

Change-Id: Iaf31e60813dab94e2d4a3b58f54aa841f77519a6
This commit is contained in:
Lin Yang 2018-06-07 10:58:22 -07:00
parent 7b1f32f791
commit 1a99d79894
4 changed files with 42 additions and 0 deletions

View File

@ -49,3 +49,24 @@ class ShowFabric(command.Command):
rsd_client = self.app.client_manager.rsd
fabric_detail = rsd_client.fabric.show(parsed_args.fabric)
print("{0}".format(json.dumps(fabric_detail, indent=2)))
class ListEndpoint(command.Command):
"""List all endpoints of one fabric."""
_description = "List all endpoints of one fabric"
def get_parser(self, prog_name):
parser = super(ListEndpoint, self).get_parser(prog_name)
parser.add_argument(
'fabric',
metavar='<fabric>',
help='ID of the fabric.')
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
rsd_client = self.app.client_manager.rsd
endpoint_list = rsd_client.fabric.list_endpoint(parsed_args.fabric)
print(endpoint_list)

View File

@ -61,3 +61,13 @@ class FabricTest(testtools.TestCase):
self.mgr.client.get_fabric.assert_called_once_with(
'/redfish/v1/Fabrics/PCIe')
self.assertEqual(result, expected)
def test_list_endpoint(self):
mock_fabric = mock.Mock()
self.client.get_fabric.return_value = mock_fabric
mock_fabric.endpoints.get_members.return_value = ()
self.mgr.list_endpoint('/redfish/v1/Fabrics/1-ff-1')
self.mgr.client.get_fabric.assert_called_once_with(
'/redfish/v1/Fabrics/1-ff-1')
mock_fabric.endpoints.get_members.assert_called_once()

View File

@ -45,3 +45,13 @@ class FabricManager(base.Manager):
for item in fabric.zones.get_members()]
return fabric_dict
def list_endpoint(self, fabric_id):
fabric = self.client.get_fabric(fabric_id)
endpoint_collection = fabric.endpoints.get_members()
endpoints = [utils.extract_attr(endpoint)
for endpoint in endpoint_collection]
endpoint_info_table = utils.print_dict(
endpoints, ["Identity", "Name", "Description"])
return endpoint_info_table

View File

@ -52,6 +52,7 @@ openstack.rsd.v1 =
rsd_fabric_list = rsdclient.osc.v1.fabric:ListFabric
rsd_fabric_show = rsdclient.osc.v1.fabric:ShowFabric
rsd_fabric_endpoint_list = rsdclient.osc.v1.fabric:ListEndpoint
[build_sphinx]
all-files = 1