summaryrefslogtreecommitdiff
path: root/openstackclient/network/v2
diff options
context:
space:
mode:
authorreedip <reedip.banerjee@nectechnologies.in>2016-04-01 13:40:45 +0900
committerReedip <reedip.banerjee@nectechnologies.in>2016-04-14 00:48:09 +0000
commitc92ac9d9110524ffb4c672a5b1c3cdc08e38e717 (patch)
tree085ec87447dc6711272b95d6d38739f00912cd81 /openstackclient/network/v2
parent2a9ba9db30f8d57aa32f7614ee4b4afee15fba9d (diff)
downloadpython-openstackclient-c92ac9d9110524ffb4c672a5b1c3cdc08e38e717.tar.gz
Append existing information during port set
Existing --fixed-ip and --binding-profile information is currently overwritten when a user executes 'port set', but actually that data should be appended. This patch fixes the issue. Closes-Bug: #1564453 Change-Id: I62500c10ccbbc68167f24e9d4fa49e85345d82c4
Diffstat (limited to 'openstackclient/network/v2')
-rw-r--r--openstackclient/network/v2/port.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index a9e80428..9a73a62c 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -30,6 +30,7 @@ LOG = logging.getLogger(__name__)
def _format_admin_state(state):
return 'UP' if state else 'DOWN'
+
_formatters = {
'admin_state_up': _format_admin_state,
'allowed_address_pairs': utils.format_list_of_dicts,
@@ -383,17 +384,24 @@ 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:
+ obj = client.find_port(parsed_args.port, ignore_missing=False)
+ if 'binding:profile' in attrs:
+ attrs['binding:profile'].update(obj.binding_profile)
+ elif parsed_args.no_binding_profile:
attrs['binding:profile'] = {}
+ if 'fixed_ips' in attrs:
+ # When user unsets the fixed_ips, obj.fixed_ips = [{}].
+ # Adding the obj.fixed_ips list to attrs['fixed_ips']
+ # would therefore add an empty dictionary, while we need
+ # to append the attrs['fixed_ips'] iff there is some info
+ # in the obj.fixed_ips. Therefore I have opted for this `for` loop
+ attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip]
+ elif parsed_args.no_fixed_ip:
+ attrs['fixed_ips'] = []
if attrs == {}:
msg = "Nothing specified to be set"
raise exceptions.CommandError(msg)
-
- obj = client.find_port(parsed_args.port, ignore_missing=False)
client.update_port(obj, **attrs)