Client support port name

This patch implements port name support for the client.

Change-Id: Ida51028fbfdb52de0731ed55e4458ec67f41037b
Story: 2003091
Task: 23180
This commit is contained in:
Kaifeng Wang 2023-09-22 21:41:00 +08:00
parent bc19ec26d1
commit 0357ed5436
7 changed files with 41 additions and 6 deletions

View File

@ -37,7 +37,7 @@ from ironicclient import exc
# http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa # http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa
# for full details. # for full details.
DEFAULT_VER = '1.9' DEFAULT_VER = '1.9'
LAST_KNOWN_API_VERSION = 87 LAST_KNOWN_API_VERSION = 88
LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION) LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION)
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -106,6 +106,12 @@ class CreateBaremetalPort(command.ShowOne):
action='store_true', action='store_true',
help=_("Indicates whether this Port is a Smart NIC port")) help=_("Indicates whether this Port is a Smart NIC port"))
parser.add_argument(
'--name',
dest='name',
metavar='<port name>',
help=_("Name of the port."))
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -231,6 +237,12 @@ class UnsetBaremetalPort(command.Command):
action='store_true', action='store_true',
help=_("Set Port as not Smart NIC port")) 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 return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -251,6 +263,9 @@ class UnsetBaremetalPort(command.Command):
if parsed_args.is_smartnic: if parsed_args.is_smartnic:
properties.extend(utils.args_array_to_patch( properties.extend(utils.args_array_to_patch(
'add', ["is_smartnic=False"])) 'add', ["is_smartnic=False"]))
if parsed_args.name:
properties.extend(utils.args_array_to_patch('remove',
['name']))
if properties: if properties:
baremetal_client.port.update(parsed_args.port, properties) baremetal_client.port.update(parsed_args.port, properties)
@ -336,6 +351,12 @@ class SetBaremetalPort(command.Command):
action='store_true', action='store_true',
help=_("Set port to be Smart NIC port")) help=_("Set port to be Smart NIC port"))
parser.add_argument(
'--name',
metavar='<name>',
dest='name',
help=_("Set name for this port"))
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -372,6 +393,9 @@ class SetBaremetalPort(command.Command):
if parsed_args.is_smartnic: if parsed_args.is_smartnic:
is_smartnic = ["is_smartnic=%s" % parsed_args.is_smartnic] is_smartnic = ["is_smartnic=%s" % parsed_args.is_smartnic]
properties.extend(utils.args_array_to_patch('add', 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: if properties:
baremetal_client.port.update(parsed_args.port, properties) baremetal_client.port.update(parsed_args.port, properties)

View File

@ -750,7 +750,8 @@ class TestBaremetalPortList(TestBaremetalPort):
collist = ('UUID', 'Address', 'Created At', 'Extra', 'Node UUID', collist = ('UUID', 'Address', 'Created At', 'Extra', 'Node UUID',
'Local Link Connection', 'Portgroup UUID', 'Local Link Connection', 'Portgroup UUID',
'PXE boot enabled', 'Physical Network', 'Updated At', '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) self.assertEqual(collist, columns)
datalist = (( datalist = ((
@ -765,7 +766,8 @@ class TestBaremetalPortList(TestBaremetalPort):
'', '',
'', '',
'', '',
'' '',
'',
), ) ), )
self.assertEqual(datalist, tuple(data)) self.assertEqual(datalist, tuple(data))

View File

@ -30,7 +30,8 @@ PORT = {'uuid': '11111111-2222-3333-4444-555555555555',
'portgroup_uuid': '55555555-4444-3333-2222-111111111111', 'portgroup_uuid': '55555555-4444-3333-2222-111111111111',
'physical_network': 'physnet1', 'physical_network': 'physnet1',
'is_smartnic': False, 'is_smartnic': False,
'extra': {}} 'extra': {},
'name': 'port_name'}
PORT2 = {'uuid': '55555555-4444-3333-2222-111111111111', PORT2 = {'uuid': '55555555-4444-3333-2222-111111111111',
'node_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', 'portgroup_uuid': '55555555-4444-3333-2222-111111111111',
'physical_network': 'physnet2', 'physical_network': 'physnet2',
'is_smartnic': True, 'is_smartnic': True,
'extra': {}} 'extra': {},
'name': 'port2_name'}
CREATE_PORT = copy.deepcopy(PORT) CREATE_PORT = copy.deepcopy(PORT)
del CREATE_PORT['uuid'] del CREATE_PORT['uuid']
@ -306,6 +308,7 @@ class PortManagerTest(testtools.TestCase):
self.assertEqual(PORT['portgroup_uuid'], port.portgroup_uuid) self.assertEqual(PORT['portgroup_uuid'], port.portgroup_uuid)
self.assertEqual(PORT['physical_network'], port.physical_network) self.assertEqual(PORT['physical_network'], port.physical_network)
self.assertEqual(PORT['is_smartnic'], port.is_smartnic) self.assertEqual(PORT['is_smartnic'], port.is_smartnic)
self.assertEqual(PORT['name'], port.name)
def test_ports_show_by_address(self): def test_ports_show_by_address(self):
port = self.mgr.get_by_address(PORT['address']) port = self.mgr.get_by_address(PORT['address'])

View File

@ -29,7 +29,7 @@ class PortManager(base.CreateManager):
resource_class = Port resource_class = Port
_creation_attributes = ['address', 'extra', 'local_link_connection', _creation_attributes = ['address', 'extra', 'local_link_connection',
'node_uuid', 'physical_network', 'portgroup_uuid', 'node_uuid', 'physical_network', 'portgroup_uuid',
'pxe_enabled', 'uuid', 'is_smartnic'] 'pxe_enabled', 'uuid', 'is_smartnic', 'name']
_resource_name = 'ports' _resource_name = 'ports'
def list(self, address=None, limit=None, marker=None, sort_key=None, def list(self, address=None, limit=None, marker=None, sort_key=None,

View File

@ -157,6 +157,7 @@ class Resource(object):
'parent_node': 'Parent Node', 'parent_node': 'Parent Node',
'children': 'Child Nodes', 'children': 'Child Nodes',
'firmware_interface': 'Firmware Interface', 'firmware_interface': 'Firmware Interface',
'port_name': 'Port Name',
} }
def __init__(self, field_ids, sort_excluded=None, override_labels=None): def __init__(self, field_ids, sort_excluded=None, override_labels=None):
@ -345,6 +346,7 @@ PORT_DETAILED_RESOURCE = Resource(
'updated_at', 'updated_at',
'internal_info', 'internal_info',
'is_smartnic', 'is_smartnic',
'port_name',
], ],
sort_excluded=[ sort_excluded=[
'extra', 'extra',

View File

@ -0,0 +1,4 @@
---
features:
- |
Adds ``name`` field support, which is introduced in ironic API 1.88.