From 0357ed5436e28140fee4b4515a8222b7f2086735 Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Fri, 22 Sep 2023 21:41:00 +0800 Subject: [PATCH] Client support port name This patch implements port name support for the client. Change-Id: Ida51028fbfdb52de0731ed55e4458ec67f41037b Story: 2003091 Task: 23180 --- ironicclient/common/http.py | 2 +- ironicclient/osc/v1/baremetal_port.py | 24 +++++++++++++++++++ .../tests/unit/osc/v1/test_baremetal_port.py | 6 +++-- ironicclient/tests/unit/v1/test_port.py | 7 ++++-- ironicclient/v1/port.py | 2 +- ironicclient/v1/resource_fields.py | 2 ++ .../notes/port-name-6b1bf35a3939bedb.yaml | 4 ++++ 7 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/port-name-6b1bf35a3939bedb.yaml diff --git a/ironicclient/common/http.py b/ironicclient/common/http.py index b481545ab..9cad35560 100644 --- a/ironicclient/common/http.py +++ b/ironicclient/common/http.py @@ -37,7 +37,7 @@ from ironicclient import exc # http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa # for full details. DEFAULT_VER = '1.9' -LAST_KNOWN_API_VERSION = 87 +LAST_KNOWN_API_VERSION = 88 LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION) LOG = logging.getLogger(__name__) diff --git a/ironicclient/osc/v1/baremetal_port.py b/ironicclient/osc/v1/baremetal_port.py index ceb670230..bd79eb18e 100644 --- a/ironicclient/osc/v1/baremetal_port.py +++ b/ironicclient/osc/v1/baremetal_port.py @@ -106,6 +106,12 @@ class CreateBaremetalPort(command.ShowOne): action='store_true', help=_("Indicates whether this Port is a Smart NIC port")) + parser.add_argument( + '--name', + dest='name', + metavar='', + help=_("Name of the port.")) + return parser def take_action(self, parsed_args): @@ -231,6 +237,12 @@ class UnsetBaremetalPort(command.Command): action='store_true', help=_("Set Port as not Smart NIC port")) + parser.add_argument( + '--name', + dest='name', + action='store_true', + help=_("Unset the name for this port")) + return parser def take_action(self, parsed_args): @@ -251,6 +263,9 @@ class UnsetBaremetalPort(command.Command): if parsed_args.is_smartnic: properties.extend(utils.args_array_to_patch( 'add', ["is_smartnic=False"])) + if parsed_args.name: + properties.extend(utils.args_array_to_patch('remove', + ['name'])) if properties: baremetal_client.port.update(parsed_args.port, properties) @@ -336,6 +351,12 @@ class SetBaremetalPort(command.Command): action='store_true', help=_("Set port to be Smart NIC port")) + parser.add_argument( + '--name', + metavar='', + dest='name', + help=_("Set name for this port")) + return parser def take_action(self, parsed_args): @@ -372,6 +393,9 @@ class SetBaremetalPort(command.Command): if parsed_args.is_smartnic: is_smartnic = ["is_smartnic=%s" % parsed_args.is_smartnic] properties.extend(utils.args_array_to_patch('add', is_smartnic)) + if parsed_args.name: + port_name = ["name=%s" % parsed_args.name] + properties.extend(utils.args_array_to_patch('add', port_name)) if properties: baremetal_client.port.update(parsed_args.port, properties) diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_port.py b/ironicclient/tests/unit/osc/v1/test_baremetal_port.py index 2b8fde49a..6140ec3c3 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_port.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_port.py @@ -750,7 +750,8 @@ class TestBaremetalPortList(TestBaremetalPort): collist = ('UUID', 'Address', 'Created At', 'Extra', 'Node UUID', 'Local Link Connection', 'Portgroup UUID', 'PXE boot enabled', 'Physical Network', 'Updated At', - 'Internal Info', 'Is Smart NIC port') + 'Internal Info', 'Is Smart NIC port', + 'Port Name') self.assertEqual(collist, columns) datalist = (( @@ -765,7 +766,8 @@ class TestBaremetalPortList(TestBaremetalPort): '', '', '', - '' + '', + '', ), ) self.assertEqual(datalist, tuple(data)) diff --git a/ironicclient/tests/unit/v1/test_port.py b/ironicclient/tests/unit/v1/test_port.py index 89a947857..6da09f3c6 100644 --- a/ironicclient/tests/unit/v1/test_port.py +++ b/ironicclient/tests/unit/v1/test_port.py @@ -30,7 +30,8 @@ PORT = {'uuid': '11111111-2222-3333-4444-555555555555', 'portgroup_uuid': '55555555-4444-3333-2222-111111111111', 'physical_network': 'physnet1', 'is_smartnic': False, - 'extra': {}} + 'extra': {}, + 'name': 'port_name'} PORT2 = {'uuid': '55555555-4444-3333-2222-111111111111', 'node_uuid': '55555555-4444-3333-2222-111111111111', @@ -40,7 +41,8 @@ PORT2 = {'uuid': '55555555-4444-3333-2222-111111111111', 'portgroup_uuid': '55555555-4444-3333-2222-111111111111', 'physical_network': 'physnet2', 'is_smartnic': True, - 'extra': {}} + 'extra': {}, + 'name': 'port2_name'} CREATE_PORT = copy.deepcopy(PORT) del CREATE_PORT['uuid'] @@ -306,6 +308,7 @@ class PortManagerTest(testtools.TestCase): self.assertEqual(PORT['portgroup_uuid'], port.portgroup_uuid) self.assertEqual(PORT['physical_network'], port.physical_network) self.assertEqual(PORT['is_smartnic'], port.is_smartnic) + self.assertEqual(PORT['name'], port.name) def test_ports_show_by_address(self): port = self.mgr.get_by_address(PORT['address']) diff --git a/ironicclient/v1/port.py b/ironicclient/v1/port.py index 403c22320..43b6dfa12 100644 --- a/ironicclient/v1/port.py +++ b/ironicclient/v1/port.py @@ -29,7 +29,7 @@ class PortManager(base.CreateManager): resource_class = Port _creation_attributes = ['address', 'extra', 'local_link_connection', 'node_uuid', 'physical_network', 'portgroup_uuid', - 'pxe_enabled', 'uuid', 'is_smartnic'] + 'pxe_enabled', 'uuid', 'is_smartnic', 'name'] _resource_name = 'ports' def list(self, address=None, limit=None, marker=None, sort_key=None, diff --git a/ironicclient/v1/resource_fields.py b/ironicclient/v1/resource_fields.py index 4cbab2bc6..908ec1d5e 100644 --- a/ironicclient/v1/resource_fields.py +++ b/ironicclient/v1/resource_fields.py @@ -157,6 +157,7 @@ class Resource(object): 'parent_node': 'Parent Node', 'children': 'Child Nodes', 'firmware_interface': 'Firmware Interface', + 'port_name': 'Port Name', } def __init__(self, field_ids, sort_excluded=None, override_labels=None): @@ -345,6 +346,7 @@ PORT_DETAILED_RESOURCE = Resource( 'updated_at', 'internal_info', 'is_smartnic', + 'port_name', ], sort_excluded=[ 'extra', diff --git a/releasenotes/notes/port-name-6b1bf35a3939bedb.yaml b/releasenotes/notes/port-name-6b1bf35a3939bedb.yaml new file mode 100644 index 000000000..73b49f825 --- /dev/null +++ b/releasenotes/notes/port-name-6b1bf35a3939bedb.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Adds ``name`` field support, which is introduced in ironic API 1.88.