diff options
Diffstat (limited to 'openstackclient/network/v2')
| -rw-r--r-- | openstackclient/network/v2/network.py | 38 | ||||
| -rw-r--r-- | openstackclient/network/v2/port.py | 20 |
2 files changed, 44 insertions, 14 deletions
diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 20d943ed..afac471a 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -76,6 +76,16 @@ def _get_attrs(client_manager, parsed_args): parsed_args.availability_zone_hints is not None: attrs['availability_zone_hints'] = parsed_args.availability_zone_hints + # update_external_network_options + if parsed_args.internal: + attrs['router:external'] = False + if parsed_args.external: + attrs['router:external'] = True + if parsed_args.no_default: + attrs['is_default'] = False + if parsed_args.default: + attrs['is_default'] = True + return attrs @@ -197,14 +207,6 @@ class CreateNetwork(common.NetworkAndComputeShowOne): def take_action_network(self, client, parsed_args): attrs = _get_attrs(self.app.client_manager, parsed_args) - if parsed_args.internal: - attrs['router:external'] = False - if parsed_args.external: - attrs['router:external'] = True - if parsed_args.no_default: - attrs['is_default'] = False - if parsed_args.default: - attrs['is_default'] = True if parsed_args.provider_network_type: attrs['provider:network_type'] = parsed_args.provider_network_type if parsed_args.physical_network: @@ -379,6 +381,26 @@ class SetNetwork(command.Command): action='store_true', help='Do not share the network between projects', ) + external_router_grp = parser.add_mutually_exclusive_group() + external_router_grp.add_argument( + '--external', + action='store_true', + help='Set this network as an external network. ' + 'Requires the "external-net" extension to be enabled.') + external_router_grp.add_argument( + '--internal', + action='store_true', + help='Set this network as an internal network') + default_router_grp = parser.add_mutually_exclusive_group() + default_router_grp.add_argument( + '--default', + action='store_true', + help='Specify if this network should be used as ' + 'the default external network') + default_router_grp.add_argument( + '--no-default', + action='store_true', + help='Do not use the network as the default external network.') return parser def take_action(self, parsed_args): diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 820f2ac2..c54cb257 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) |
