port-list support get-port-from-mac
cli command port-show use the restapi 'get /v1/port/detail?address ={macaddress}', it also lack restapi 'get /v1/port?address={mac}' add port-list to get the port which has macaddress: ironic port-list --address {macaddress} ironic port-list --address {macaddress} --detail Change-Id: I4d836940974812360066b7d977472991235cb5c9 Closes-Bug: #1416627
This commit is contained in:
parent
f21df697cf
commit
92dd20bdcb
|
@ -84,6 +84,13 @@ fake_responses = {
|
|||
{"ports": [PORT]},
|
||||
),
|
||||
},
|
||||
'/v1/ports/?address=%s' % PORT['address']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"ports": [PORT]},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fake_responses_pagination = {
|
||||
|
@ -144,6 +151,22 @@ class PortManagerTest(testtools.TestCase):
|
|||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(ports))
|
||||
|
||||
def test_ports_list_by_address(self):
|
||||
ports = self.mgr.list(address=PORT['address'])
|
||||
expect = [
|
||||
('GET', '/v1/ports/?address=%s' % PORT['address'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(ports))
|
||||
|
||||
def test_ports_list_by_address_detail(self):
|
||||
ports = self.mgr.list(address=PORT['address'], detail=True)
|
||||
expect = [
|
||||
('GET', '/v1/ports/detail?address=%s' % PORT['address'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(ports))
|
||||
|
||||
def test_ports_list_detail(self):
|
||||
ports = self.mgr.list(detail=True)
|
||||
expect = [
|
||||
|
|
|
@ -33,10 +33,12 @@ class PortManager(base.Manager):
|
|||
def _path(id=None):
|
||||
return '/v1/ports/%s' % id if id else '/v1/ports'
|
||||
|
||||
def list(self, limit=None, marker=None, sort_key=None,
|
||||
def list(self, address=None, limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
"""Retrieve a list of port.
|
||||
|
||||
:param address: Optional, MAC address of a port, to get
|
||||
the port which has this MAC address
|
||||
:param marker: Optional, the UUID of a port, eg the last
|
||||
port from a previous result set. Return
|
||||
the next result set.
|
||||
|
@ -64,6 +66,8 @@ class PortManager(base.Manager):
|
|||
limit = int(limit)
|
||||
|
||||
filters = utils.common_filters(marker, limit, sort_key, sort_dir)
|
||||
if address is not None:
|
||||
filters.append('address=%s' % address)
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
|
|
|
@ -49,6 +49,11 @@ def do_port_show(cc, args):
|
|||
action='store_true',
|
||||
default=False,
|
||||
help="Show detailed information about ports.")
|
||||
@cliutils.arg(
|
||||
'--address',
|
||||
metavar='<macaddress>',
|
||||
help='MAC address of port, to get the port'
|
||||
'which has this address')
|
||||
@cliutils.arg(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
|
@ -73,6 +78,10 @@ def do_port_show(cc, args):
|
|||
help='Sort direction: one of "asc" (the default) or "desc".')
|
||||
def do_port_list(cc, args):
|
||||
"""List ports."""
|
||||
params = {}
|
||||
|
||||
if args.address is not None:
|
||||
params['address'] = args.address
|
||||
if args.detail:
|
||||
fields = res_fields.PORT_FIELDS
|
||||
field_labels = res_fields.PORT_FIELD_LABELS
|
||||
|
@ -80,7 +89,9 @@ def do_port_list(cc, args):
|
|||
fields = res_fields.PORT_LIST_FIELDS
|
||||
field_labels = res_fields.PORT_LIST_FIELD_LABELS
|
||||
|
||||
params = utils.common_params_for_list(args, fields, field_labels)
|
||||
params.update(utils.common_params_for_list(args,
|
||||
fields,
|
||||
field_labels))
|
||||
|
||||
port = cc.port.list(**params)
|
||||
cliutils.print_list(port, fields,
|
||||
|
|
Loading…
Reference in New Issue