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
This commit is contained in:
reedip 2016-04-01 14:26:16 +09:00
parent 0edab95fd1
commit 73d15e3768
4 changed files with 64 additions and 17 deletions

View File

@ -123,11 +123,11 @@ Set port properties
.. code:: bash
os port set
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
[--fixed-ip subnet=<subnet>,ip-address=<ip-address> | --no-fixed-ip]
[--device-id <device-id>]
[--device-owner <device-owner>]
[--vnic-type <vnic-type>]
[--binding-profile <binding-profile>]
[--binding-profile <binding-profile> | --no-binding-profile]
[--host-id <host-id>]
[--enable | --disable]
[--name <name>]
@ -139,6 +139,10 @@ Set port properties
subnet=<subnet>,ip-address=<ip-address>
(you can repeat this option)
.. option:: --no-fixed-ip
Clear existing information of fixed-ips
.. option:: --device-id <device-id>
Device ID of this port
@ -157,6 +161,10 @@ Set port properties
Custom data to be passed as binding:profile: <key>=<value>
(this option can be repeated)
.. option:: --no-binding-profile
Clear existing information of binding:profile
.. option:: --host-id <host-id>
The ID of the host where the port is allocated

View File

@ -151,14 +151,6 @@ def _prepare_fixed_ips(client_manager, parsed_args):
def _add_updatable_args(parser):
parser.add_argument(
'--fixed-ip',
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
help='Desired IP and/or subnet (name or ID) for this port: '
'subnet=<subnet>,ip-address=<ip-address> '
'(this option can be repeated)')
# NOTE(dtroyer): --device-id is deprecated in Mar 2016. Do not
# remove before 3.x release or Mar 2017.
device_group = parser.add_mutually_exclusive_group()
@ -184,12 +176,6 @@ def _add_updatable_args(parser):
help="VNIC type for this port (direct | direct-physical |"
" macvtap | normal | baremetal). If unspecified during"
" port creation, default value will be 'normal'.")
parser.add_argument(
'--binding-profile',
metavar='<binding-profile>',
action=parseractions.KeyValueAction,
help='Custom data to be passed as binding:profile: <key>=<value> '
'(this option can be repeated)')
# NOTE(dtroyer): --host-id is deprecated in Mar 2016. Do not
# remove before 3.x release or Mar 2017.
host_group = parser.add_mutually_exclusive_group()
@ -217,6 +203,20 @@ class CreatePort(command.ShowOne):
required=True,
help='Network this port belongs to (name or ID)')
_add_updatable_args(parser)
parser.add_argument(
'--fixed-ip',
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
help='Desired IP and/or subnet (name or ID) for this port: '
'subnet=<subnet>,ip-address=<ip-address> '
'(this option can be repeated)')
parser.add_argument(
'--binding-profile',
metavar='<binding-profile>',
action=parseractions.KeyValueAction,
help='Custom data to be passed as binding:profile: <key>=<value> '
'(this option can be repeated)')
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
@ -352,7 +352,30 @@ class SetPort(command.Command):
metavar="<port>",
help=("Port to modify (name or ID)")
)
fixed_ip = parser.add_mutually_exclusive_group()
fixed_ip.add_argument(
'--fixed-ip',
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
help='Desired IP and/or subnet (name or ID) for this port: '
'subnet=<subnet>,ip-address=<ip-address> '
'(this option can be repeated)')
fixed_ip.add_argument(
'--no-fixed-ip',
action='store_true',
help='Clear existing information of fixed-ips')
binding_profile = parser.add_mutually_exclusive_group()
binding_profile.add_argument(
'--binding-profile',
metavar='<binding-profile>',
action=parseractions.KeyValueAction,
help='Custom data to be passed as binding:profile: <key>=<value> '
'(this option can be repeated)')
binding_profile.add_argument(
'--no-binding-profile',
action='store_true',
help='Clear existing information of binding:profile')
return parser
def take_action(self, parsed_args):
@ -361,6 +384,11 @@ class SetPort(command.Command):
_prepare_fixed_ips(self.app.client_manager, parsed_args)
attrs = _get_attrs(self.app.client_manager, parsed_args)
if parsed_args.no_fixed_ip:
attrs['fixed_ips'] = []
if parsed_args.no_binding_profile:
attrs['binding:profile'] = {}
if attrs == {}:
msg = "Nothing specified to be set"
raise exceptions.CommandError(msg)

View File

@ -298,10 +298,14 @@ class TestSetPort(TestPort):
def test_set_this(self):
arglist = [
'--disable',
'--no-fixed-ip',
'--no-binding-profile',
self._port.name,
]
verifylist = [
('disable', True),
('no_binding_profile', True),
('no_fixed_ip', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -309,6 +313,8 @@ class TestSetPort(TestPort):
attrs = {
'admin_state_up': False,
'binding:profile': {},
'fixed_ips': [],
}
self.network.update_port.assert_called_once_with(self._port, **attrs)
self.assertIsNone(result)

View File

@ -0,0 +1,5 @@
---
features:
- Fixed-IP information and binding profile information
in ports can now be cleared using ``--no-fixed-ip``
and ``--no-binding-profile`` with ``port set``