|
30 | 30 | def _format_admin_state(state): |
31 | 31 | return 'UP' if state else 'DOWN' |
32 | 32 |
|
| 33 | + |
33 | 34 | _formatters = { |
34 | 35 | 'admin_state_up': _format_admin_state, |
35 | 36 | 'allowed_address_pairs': utils.format_list_of_dicts, |
@@ -383,17 +384,24 @@ def take_action(self, parsed_args): |
383 | 384 |
|
384 | 385 | _prepare_fixed_ips(self.app.client_manager, parsed_args) |
385 | 386 | attrs = _get_attrs(self.app.client_manager, parsed_args) |
386 | | - |
387 | | - if parsed_args.no_fixed_ip: |
388 | | - attrs['fixed_ips'] = [] |
389 | | - if parsed_args.no_binding_profile: |
| 387 | + obj = client.find_port(parsed_args.port, ignore_missing=False) |
| 388 | + if 'binding:profile' in attrs: |
| 389 | + attrs['binding:profile'].update(obj.binding_profile) |
| 390 | + elif parsed_args.no_binding_profile: |
390 | 391 | attrs['binding:profile'] = {} |
| 392 | + if 'fixed_ips' in attrs: |
| 393 | + # When user unsets the fixed_ips, obj.fixed_ips = [{}]. |
| 394 | + # Adding the obj.fixed_ips list to attrs['fixed_ips'] |
| 395 | + # would therefore add an empty dictionary, while we need |
| 396 | + # to append the attrs['fixed_ips'] iff there is some info |
| 397 | + # in the obj.fixed_ips. Therefore I have opted for this `for` loop |
| 398 | + attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip] |
| 399 | + elif parsed_args.no_fixed_ip: |
| 400 | + attrs['fixed_ips'] = [] |
391 | 401 |
|
392 | 402 | if attrs == {}: |
393 | 403 | msg = "Nothing specified to be set" |
394 | 404 | raise exceptions.CommandError(msg) |
395 | | - |
396 | | - obj = client.find_port(parsed_args.port, ignore_missing=False) |
397 | 405 | client.update_port(obj, **attrs) |
398 | 406 |
|
399 | 407 |
|
|
0 commit comments