def do_node_port_list(cc, args): """List the ports associated with a node.""" if args.detail: fields = res_fields.PORT_DETAILED_RESOURCE.fields field_labels = res_fields.PORT_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.PORT_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.PORT_RESOURCE.fields field_labels = res_fields.PORT_RESOURCE.labels sort_fields = res_fields.PORT_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.PORT_DETAILED_RESOURCE.sort_labels params = utils.common_params_for_list(args, sort_fields, sort_field_labels) ports = cc.node.list_ports(args.node, **params) cliutils.print_list(ports, fields, field_labels=field_labels, sortby_index=None)
def do_portgroup_list(cc, args): """List the portgroups.""" params = {} if args.address is not None: params['address'] = args.address if args.node is not None: params['node'] = args.node if args.detail: fields = res_fields.PORTGROUP_DETAILED_RESOURCE.fields field_labels = res_fields.PORTGROUP_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.PORTGROUP_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.PORTGROUP_RESOURCE.fields field_labels = res_fields.PORTGROUP_RESOURCE.labels sort_fields = res_fields.PORTGROUP_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.PORTGROUP_DETAILED_RESOURCE.sort_labels params.update( utils.common_params_for_list(args, sort_fields, sort_field_labels)) portgroup = cc.portgroup.list(**params) cliutils.print_list(portgroup, fields, field_labels=field_labels, sortby_index=None, json_flag=args.json)
def do_volume_target_list(cc, args): """List the volume targets.""" params = {} if args.node is not None: params['node'] = args.node if args.detail: fields = res_fields.VOLUME_TARGET_DETAILED_RESOURCE.fields field_labels = res_fields.VOLUME_TARGET_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.VOLUME_TARGET_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.VOLUME_TARGET_RESOURCE.fields field_labels = res_fields.VOLUME_TARGET_RESOURCE.labels sort_fields = res_fields.VOLUME_TARGET_DETAILED_RESOURCE.sort_fields sort_field_labels = ( res_fields.VOLUME_TARGET_DETAILED_RESOURCE.sort_labels) params.update( utils.common_params_for_list(args, sort_fields, sort_field_labels)) volume_target = cc.volume_target.list(**params) cliutils.print_list(volume_target, fields, field_labels=field_labels, sortby_index=None, json_flag=args.json)
def do_chassis_list(cc, args): """List the chassis.""" if args.detail: fields = res_fields.CHASSIS_DETAILED_RESOURCE.fields field_labels = res_fields.CHASSIS_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.CHASSIS_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.CHASSIS_RESOURCE.fields field_labels = res_fields.CHASSIS_RESOURCE.labels sort_fields = res_fields.CHASSIS_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.CHASSIS_DETAILED_RESOURCE.sort_labels params = utils.common_params_for_list(args, sort_fields, sort_field_labels) chassis = cc.chassis.list(**params) cliutils.print_list(chassis, fields, field_labels=field_labels, sortby_index=None)
def do_volume_target_list(cc, args): """List the volume targets.""" params = {} if args.node is not None: params['node'] = args.node if args.detail: fields = res_fields.VOLUME_TARGET_DETAILED_RESOURCE.fields field_labels = res_fields.VOLUME_TARGET_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.VOLUME_TARGET_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.VOLUME_TARGET_RESOURCE.fields field_labels = res_fields.VOLUME_TARGET_RESOURCE.labels sort_fields = res_fields.VOLUME_TARGET_DETAILED_RESOURCE.sort_fields sort_field_labels = ( res_fields.VOLUME_TARGET_DETAILED_RESOURCE.sort_labels) params.update(utils.common_params_for_list(args, sort_fields, sort_field_labels)) volume_target = cc.volume_target.list(**params) cliutils.print_list(volume_target, fields, field_labels=field_labels, sortby_index=None, json_flag=args.json)
def do_node_port_list(cc, args): """List the ports associated with a node.""" if args.detail: fields = res_fields.PORT_DETAILED_RESOURCE.fields field_labels = res_fields.PORT_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.PORT_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.PORT_RESOURCE.fields field_labels = res_fields.PORT_RESOURCE.labels sort_fields = res_fields.PORT_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.PORT_DETAILED_RESOURCE.sort_labels params = utils.common_params_for_list(args, sort_fields, sort_field_labels) ports = cc.node.list_ports(args.node, **params) cliutils.print_list(ports, fields, field_labels=field_labels, sortby_index=None, json_flag=args.json)
def do_port_list(cc, args): """List the ports.""" params = {} if args.address is not None: params['address'] = args.address if args.detail: fields = res_fields.PORT_DETAILED_RESOURCE.fields field_labels = res_fields.PORT_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.PORT_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.PORT_RESOURCE.fields field_labels = res_fields.PORT_RESOURCE.labels sort_fields = res_fields.PORT_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.PORT_DETAILED_RESOURCE.sort_labels params.update(utils.common_params_for_list(args, sort_fields, sort_field_labels)) port = cc.port.list(**params) cliutils.print_list(port, fields, field_labels=field_labels, sortby_index=None, json_flag=args.json)
def do_node_list(cc, args): """List the nodes which are registered with the Ironic service.""" params = {} if args.associated is not None: params['associated'] = utils.bool_argument_value("--associated", args.associated) if args.maintenance is not None: params['maintenance'] = utils.bool_argument_value("--maintenance", args.maintenance) if args.provision_state is not None: params['provision_state'] = args.provision_state if args.detail: fields = res_fields.NODE_DETAILED_RESOURCE.fields field_labels = res_fields.NODE_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.NODE_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.NODE_RESOURCE.fields field_labels = res_fields.NODE_RESOURCE.labels sort_fields = res_fields.NODE_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.NODE_DETAILED_RESOURCE.sort_labels params.update(utils.common_params_for_list(args, sort_fields, sort_field_labels)) nodes = cc.node.list(**params) cliutils.print_list(nodes, fields, field_labels=field_labels, sortby_index=None)
def do_node_list(cc, args): """List the nodes which are registered with the Ironic service.""" params = {} if args.associated is not None: params['associated'] = utils.bool_argument_value( "--associated", args.associated) if args.maintenance is not None: params['maintenance'] = utils.bool_argument_value( "--maintenance", args.maintenance) if args.provision_state is not None: params['provision_state'] = args.provision_state if args.detail: fields = res_fields.NODE_DETAILED_RESOURCE.fields field_labels = res_fields.NODE_DETAILED_RESOURCE.labels elif args.fields: utils.check_for_invalid_fields( args.fields[0], res_fields.NODE_DETAILED_RESOURCE.fields) resource = res_fields.Resource(args.fields[0]) fields = resource.fields field_labels = resource.labels else: fields = res_fields.NODE_RESOURCE.fields field_labels = res_fields.NODE_RESOURCE.labels sort_fields = res_fields.NODE_DETAILED_RESOURCE.sort_fields sort_field_labels = res_fields.NODE_DETAILED_RESOURCE.sort_labels params.update( utils.common_params_for_list(args, sort_fields, sort_field_labels)) nodes = cc.node.list(**params) cliutils.print_list(nodes, fields, field_labels=field_labels, sortby_index=None)
def do_node_vif_list(cc, args): """List VIFs for a given node.""" vifs = cc.node.vif_list(args.node) fields = res_fields.VIF_RESOURCE.fields field_labels = res_fields.VIF_RESOURCE.labels cliutils.print_list(vifs, fields, field_labels=field_labels, sortby_index=None, json_flag=args.json)
def test_print_list_dict(self): objs = [{'name': 'k1', 'value': 1}, {'name': 'k2', 'value': 2}] cliutils.print_list(objs, ["Name", "Value"], sortby_index=None) self.assertEqual( self.mock_add_row.call_args_list, [mock.call(["k1", 1]), mock.call(["k2", 2])]) self.mock_get_string.assert_called_with() self.mock_init.assert_called_once_with(["Name", "Value"])
def do_driver_list(cc, args): """List the enabled drivers.""" drivers = cc.driver.list() # NOTE(lucasagomes): Separate each host by a comma. # It's easier to read. for d in drivers: d.hosts = ', '.join(d.hosts) field_labels = ['Supported driver(s)', 'Active host(s)'] fields = ['name', 'hosts'] cliutils.print_list(drivers, fields, field_labels=field_labels)
def test_print_list_dict(self): objs = [{'name': 'k1', 'value': 1}, {'name': 'k2', 'value': 2}] cliutils.print_list(objs, ["Name", "Value"], sortby_index=None) self.assertEqual(self.mock_add_row.call_args_list, [mock.call(["k1", 1]), mock.call(["k2", 2])]) self.mock_get_string.assert_called_with() self.mock_init.assert_called_once_with(["Name", "Value"])
def do_node_validate(cc, args): """Validate a node's driver interfaces.""" ifaces = cc.node.validate(args.node) obj_list = [] for key, value in ifaces.to_dict().items(): data = {'interface': key} data.update(value) obj_list.append(type('iface', (object,), data)) field_labels = ['Interface', 'Result', 'Reason'] fields = ['interface', 'result', 'reason'] cliutils.print_list(obj_list, fields, field_labels=field_labels)
def do_node_validate(cc, args): """Validate a node's driver interfaces.""" ifaces = cc.node.validate(args.node) obj_list = [] for key, value in ifaces.to_dict().items(): data = {'interface': key} data.update(value) obj_list.append(type('iface', (object, ), data)) field_labels = ['Interface', 'Result', 'Reason'] fields = ['interface', 'result', 'reason'] cliutils.print_list(obj_list, fields, field_labels=field_labels)
def test_print_list_string_json(self): objs = [_FakeResult("k1", 1)] field_labels = ["Another Name", "Another Value"] orig = sys.stdout sys.stdout = six.StringIO() cliutils.print_list(objs, ["Name", "Value"], sortby_index=0, field_labels=field_labels, json_flag=True) out = sys.stdout.getvalue() sys.stdout.close() sys.stdout = orig self.assertEqual([objs[0]._info], json.loads(out))
def test_print_list_sort_by_none(self): objs = [_FakeResult("k1", 1), _FakeResult("k3", 3), _FakeResult("k2", 2)] cliutils.print_list(objs, ["Name", "Value"], sortby_index=None) self.assertEqual(self.mock_add_row.call_args_list, [mock.call(["k1", 1]), mock.call(["k3", 3]), mock.call(["k2", 2])]) self.mock_get_string.assert_called_with() self.mock_init.assert_called_once_with(["Name", "Value"])
def do_driver_get_vendor_passthru_methods(cc, args): """Get the vendor passthru methods for a driver.""" methods = cc.driver.get_vendor_passthru_methods(args.driver_name) data = [] for method, response in methods.items(): response['name'] = method http_methods = ','.join(response['http_methods']) response['http_methods'] = http_methods data.append(response) fields = res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.fields field_labels = res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.labels cliutils.print_list(data, fields, field_labels=field_labels, sortby_index=None)
def do_node_get_vendor_passthru_methods(cc, args): """Get the vendor passthru methods for a node.""" methods = cc.node.get_vendor_passthru_methods(args.node) data = [] for method, response in methods.items(): response['name'] = method http_methods = ','.join(response['http_methods']) response['http_methods'] = http_methods data.append(response) fields = res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.fields field_labels = res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.labels cliutils.print_list(data, fields, field_labels=field_labels, sortby_index=None)
def test_print_list_field_labels(self): objs = [_FakeResult("k1", 1), _FakeResult("k3", 3), _FakeResult("k2", 2)] field_labels = ["Another Name", "Another Value"] cliutils.print_list(objs, ["Name", "Value"], sortby_index=None, field_labels=field_labels) self.assertEqual(self.mock_add_row.call_args_list, [mock.call(["k1", 1]), mock.call(["k3", 3]), mock.call(["k2", 2])]) self.mock_init.assert_called_once_with(field_labels)
def test_print_list_sort_by_none(self): objs = [ _FakeResult("k1", 1), _FakeResult("k3", 3), _FakeResult("k2", 2) ] cliutils.print_list(objs, ["Name", "Value"], sortby_index=None) self.assertEqual( self.mock_add_row.call_args_list, [mock.call(["k1", 1]), mock.call(["k3", 3]), mock.call(["k2", 2])]) self.mock_get_string.assert_called_with() self.mock_init.assert_called_once_with(["Name", "Value"])
def do_driver_list(cc, args): """List the enabled drivers.""" drivers = cc.driver.list(driver_type=args.type, detail=args.detail) # NOTE(lucasagomes): For list-type properties, show the values as # comma separated strings. It's easier to read. data = [utils.convert_list_props_to_comma_separated(d._info) for d in drivers] if args.detail: field_labels = res_fields.DRIVER_DETAILED_RESOURCE.labels fields = res_fields.DRIVER_DETAILED_RESOURCE.fields else: field_labels = res_fields.DRIVER_RESOURCE.labels fields = res_fields.DRIVER_RESOURCE.fields cliutils.print_list(data, fields, field_labels=field_labels, json_flag=args.json)
def test_print_list_field_labels(self): objs = [ _FakeResult("k1", 1), _FakeResult("k3", 3), _FakeResult("k2", 2) ] field_labels = ["Another Name", "Another Value"] cliutils.print_list(objs, ["Name", "Value"], sortby_index=None, field_labels=field_labels) self.assertEqual( self.mock_add_row.call_args_list, [mock.call(["k1", 1]), mock.call(["k3", 3]), mock.call(["k2", 2])]) self.mock_init.assert_called_once_with(field_labels)
def test_print_list_string(self): objs = [_FakeResult("k1", 1)] field_labels = ["Another Name", "Another Value"] orig = sys.stdout sys.stdout = six.StringIO() cliutils.print_list(objs, ["Name", "Value"], sortby_index=0, field_labels=field_labels) out = sys.stdout.getvalue() sys.stdout.close() sys.stdout = orig expected = '''\ +--------------+---------------+ | Another Name | Another Value | +--------------+---------------+ | k1 | 1 | +--------------+---------------+ ''' self.assertEqual(expected, out)
def test_print_list_string_json(self): objs = [_FakeResult("k1", 1)] field_labels = ["Another Name", "Another Value"] orig = sys.stdout sys.stdout = six.StringIO() cliutils.print_list(objs, ["Name", "Value"], sortby_index=0, field_labels=field_labels, json_flag=True) out = sys.stdout.getvalue() sys.stdout.close() sys.stdout = orig expected = [ '''\ [{"name": "k1", "value": 1}] ''', '''\ [{"value": 1, "name": "k1"}] ''' ] self.assertIn(out, expected)