diff --git a/ironicclient/tests/v1/test_chassis.py b/ironicclient/tests/v1/test_chassis.py index 96bc88290..f0aad9775 100644 --- a/ironicclient/tests/v1/test_chassis.py +++ b/ironicclient/tests/v1/test_chassis.py @@ -28,6 +28,14 @@ CHASSIS = {'id': 42, 'extra': {}, 'description': 'data-center-1-chassis'} +NODE = {'id': 123, + 'uuid': '66666666-7777-8888-9999-000000000000', + 'chassis_id': 42, + 'driver': 'fake', + 'driver_info': {'user': 'foo', 'password': 'bar'}, + 'properties': {'num_cpu': 4}, + 'extra': {}} + CREATE_CHASSIS = copy.deepcopy(CHASSIS) del CREATE_CHASSIS['id'] del CREATE_CHASSIS['uuid'] @@ -62,7 +70,13 @@ fixtures = { {}, UPDATED_CHASSIS, ), - + }, + '/v1/chassis/%s/nodes' % CHASSIS['uuid']: + { + 'GET': ( + {}, + {"nodes": [NODE]}, + ), }, } @@ -117,3 +131,12 @@ class ChassisManagerTest(testtools.TestCase): ] self.assertEqual(self.api.calls, expect) self.assertEqual(chassis.description, NEW_DESCR) + + def test_chassis_node_list(self): + nodes = self.mgr.list_nodes(CHASSIS['uuid']) + expect = [ + ('GET', '/v1/chassis/%s/nodes' % CHASSIS['uuid'], {}, None), + ] + self.assertEqual(self.api.calls, expect) + self.assertEqual(len(nodes), 1) + self.assertEqual(nodes[0].uuid, NODE['uuid']) diff --git a/ironicclient/v1/chassis.py b/ironicclient/v1/chassis.py index d7d97754b..c592ba5d0 100644 --- a/ironicclient/v1/chassis.py +++ b/ironicclient/v1/chassis.py @@ -36,6 +36,10 @@ class ChassisManager(base.Manager): def list(self): return self._list(self._path(), "chassis") + def list_nodes(self, chassis_id): + path = "%s/nodes" % chassis_id + return self._list(self._path(path), "nodes") + def get(self, chassis_id): try: return self._list(self._path(chassis_id))[0] diff --git a/ironicclient/v1/chassis_shell.py b/ironicclient/v1/chassis_shell.py index 245374334..68bd3de87 100644 --- a/ironicclient/v1/chassis_shell.py +++ b/ironicclient/v1/chassis_shell.py @@ -102,3 +102,16 @@ def do_chassis_update(cc, args): except exc.HTTPNotFound: raise exc.CommandError('Chassis not found: %s' % args.chassis) _print_chassis_show(chassis) + + +@utils.arg('chassis', metavar='', help="ID of chassis") +def do_chassis_node_list(cc, args): + """List the nodes contained in the chassis.""" + try: + nodes = cc.chassis.list_nodes(args.chassis) + except exc.HTTPNotFound: + raise exc.CommandError(_('Chassis not found: %s') % args.chassis) + field_labels = ['UUID', 'Instance UUID', + 'Power State', 'Provisioning State'] + fields = ['uuid', 'instance_uuid', 'power_state', 'provision_state'] + utils.print_list(nodes, fields, field_labels, sortby=1)