Skip to content

Commit f1bd417

Browse files
committed
Add device ID and device owner to port unset
This adds support to unset the device_id and device_owner property on a port. Change-Id: I43b1ea63e3a119f57162948e128a85f8ba323d41
1 parent 966aede commit f1bd417

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,18 @@ def get_parser(self, prog_name):
13171317
default=False,
13181318
help=_("Clear hints for the port."),
13191319
)
1320+
parser.add_argument(
1321+
'--device',
1322+
action='store_true',
1323+
default=False,
1324+
help=_("Clear device ID for the port."),
1325+
)
1326+
parser.add_argument(
1327+
'--device-owner',
1328+
action='store_true',
1329+
default=False,
1330+
help=_("Clear device owner for the port."),
1331+
)
13201332
_tag.add_tag_option_to_parser_for_unset(parser, _('port'))
13211333
parser.add_argument(
13221334
'port',
@@ -1383,6 +1395,10 @@ def take_action(self, parsed_args):
13831395
attrs['binding:host_id'] = None
13841396
if parsed_args.hints:
13851397
attrs['hints'] = None
1398+
if parsed_args.device:
1399+
attrs['device_id'] = ''
1400+
if parsed_args.device_owner:
1401+
attrs['device_owner'] = ''
13861402

13871403
attrs.update(
13881404
self._parse_extra_properties(parsed_args.extra_properties)

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,3 +3015,43 @@ def test_unset_hints(self):
30153015
**{'hints': None},
30163016
)
30173017
self.assertIsNone(result)
3018+
3019+
def test_unset_device(self):
3020+
testport = network_fakes.create_one_port()
3021+
self.network_client.find_port = mock.Mock(return_value=testport)
3022+
arglist = [
3023+
'--device',
3024+
testport.name,
3025+
]
3026+
verifylist = [
3027+
('device', True),
3028+
('port', testport.name),
3029+
]
3030+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3031+
result = self.cmd.take_action(parsed_args)
3032+
3033+
self.network_client.update_port.assert_called_once_with(
3034+
testport,
3035+
**{'device_id': ''},
3036+
)
3037+
self.assertIsNone(result)
3038+
3039+
def test_unset_device_owner(self):
3040+
testport = network_fakes.create_one_port()
3041+
self.network_client.find_port = mock.Mock(return_value=testport)
3042+
arglist = [
3043+
'--device-owner',
3044+
testport.name,
3045+
]
3046+
verifylist = [
3047+
('device_owner', True),
3048+
('port', testport.name),
3049+
]
3050+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
3051+
result = self.cmd.take_action(parsed_args)
3052+
3053+
self.network_client.update_port.assert_called_once_with(
3054+
testport,
3055+
**{'device_owner': ''},
3056+
)
3057+
self.assertIsNone(result)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Added ``--device`` and ``--device-owner`` parameter to the
5+
``port unset`` command.

0 commit comments

Comments
 (0)