Add --uuid to port-create
Support specify port uuid to port-create like node-create Change-Id: Ifc187238134d4661c47efe8dea11e99c48e71a3e
This commit is contained in:
parent
5751b32932
commit
e8f251c007
@ -38,6 +38,9 @@ CREATE_PORT = copy.deepcopy(PORT)
|
||||
del CREATE_PORT['id']
|
||||
del CREATE_PORT['uuid']
|
||||
|
||||
CREATE_PORT_WITH_UUID = copy.deepcopy(PORT)
|
||||
del CREATE_PORT_WITH_UUID['id']
|
||||
|
||||
UPDATED_PORT = copy.deepcopy(PORT)
|
||||
NEW_ADDR = 'AA:AA:AA:AA:AA:AA'
|
||||
UPDATED_PORT['address'] = NEW_ADDR
|
||||
@ -290,6 +293,14 @@ class PortManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(port)
|
||||
|
||||
def test_create_with_uuid(self):
|
||||
port = self.mgr.create(**CREATE_PORT_WITH_UUID)
|
||||
expect = [
|
||||
('POST', '/v1/ports', {}, CREATE_PORT_WITH_UUID),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(port)
|
||||
|
||||
def test_delete(self):
|
||||
port = self.mgr.delete(port_id=PORT['uuid'])
|
||||
expect = [
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
import mock
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from ironicclient.common.apiclient import exceptions
|
||||
from ironicclient.common import cliutils
|
||||
from ironicclient.common import utils as commonutils
|
||||
@ -232,6 +234,14 @@ class PortShellTest(utils.BaseTestCase):
|
||||
p_shell.do_port_create(client_mock, args)
|
||||
client_mock.port.create.assert_called_once_with()
|
||||
|
||||
def test_do_port_create_with_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.uuid = uuidutils.generate_uuid()
|
||||
|
||||
p_shell.do_port_create(client_mock, args)
|
||||
client_mock.port.create.assert_called_once_with(uuid=args.uuid)
|
||||
|
||||
def test_do_port_create_valid_fields_values(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
|
@ -27,7 +27,7 @@ class Port(base.Resource):
|
||||
|
||||
class PortManager(base.CreateManager):
|
||||
resource_class = Port
|
||||
_creation_attributes = ['address', 'extra', 'node_uuid']
|
||||
_creation_attributes = ['address', 'extra', 'node_uuid', 'uuid']
|
||||
_resource_name = 'ports'
|
||||
|
||||
def list(self, address=None, limit=None, marker=None, sort_key=None,
|
||||
|
@ -148,15 +148,18 @@ def do_port_list(cc, args):
|
||||
action='append',
|
||||
help="Record arbitrary key/value metadata. "
|
||||
"Can be specified multiple times.")
|
||||
@cliutils.arg(
|
||||
'-u', '--uuid',
|
||||
metavar='<uuid>',
|
||||
help="UUID of the port.")
|
||||
def do_port_create(cc, args):
|
||||
"""Create a new port."""
|
||||
field_list = ['address', 'extra', 'node_uuid']
|
||||
field_list = ['address', 'extra', 'node_uuid', 'uuid']
|
||||
fields = dict((k, v) for (k, v) in vars(args).items()
|
||||
if k in field_list and not (v is None))
|
||||
fields = utils.args_array_to_dict(fields, 'extra')
|
||||
port = cc.port.create(**fields)
|
||||
|
||||
field_list.append('uuid')
|
||||
data = dict([(f, getattr(port, f, '')) for f in field_list])
|
||||
cliutils.print_dict(data, wrap=72)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user