diff options
author | Akihiro Motoki <motoki@da.jp.nec.com> | 2015-09-24 06:45:19 +0900 |
---|---|---|
committer | Akihiro Motoki <motoki@da.jp.nec.com> | 2015-09-30 14:02:16 +0900 |
commit | 647b0847b23130ab29fcf8f2661b26969204cf6c (patch) | |
tree | e5e749c9dfd82af082e9d5ed84239dba774ed3be /neutronclient/neutron/v2_0/securitygroup.py | |
parent | 3e115991c1cf9ec7cf4252440fa8d6015a5f53ce (diff) | |
download | python-neutronclient-647b0847b23130ab29fcf8f2661b26969204cf6c.tar.gz |
neutron v2 command module cleanup #1
Purge "body[resource].update({key: value})" pattern
and use "body[key] = value" pattern.
The purged pattern is a bad convention in neutronclient and
I commented not to use it many times but I got tired of it.
Change-Id: I2fe0be30d648f59fa45c5951ccc5060c35527aff
Diffstat (limited to 'neutronclient/neutron/v2_0/securitygroup.py')
-rw-r--r-- | neutronclient/neutron/v2_0/securitygroup.py | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/neutronclient/neutron/v2_0/securitygroup.py b/neutronclient/neutron/v2_0/securitygroup.py index 31c589c..9e8d0da 100644 --- a/neutronclient/neutron/v2_0/securitygroup.py +++ b/neutronclient/neutron/v2_0/securitygroup.py @@ -123,14 +123,12 @@ class CreateSecurityGroup(neutronV20.CreateCommand): help=_('Description of security group.')) def args2body(self, parsed_args): - body = {'security_group': { - 'name': parsed_args.name}} + body = {'name': parsed_args.name} if parsed_args.description: - body['security_group'].update( - {'description': parsed_args.description}) + body['description'] = parsed_args.description if parsed_args.tenant_id: - body['security_group'].update({'tenant_id': parsed_args.tenant_id}) - return body + body['tenant_id'] = parsed_args.tenant_id + return {'security_group': body} class DeleteSecurityGroup(neutronV20.DeleteCommand): @@ -154,14 +152,12 @@ class UpdateSecurityGroup(neutronV20.UpdateCommand): help=_('Description of security group.')) def args2body(self, parsed_args): - body = {'security_group': {}} + body = {} if parsed_args.name: - body['security_group'].update( - {'name': parsed_args.name}) + body['name'] = parsed_args.name if parsed_args.description: - body['security_group'].update( - {'description': parsed_args.description}) - return body + body['description'] = parsed_args.description + return {'security_group': body} class ListSecurityGroupRule(neutronV20.ListCommand): @@ -344,32 +340,25 @@ class CreateSecurityGroupRule(neutronV20.CreateCommand): def args2body(self, parsed_args): _security_group_id = neutronV20.find_resourceid_by_name_or_id( self.get_client(), 'security_group', parsed_args.security_group_id) - body = {'security_group_rule': { - 'security_group_id': _security_group_id, - 'direction': parsed_args.direction, - 'ethertype': parsed_args.ethertype}} + body = {'security_group_id': _security_group_id, + 'direction': parsed_args.direction, + 'ethertype': parsed_args.ethertype} if parsed_args.protocol: - body['security_group_rule'].update( - {'protocol': parsed_args.protocol}) + body['protocol'] = parsed_args.protocol if parsed_args.port_range_min: - body['security_group_rule'].update( - {'port_range_min': parsed_args.port_range_min}) + body['port_range_min'] = parsed_args.port_range_min if parsed_args.port_range_max: - body['security_group_rule'].update( - {'port_range_max': parsed_args.port_range_max}) + body['port_range_max'] = parsed_args.port_range_max if parsed_args.remote_ip_prefix: - body['security_group_rule'].update( - {'remote_ip_prefix': parsed_args.remote_ip_prefix}) + body['remote_ip_prefix'] = parsed_args.remote_ip_prefix if parsed_args.remote_group_id: _remote_group_id = neutronV20.find_resourceid_by_name_or_id( self.get_client(), 'security_group', parsed_args.remote_group_id) - body['security_group_rule'].update( - {'remote_group_id': _remote_group_id}) + body['remote_group_id'] = _remote_group_id if parsed_args.tenant_id: - body['security_group_rule'].update( - {'tenant_id': parsed_args.tenant_id}) - return body + body['tenant_id'] = parsed_args.tenant_id + return {'security_group_rule': body} class DeleteSecurityGroupRule(neutronV20.DeleteCommand): |