diff options
-rwxr-xr-x | ironicclient/osc/v1/baremetal_node.py | 41 | ||||
-rw-r--r-- | ironicclient/tests/unit/osc/v1/fakes.py | 10 | ||||
-rw-r--r-- | ironicclient/tests/unit/osc/v1/test_baremetal_node.py | 72 | ||||
-rw-r--r-- | ironicclient/v1/node.py | 19 | ||||
-rw-r--r-- | ironicclient/v1/resource_fields.py | 31 | ||||
-rw-r--r-- | releasenotes/notes/add-bios-registry-in-list-21974873f146aff7.yaml | 8 |
6 files changed, 169 insertions, 12 deletions
diff --git a/ironicclient/osc/v1/baremetal_node.py b/ironicclient/osc/v1/baremetal_node.py index 45b3b30..ece83f6 100755 --- a/ironicclient/osc/v1/baremetal_node.py +++ b/ironicclient/osc/v1/baremetal_node.py @@ -1978,15 +1978,52 @@ class ListBIOSSettingBaremetalNode(command.Lister): metavar='<node>', help=_("Name or UUID of the node") ) + display_group = parser.add_mutually_exclusive_group(required=False) + display_group.add_argument( + '--long', + default=False, + help=_("Show detailed information about the BIOS settings."), + action='store_true') + display_group.add_argument( + '--fields', + nargs='+', + dest='fields', + metavar='<field>', + action='append', + default=[], + choices=res_fields.BIOS_DETAILED_RESOURCE.fields, + help=_("One or more node fields. Only these fields will be " + "fetched from the server. Can not be used when '--long' " + "is specified.")) return parser def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) labels = res_fields.BIOS_RESOURCE.labels + fields = res_fields.BIOS_RESOURCE.fields + + params = {} + if parsed_args.long: + params['detail'] = parsed_args.long + fields = res_fields.BIOS_DETAILED_RESOURCE.fields + labels = res_fields.BIOS_DETAILED_RESOURCE.labels + elif parsed_args.fields: + params['detail'] = False + fields = itertools.chain.from_iterable(parsed_args.fields) + resource = res_fields.Resource(list(fields)) + fields = resource.fields + labels = resource.labels + params['fields'] = fields + + self.log.debug("params(%s)", params) + baremetal_client = self.app.client_manager.baremetal - settings = baremetal_client.node.list_bios_settings(parsed_args.node) - return (labels, [[s['name'], s['value']] for s in settings]) + settings = baremetal_client.node.list_bios_settings(parsed_args.node, + **params) + + return (labels, + (oscutils.get_dict_properties(s, fields) for s in settings)) class BIOSSettingShowBaremetalNode(command.ShowOne): diff --git a/ironicclient/tests/unit/osc/v1/fakes.py b/ironicclient/tests/unit/osc/v1/fakes.py index f506943..111fd7f 100644 --- a/ironicclient/tests/unit/osc/v1/fakes.py +++ b/ironicclient/tests/unit/osc/v1/fakes.py @@ -152,6 +152,16 @@ TRAITS = ['CUSTOM_FOO', 'CUSTOM_BAR'] BIOS_SETTINGS = [{'name': 'bios_name_1', 'value': 'bios_value_1', 'links': []}, {'name': 'bios_name_2', 'value': 'bios_value_2', 'links': []}] +BIOS_DETAILED_SETTINGS = [{'name': 'SysName', 'value': 'my-system', + 'links': [], 'attribute_type': 'String', + 'min_length': '1', 'max_length': '16'}, + {'name': 'NumCores', 'value': '10', + 'links': [], 'attribute_type': 'Integer', + 'lower_bound': '10', 'upper_bound': '20'}, + {'name': 'ProcVirtualization', 'value': 'Enabled', + 'links': [], 'attribute_type': 'Enumeration', + 'allowable_values': ['Enabled', 'Disabled']}] + baremetal_volume_connector_uuid = 'vvv-cccccc-vvvv' baremetal_volume_connector_type = 'iqn' baremetal_volume_connector_connector_id = 'iqn.2017-01.connector' diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py index 7b17e47..55bf062 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py @@ -4031,14 +4031,76 @@ class TestListBIOSSetting(TestBaremetal): parsed_args = self.check_parser(self.cmd, arglist, verifylist) - data = self.cmd.take_action(parsed_args) + columns, data = self.cmd.take_action(parsed_args) self.baremetal_mock.node.list_bios_settings.assert_called_once_with( 'node_uuid') - expected_data = (('BIOS setting name', 'BIOS setting value'), - [[s['name'], s['value']] - for s in baremetal_fakes.BIOS_SETTINGS]) - self.assertEqual(expected_data, data) + expected_columns = ('BIOS setting name', 'BIOS setting value') + self.assertEqual(expected_columns, columns) + + expected_data = ([(s['name'], s['value']) + for s in baremetal_fakes.BIOS_SETTINGS]) + self.assertEqual(tuple(expected_data), tuple(data)) + + def test_baremetal_list_bios_setting_long(self): + verifylist = [ + ('long', True), + ] + + arglist = ['node_uuid', '--long'] + verifylist = [('node', 'node_uuid'), ('long', True)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.baremetal_mock.node.list_bios_settings.return_value = ( + baremetal_fakes.BIOS_DETAILED_SETTINGS) + + columns, data = self.cmd.take_action(parsed_args) + + kwargs = { + 'detail': True, + } + + self.baremetal_mock.node.list_bios_settings.assert_called_once_with( + 'node_uuid', **kwargs) + expected_columns = ('Name', 'Value', 'Attribute Type', + 'Allowable Values', 'Lower Bound', + 'Minimum Length', 'Maximum Length', 'Read Only', + 'Reset Required', 'Unique', 'Upper Bound') + self.assertEqual(expected_columns, columns) + + expected_data = (('SysName', 'my-system', 'String', '', '', '1', '16', + '', '', '', ''), + ('NumCores', '10', 'Integer', '', '10', '', '', '', + '', '', '20'), + ('ProcVirtualization', 'Enabled', + 'Enumeration', ['Enabled', 'Disabled'], '', '', '', + '', '', '', '')) + self.assertEqual(expected_data, tuple(data)) + + def test_baremetal_list_bios_setting_fields(self): + + arglist = ['node_uuid', '--fields', 'name', 'attribute_type'] + verifylist = [ + ('fields', [['name', 'attribute_type']]), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.baremetal_mock.node.list_bios_settings.return_value = ( + baremetal_fakes.BIOS_DETAILED_SETTINGS) + + columns, data = self.cmd.take_action(parsed_args) + self.assertNotIn('Value', columns) + self.assertIn('Name', columns) + self.assertIn('Attribute Type', columns) + + kwargs = { + 'detail': False, + 'fields': ('name', 'attribute_type'), + } + + self.baremetal_mock.node.list_bios_settings.assert_called_with( + 'node_uuid', **kwargs) class TestBIOSSettingShow(TestBaremetal): diff --git a/ironicclient/v1/node.py b/ironicclient/v1/node.py index 88879f0..509227a 100644 --- a/ironicclient/v1/node.py +++ b/ironicclient/v1/node.py @@ -847,8 +847,8 @@ class NodeManager(base.CreateManager): path, os_ironic_api_version=os_ironic_api_version, global_request_id=global_request_id).get(name) - def list_bios_settings(self, node_ident, os_ironic_api_version=None, - global_request_id=None): + def list_bios_settings(self, node_ident, detail=False, fields=None, + os_ironic_api_version=None, global_request_id=None): """List all BIOS settings from a node. :param node_ident: node UUID or name. @@ -856,8 +856,23 @@ class NodeManager(base.CreateManager): the request. If not specified, the client's default is used. :param global_request_id: String containing global request ID header value (in form "req-<UUID>") to use for the request. + :param detail: Optional, boolean whether to return detailed information + about bios settings. + :param fields: Optional, a list with a specified set of fields + of the resource to be returned. Can not be used + when 'detail' is set. + """ + if detail and fields: + raise exc.InvalidAttribute(_("Can't fetch a subset of fields " + "with 'detail' set")) + + filters = utils.common_filters(detail=detail, fields=fields) path = "%s/bios" % node_ident + + if filters: + path += '?' + '&'.join(filters) + return self._list_primitives( self._path(path), 'bios', os_ironic_api_version=os_ironic_api_version, diff --git a/ironicclient/v1/resource_fields.py b/ironicclient/v1/resource_fields.py index 4cc274c..76cfaca 100644 --- a/ironicclient/v1/resource_fields.py +++ b/ironicclient/v1/resource_fields.py @@ -34,11 +34,11 @@ class Resource(object): 'address': 'Address', 'alive': 'Alive', 'allocation_uuid': 'Allocation UUID', + 'allowable_values': 'Allowable Values', 'async': 'Async', + 'attribute_type': 'Attribute Type', 'automated_clean': 'Automated Clean', 'attach': 'Response is attachment', - 'bios_name': 'BIOS setting name', - 'bios_value': 'BIOS setting value', 'boot_index': 'Boot Index', 'boot_mode': 'Boot Mode', 'candidate_nodes': 'Candidate Nodes', @@ -89,9 +89,12 @@ class Resource(object): 'internal_info': 'Internal Info', 'last_error': 'Last Error', 'lessee': 'Lessee', + 'lower_bound': 'Lower Bound', 'maintenance': 'Maintenance', 'maintenance_reason': 'Maintenance Reason', + 'max_length': 'Maximum Length', 'fault': 'Fault', + 'min_length': 'Minimum Length', 'mode': 'Mode', 'name': 'Name', 'network_data': 'Network Configuration', @@ -104,6 +107,8 @@ class Resource(object): 'provision_state': 'Provisioning State', 'provision_updated_at': 'Provision Updated At', 'raid_config': 'Current RAID configuration', + 'read_only': 'Read Only', + 'reset_required': 'Reset Required', 'reservation': 'Reservation', 'resource_class': 'Resource Class', 'retired': 'Retired', @@ -118,6 +123,7 @@ class Resource(object): 'type': 'Type', 'updated_at': 'Updated At', 'uuid': 'UUID', + 'value': 'Value', 'volume_id': 'Volume ID', 'volume_type': 'Driver Volume Type', 'local_link_connection': 'Local Link Connection', @@ -134,6 +140,8 @@ class Resource(object): 'raid_interface': 'RAID Interface', 'rescue_interface': 'Rescue Interface', 'storage_interface': 'Storage Interface', + 'unique': 'Unique', + 'upper_bound': 'Upper Bound', 'vendor_interface': 'Vendor Interface', 'standalone_ports_supported': 'Standalone Ports Supported', 'physical_network': 'Physical Network', @@ -381,7 +389,24 @@ TRAIT_RESOURCE = Resource( ) BIOS_RESOURCE = Resource( - ['bios_name', 'bios_value'], + ['name', 'value'], + override_labels={'name': 'BIOS setting name', + 'value': 'BIOS setting value'} +) + +BIOS_DETAILED_RESOURCE = Resource( + ['name', + 'value', + 'attribute_type', + 'allowable_values', + 'lower_bound', + 'min_length', + 'max_length', + 'read_only', + 'reset_required', + 'unique', + 'upper_bound' + ], ) # Drivers diff --git a/releasenotes/notes/add-bios-registry-in-list-21974873f146aff7.yaml b/releasenotes/notes/add-bios-registry-in-list-21974873f146aff7.yaml new file mode 100644 index 0000000..6f79445 --- /dev/null +++ b/releasenotes/notes/add-bios-registry-in-list-21974873f146aff7.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Adds new params to the ``baremetal node bios setting list`` command to + include support for the BIOS registry. The ``--long`` option will + retrieve and display the additonal BIOS registry fields, the ``--fields`` + option will retrieve and display selected fields. The ``baremetal node + bios setting show`` includes these fields by default with no changes. |