Avoid overwriting parsed_args

I just notice this in the context of this review [1].  It seemed like an odd
pattern to me but I wasn't sure if it should be folded in to that patch because
of the reach of the change.  So, I thought I'd post it as a clean-up.

[1] https://review.openstack.org/#/c/194078/13/neutronclient/neutron/v2_0/subnet.py

Change-Id: Iaf53f595e6d50fc18a33258439b6ae5e476dfca9
This commit is contained in:
Carl Baldwin
2015-07-06 20:05:38 +00:00
committed by Akihiro Motoki
parent 043656c8f8
commit 31f8f23fb5

View File

@@ -102,7 +102,7 @@ def add_updatable_arguments(parser):
help=argparse.SUPPRESS)
def updatable_args2body(parsed_args, body, for_create=True):
def updatable_args2body(parsed_args, body, for_create=True, ip_version=None):
if parsed_args.disable_dhcp and parsed_args.enable_dhcp:
raise exceptions.CommandError(_(
"You cannot enable and disable DHCP at the same time."))
@@ -124,12 +124,12 @@ def updatable_args2body(parsed_args, body, for_create=True):
if parsed_args.dns_nameservers:
body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers
if for_create and parsed_args.ipv6_ra_mode:
if parsed_args.ip_version == 4:
if ip_version == 4:
raise exceptions.CommandError(_("--ipv6-ra-mode is invalid "
"when --ip-version is 4"))
body['subnet']['ipv6_ra_mode'] = parsed_args.ipv6_ra_mode
if for_create and parsed_args.ipv6_address_mode:
if parsed_args.ip_version == 4:
if ip_version == 4:
raise exceptions.CommandError(_("--ipv6-address-mode is "
"invalid when --ip-version "
"is 4"))
@@ -203,6 +203,7 @@ class CreateSubnet(neutronV20.CreateCommand):
if parsed_args.prefixlen:
body['subnet'].update({'prefixlen': parsed_args.prefixlen})
ip_version = parsed_args.ip_version
if parsed_args.subnetpool:
if parsed_args.subnetpool == 'None':
_subnetpool_id = None
@@ -212,27 +213,27 @@ class CreateSubnet(neutronV20.CreateCommand):
_subnetpool_id = _subnetpool['id']
# Now that we have the pool_id - let's just have a check on the
# ip version used in the pool
parsed_args.ip_version = _subnetpool['ip_version']
ip_version = _subnetpool['ip_version']
body['subnet'].update({'subnetpool_id': _subnetpool_id})
# IP version needs to be set as IP version can be
# determined by subnetpool.
body['subnet']['ip_version'] = parsed_args.ip_version
body['subnet']['ip_version'] = ip_version
if parsed_args.cidr:
# With subnetpool, cidr is now optional for creating subnet.
cidr = parsed_args.cidr
body['subnet'].update({'cidr': cidr})
unusable_cidr = '/32' if parsed_args.ip_version == 4 else '/128'
unusable_cidr = '/32' if ip_version == 4 else '/128'
if cidr.endswith(unusable_cidr):
self.log.warning(_("An IPv%(ip)d subnet with a %(cidr)s CIDR "
"will have only one usable IP address so "
"the device attached to it will not have "
"any IP connectivity.")
% {"ip": parsed_args.ip_version,
% {"ip": ip_version,
"cidr": unusable_cidr})
updatable_args2body(parsed_args, body)
updatable_args2body(parsed_args, body, ip_version=ip_version)
if parsed_args.tenant_id:
body['subnet'].update({'tenant_id': parsed_args.tenant_id})