Skip to content

Commit 73d15e3

Browse files
author
reedip
committed
Add option to clear information from ports
This patch adds the option of "no-fixed-ip" and "no-binding-profile" which is used to clear the fixed-ip and binding:profile information from the ports. Change-Id: I946301eaf6c647bae55e4f416aa0d98e5f06e699
1 parent 0edab95 commit 73d15e3

4 files changed

Lines changed: 64 additions & 17 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ Set port properties
123123
.. code:: bash
124124
125125
os port set
126-
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
126+
[--fixed-ip subnet=<subnet>,ip-address=<ip-address> | --no-fixed-ip]
127127
[--device-id <device-id>]
128128
[--device-owner <device-owner>]
129129
[--vnic-type <vnic-type>]
130-
[--binding-profile <binding-profile>]
130+
[--binding-profile <binding-profile> | --no-binding-profile]
131131
[--host-id <host-id>]
132132
[--enable | --disable]
133133
[--name <name>]
@@ -139,6 +139,10 @@ Set port properties
139139
subnet=<subnet>,ip-address=<ip-address>
140140
(you can repeat this option)
141141
142+
.. option:: --no-fixed-ip
143+
144+
Clear existing information of fixed-ips
145+
142146
.. option:: --device-id <device-id>
143147
144148
Device ID of this port
@@ -157,6 +161,10 @@ Set port properties
157161
Custom data to be passed as binding:profile: <key>=<value>
158162
(this option can be repeated)
159163
164+
.. option:: --no-binding-profile
165+
166+
Clear existing information of binding:profile
167+
160168
.. option:: --host-id <host-id>
161169
162170
The ID of the host where the port is allocated

openstackclient/network/v2/port.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ def _prepare_fixed_ips(client_manager, parsed_args):
151151

152152

153153
def _add_updatable_args(parser):
154-
parser.add_argument(
155-
'--fixed-ip',
156-
metavar='subnet=<subnet>,ip-address=<ip-address>',
157-
action=parseractions.MultiKeyValueAction,
158-
optional_keys=['subnet', 'ip-address'],
159-
help='Desired IP and/or subnet (name or ID) for this port: '
160-
'subnet=<subnet>,ip-address=<ip-address> '
161-
'(this option can be repeated)')
162154
# NOTE(dtroyer): --device-id is deprecated in Mar 2016. Do not
163155
# remove before 3.x release or Mar 2017.
164156
device_group = parser.add_mutually_exclusive_group()
@@ -184,12 +176,6 @@ def _add_updatable_args(parser):
184176
help="VNIC type for this port (direct | direct-physical |"
185177
" macvtap | normal | baremetal). If unspecified during"
186178
" port creation, default value will be 'normal'.")
187-
parser.add_argument(
188-
'--binding-profile',
189-
metavar='<binding-profile>',
190-
action=parseractions.KeyValueAction,
191-
help='Custom data to be passed as binding:profile: <key>=<value> '
192-
'(this option can be repeated)')
193179
# NOTE(dtroyer): --host-id is deprecated in Mar 2016. Do not
194180
# remove before 3.x release or Mar 2017.
195181
host_group = parser.add_mutually_exclusive_group()
@@ -217,6 +203,20 @@ def get_parser(self, prog_name):
217203
required=True,
218204
help='Network this port belongs to (name or ID)')
219205
_add_updatable_args(parser)
206+
parser.add_argument(
207+
'--fixed-ip',
208+
metavar='subnet=<subnet>,ip-address=<ip-address>',
209+
action=parseractions.MultiKeyValueAction,
210+
optional_keys=['subnet', 'ip-address'],
211+
help='Desired IP and/or subnet (name or ID) for this port: '
212+
'subnet=<subnet>,ip-address=<ip-address> '
213+
'(this option can be repeated)')
214+
parser.add_argument(
215+
'--binding-profile',
216+
metavar='<binding-profile>',
217+
action=parseractions.KeyValueAction,
218+
help='Custom data to be passed as binding:profile: <key>=<value> '
219+
'(this option can be repeated)')
220220
admin_group = parser.add_mutually_exclusive_group()
221221
admin_group.add_argument(
222222
'--enable',
@@ -352,7 +352,30 @@ def get_parser(self, prog_name):
352352
metavar="<port>",
353353
help=("Port to modify (name or ID)")
354354
)
355-
355+
fixed_ip = parser.add_mutually_exclusive_group()
356+
fixed_ip.add_argument(
357+
'--fixed-ip',
358+
metavar='subnet=<subnet>,ip-address=<ip-address>',
359+
action=parseractions.MultiKeyValueAction,
360+
optional_keys=['subnet', 'ip-address'],
361+
help='Desired IP and/or subnet (name or ID) for this port: '
362+
'subnet=<subnet>,ip-address=<ip-address> '
363+
'(this option can be repeated)')
364+
fixed_ip.add_argument(
365+
'--no-fixed-ip',
366+
action='store_true',
367+
help='Clear existing information of fixed-ips')
368+
binding_profile = parser.add_mutually_exclusive_group()
369+
binding_profile.add_argument(
370+
'--binding-profile',
371+
metavar='<binding-profile>',
372+
action=parseractions.KeyValueAction,
373+
help='Custom data to be passed as binding:profile: <key>=<value> '
374+
'(this option can be repeated)')
375+
binding_profile.add_argument(
376+
'--no-binding-profile',
377+
action='store_true',
378+
help='Clear existing information of binding:profile')
356379
return parser
357380

358381
def take_action(self, parsed_args):
@@ -361,6 +384,11 @@ def take_action(self, parsed_args):
361384
_prepare_fixed_ips(self.app.client_manager, parsed_args)
362385
attrs = _get_attrs(self.app.client_manager, parsed_args)
363386

387+
if parsed_args.no_fixed_ip:
388+
attrs['fixed_ips'] = []
389+
if parsed_args.no_binding_profile:
390+
attrs['binding:profile'] = {}
391+
364392
if attrs == {}:
365393
msg = "Nothing specified to be set"
366394
raise exceptions.CommandError(msg)

openstackclient/tests/network/v2/test_port.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,23 @@ def test_set_fixed_ip(self):
298298
def test_set_this(self):
299299
arglist = [
300300
'--disable',
301+
'--no-fixed-ip',
302+
'--no-binding-profile',
301303
self._port.name,
302304
]
303305
verifylist = [
304306
('disable', True),
307+
('no_binding_profile', True),
308+
('no_fixed_ip', True),
305309
]
306310

307311
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
308312
result = self.cmd.take_action(parsed_args)
309313

310314
attrs = {
311315
'admin_state_up': False,
316+
'binding:profile': {},
317+
'fixed_ips': [],
312318
}
313319
self.network.update_port.assert_called_once_with(self._port, **attrs)
314320
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+
- Fixed-IP information and binding profile information
4+
in ports can now be cleared using ``--no-fixed-ip``
5+
and ``--no-binding-profile`` with ``port set``

0 commit comments

Comments
 (0)