diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-02-01 18:45:40 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-02-01 18:45:40 +0000 |
| commit | 28a5bfef8d4315fdbce8ceb0c18eee81565161b7 (patch) | |
| tree | 458e927c81888bba06321205db8d6a82c59f0d21 /nova/api | |
| parent | a48781aa8f4d5c89cf52ad23079be9e723cb4cd1 (diff) | |
| parent | ba21072a43183388e53f47bcdac074cb6246ed83 (diff) | |
Merge "Correct checking existence of security group rule"
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/ec2/cloud.py | 19 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/security_groups.py | 19 |
2 files changed, 16 insertions, 22 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 5b7841ad5..8fa348129 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -594,17 +594,14 @@ class CloudController(object): defined in the given security group. """ for rule in security_group.rules: - if 'group_id' in values: - if rule['group_id'] == values['group_id']: - return rule['id'] - else: - is_duplicate = True - for key in ('cidr', 'from_port', 'to_port', 'protocol'): - if rule[key] != values[key]: - is_duplicate = False - break - if is_duplicate: - return rule['id'] + is_duplicate = True + keys = ('group_id', 'cidr', 'from_port', 'to_port', 'protocol') + for key in keys: + if rule.get(key) != values.get(key): + is_duplicate = False + break + if is_duplicate: + return rule['id'] return False def revoke_security_group_ingress(self, context, group_name=None, diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 45d72bf61..1faa0537a 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -379,17 +379,14 @@ class SecurityGroupRulesController(SecurityGroupController): defined in the given security group. """ for rule in security_group.rules: - if 'group_id' in values: - if rule['group_id'] == values['group_id']: - return True - else: - is_duplicate = True - for key in ('cidr', 'from_port', 'to_port', 'protocol'): - if rule[key] != values[key]: - is_duplicate = False - break - if is_duplicate: - return True + is_duplicate = True + keys = ('group_id', 'cidr', 'from_port', 'to_port', 'protocol') + for key in keys: + if rule.get(key) != values.get(key): + is_duplicate = False + break + if is_duplicate: + return True return False def _rule_args_to_dict(self, context, to_port=None, from_port=None, |
