Add baremetal port show command to OSC plugin
Change-Id: Id43d2fb6b734a8625c3780e1c226d81c7f24ae79 Partial-Bug: #1526479
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cliff import show
|
from cliff import show
|
||||||
@@ -77,3 +78,51 @@ class CreateBaremetalPort(show.ShowOne):
|
|||||||
res_fields.PORT_DETAILED_RESOURCE.fields])
|
res_fields.PORT_DETAILED_RESOURCE.fields])
|
||||||
|
|
||||||
return self.dict2columns(data)
|
return self.dict2columns(data)
|
||||||
|
|
||||||
|
|
||||||
|
class ShowBaremetalPort(show.ShowOne):
|
||||||
|
"""Show baremetal port details."""
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__ + ".ShowBaremetalPort")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShowBaremetalPort, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
"port",
|
||||||
|
metavar="<id>",
|
||||||
|
help="UUID of the port (or MAC address if --address is specified)."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--address',
|
||||||
|
dest='address',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='<id> is the MAC address (instead of the UUID) of the port.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--fields',
|
||||||
|
nargs='+',
|
||||||
|
dest='fields',
|
||||||
|
metavar='<field>',
|
||||||
|
action='append',
|
||||||
|
choices=res_fields.PORT_DETAILED_RESOURCE.fields,
|
||||||
|
default=[],
|
||||||
|
help="One or more port fields. Only these fields will be fetched "
|
||||||
|
"from the server.")
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
self.log.debug("take_action(%s)", parsed_args)
|
||||||
|
|
||||||
|
baremetal_client = self.app.client_manager.baremetal
|
||||||
|
fields = list(itertools.chain.from_iterable(parsed_args.fields))
|
||||||
|
fields = fields if fields else None
|
||||||
|
|
||||||
|
if parsed_args.address:
|
||||||
|
port = baremetal_client.port.get_by_address(
|
||||||
|
parsed_args.port, fields=fields)._info
|
||||||
|
else:
|
||||||
|
port = baremetal_client.port.get(
|
||||||
|
parsed_args.port, fields=fields)._info
|
||||||
|
|
||||||
|
port.pop("links", None)
|
||||||
|
return zip(*sorted(port.items()))
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from openstackclient.tests import utils as oscutils
|
||||||
|
|
||||||
from ironicclient.osc.v1 import baremetal_port
|
from ironicclient.osc.v1 import baremetal_port
|
||||||
from ironicclient.tests.unit.osc.v1 import fakes as baremetal_fakes
|
from ironicclient.tests.unit.osc.v1 import fakes as baremetal_fakes
|
||||||
|
|
||||||
@@ -66,3 +68,67 @@ class TestCreateBaremetalPort(TestBaremetalPort):
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.baremetal_mock.port.create.assert_called_once_with(**args)
|
self.baremetal_mock.port.create.assert_called_once_with(**args)
|
||||||
|
|
||||||
|
|
||||||
|
class TestShowBaremetalPort(TestBaremetalPort):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShowBaremetalPort, self).setUp()
|
||||||
|
|
||||||
|
self.baremetal_mock.port.get.return_value = (
|
||||||
|
baremetal_fakes.FakeBaremetalResource(
|
||||||
|
None,
|
||||||
|
copy.deepcopy(baremetal_fakes.BAREMETAL_PORT),
|
||||||
|
loaded=True))
|
||||||
|
|
||||||
|
self.baremetal_mock.port.get_by_address.return_value = (
|
||||||
|
baremetal_fakes.FakeBaremetalResource(
|
||||||
|
None,
|
||||||
|
copy.deepcopy(baremetal_fakes.BAREMETAL_PORT),
|
||||||
|
loaded=True))
|
||||||
|
|
||||||
|
self.cmd = baremetal_port.ShowBaremetalPort(self.app, None)
|
||||||
|
|
||||||
|
def test_baremetal_port_show(self):
|
||||||
|
arglist = ['zzz-zzzzzz-zzzz']
|
||||||
|
verifylist = [('port', baremetal_fakes.baremetal_port_uuid)]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Set expected values
|
||||||
|
args = ['zzz-zzzzzz-zzzz']
|
||||||
|
self.baremetal_mock.port.get.assert_called_with(*args, fields=None)
|
||||||
|
|
||||||
|
collist = (
|
||||||
|
'address',
|
||||||
|
'extra',
|
||||||
|
'node_uuid',
|
||||||
|
'uuid')
|
||||||
|
self.assertEqual(collist, columns)
|
||||||
|
|
||||||
|
datalist = (
|
||||||
|
baremetal_fakes.baremetal_port_address,
|
||||||
|
baremetal_fakes.baremetal_port_extra,
|
||||||
|
baremetal_fakes.baremetal_uuid,
|
||||||
|
baremetal_fakes.baremetal_port_uuid)
|
||||||
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
|
def test_baremetal_port_show_address(self):
|
||||||
|
|
||||||
|
arglist = ['--address', baremetal_fakes.baremetal_port_address]
|
||||||
|
verifylist = [('address', True)]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
args = {'AA:BB:CC:DD:EE:FF'}
|
||||||
|
self.baremetal_mock.port.get_by_address.assert_called_with(
|
||||||
|
*args, fields=None)
|
||||||
|
|
||||||
|
def test_baremetal_port_show_no_port(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
self.assertRaises(oscutils.ParserException,
|
||||||
|
self.check_parser,
|
||||||
|
self.cmd, arglist, verifylist)
|
||||||
|
6
releasenotes/notes/osc-plugin-9b5344aceb886cc1.yaml
Normal file
6
releasenotes/notes/osc-plugin-9b5344aceb886cc1.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Extend the OpenStackClient plugin with new commands:
|
||||||
|
|
||||||
|
* openstack baremetal port show
|
@@ -50,6 +50,7 @@ openstack.baremetal.v1 =
|
|||||||
baremetal_node_undeploy = ironicclient.osc.v1.baremetal_node:UndeployBaremetalNode
|
baremetal_node_undeploy = ironicclient.osc.v1.baremetal_node:UndeployBaremetalNode
|
||||||
baremetal_node_unset = ironicclient.osc.v1.baremetal_node:UnsetBaremetalNode
|
baremetal_node_unset = ironicclient.osc.v1.baremetal_node:UnsetBaremetalNode
|
||||||
baremetal_port_create = ironicclient.osc.v1.baremetal_port:CreateBaremetalPort
|
baremetal_port_create = ironicclient.osc.v1.baremetal_port:CreateBaremetalPort
|
||||||
|
baremetal_port_show = ironicclient.osc.v1.baremetal_port:ShowBaremetalPort
|
||||||
baremetal_set = ironicclient.osc.v1.baremetal_node:SetBaremetal
|
baremetal_set = ironicclient.osc.v1.baremetal_node:SetBaremetal
|
||||||
baremetal_show = ironicclient.osc.v1.baremetal_node:ShowBaremetal
|
baremetal_show = ironicclient.osc.v1.baremetal_node:ShowBaremetal
|
||||||
baremetal_unset = ironicclient.osc.v1.baremetal_node:UnsetBaremetal
|
baremetal_unset = ironicclient.osc.v1.baremetal_node:UnsetBaremetal
|
||||||
|
Reference in New Issue
Block a user