Esempio n. 1
0
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_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 take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.baremetal

        columns = res_fields.CHASSIS_RESOURCE.fields
        labels = res_fields.CHASSIS_RESOURCE.labels

        params = {}
        if parsed_args.limit is not None and parsed_args.limit < 0:
            raise exc.CommandError(
                _('Expected non-negative --limit, got %s') % parsed_args.limit)
        params['limit'] = parsed_args.limit
        params['marker'] = parsed_args.marker
        if parsed_args.long:
            params['detail'] = parsed_args.long
            columns = res_fields.CHASSIS_DETAILED_RESOURCE.fields
            labels = res_fields.CHASSIS_DETAILED_RESOURCE.labels
        elif parsed_args.fields:
            params['detail'] = False
            fields = itertools.chain.from_iterable(parsed_args.fields)
            resource = res_fields.Resource(list(fields))
            columns = resource.fields
            labels = resource.labels
            params['fields'] = columns

        self.log.debug("params(%s)" % params)
        data = client.chassis.list(**params)

        data = oscutils.sort_items(data, parsed_args.sort)

        return (labels, (oscutils.get_item_properties(
            s,
            columns,
            formatters={'Properties': oscutils.format_dict},
        ) for s in data))
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)
Esempio n. 5
0
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)
Esempio n. 6
0
 def test_override_labels(self):
     # Test overriding labels
     foo = resource_fields.Resource(['item_3', 'item1', '2nd_item'],
                                    override_labels={'item1': 'One'})
     self.assertEqual(('Third item', 'One', 'A second item'), foo.labels)
     self.assertEqual(('Third item', 'One', 'A second item'),
                      foo.sort_labels)
Esempio n. 7
0
 def test_fields_multiple_value_order(self):
     # Make sure order is maintained
     foo = resource_fields.Resource(['2nd_item', 'item1'])
     self.assertEqual(('2nd_item', 'item1'), foo.fields)
     self.assertEqual(('A second item', 'ITEM1'), foo.labels)
     self.assertEqual(('2nd_item', 'item1'), foo.sort_fields)
     self.assertEqual(('A second item', 'ITEM1'), foo.sort_labels)
Esempio n. 8
0
 def test_fields_single_value(self):
     # Make sure single value is what we expect
     foo = resource_fields.Resource(['item1'])
     self.assertEqual(('item1',), foo.fields)
     self.assertEqual(('ITEM1',), foo.labels)
     self.assertEqual(('item1',), foo.sort_fields)
     self.assertEqual(('ITEM1',), foo.sort_labels)
Esempio n. 9
0
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 take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        client = self.app.client_manager.baremetal

        params = {}
        if parsed_args.limit is not None and parsed_args.limit < 0:
            raise exc.CommandError(
                _('Expected non-negative --limit, got %s') % parsed_args.limit)
        params['limit'] = parsed_args.limit
        params['marker'] = parsed_args.marker
        for field in ('node', 'resource_class', 'state', 'owner'):
            value = getattr(parsed_args, field)
            if value is not None:
                params[field] = value

        if parsed_args.long:
            columns = res_fields.ALLOCATION_DETAILED_RESOURCE.fields
            labels = res_fields.ALLOCATION_DETAILED_RESOURCE.labels
        elif parsed_args.fields:
            fields = itertools.chain.from_iterable(parsed_args.fields)
            resource = res_fields.Resource(list(fields))
            columns = resource.fields
            labels = resource.labels
            params['fields'] = columns
        else:
            columns = res_fields.ALLOCATION_RESOURCE.fields
            labels = res_fields.ALLOCATION_RESOURCE.labels

        self.log.debug("params(%s)", params)
        data = client.allocation.list(**params)

        data = oscutils.sort_items(data, parsed_args.sort)

        return (labels, (oscutils.get_item_properties(s, columns)
                         for s in data))
Esempio n. 11
0
 def test_sort_excluded_override_labels(self):
     # Test excluding of fields for sort purposes and overriding labels
     foo = resource_fields.Resource(['item_3', 'item1', '2nd_item'],
                                    sort_excluded=['item1'],
                                    override_labels={'item_3': 'Three'})
     self.assertEqual(('Three', 'ITEM1', 'A second item'), foo.labels)
     self.assertEqual(('item_3', '2nd_item'), foo.sort_fields)
     self.assertEqual(('Three', 'A second item'), foo.sort_labels)
Esempio n. 12
0
 def test_sort_excluded(self):
     # Test excluding of fields for sort purposes
     foo = resource_fields.Resource(['item_3', 'item1', '2nd_item'],
                                    sort_excluded=['item1'])
     self.assertEqual(('item_3', '2nd_item'), foo.sort_fields)
     self.assertEqual(('Third item', 'A second item'), foo.sort_labels)