summaryrefslogtreecommitdiffstats
path: root/snaps/config/security_group.py
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/config/security_group.py')
-rw-r--r--snaps/config/security_group.py55
1 files changed, 33 insertions, 22 deletions
diff --git a/snaps/config/security_group.py b/snaps/config/security_group.py
index 32a1e95..9e485c3 100644
--- a/snaps/config/security_group.py
+++ b/snaps/config/security_group.py
@@ -54,7 +54,7 @@ class SecurityGroupConfig(object):
raise SecurityGroupConfigError('The attribute name is required')
for rule_setting in self.rule_settings:
- if rule_setting.sec_grp_name is not self.name:
+ if rule_setting.sec_grp_name != self.name:
raise SecurityGroupConfigError(
'Rule settings must correspond with the name of this '
'security group')
@@ -204,13 +204,14 @@ class SecurityGroupRuleConfig(object):
raise SecurityGroupRuleConfigError(
'direction and sec_grp_name are required')
- def dict_for_neutron(self, neutron):
+ def dict_for_neutron(self, neutron, keystone, project_name):
"""
Returns a dictionary object representing this object.
This is meant to be converted into JSON designed for use by the Neutron
API
-
:param neutron: the neutron client for performing lookups
+ :param keystone: the keystone client for performing lookups
+ :param project_name: the name of the project associated with the group
:return: the dictionary object
"""
out = dict()
@@ -229,7 +230,8 @@ class SecurityGroupRuleConfig(object):
out['protocol'] = self.protocol.value
if self.sec_grp_name:
sec_grp = neutron_utils.get_security_group(
- neutron, sec_grp_name=self.sec_grp_name)
+ neutron, keystone, sec_grp_name=self.sec_grp_name,
+ project_name=project_name)
if sec_grp:
out['security_group_id'] = sec_grp.id
else:
@@ -312,12 +314,15 @@ def map_direction(direction):
:return: the Direction enum object
:raise: Exception if value is invalid
"""
- if not direction:
+ if not direction or 'None' == str(direction):
return None
- if isinstance(direction, Direction):
- return direction
- elif (isinstance(direction, str) or isinstance(direction, unicode)
- or isinstance(direction, unicode)):
+ if isinstance(direction, enum.Enum):
+ if direction.__class__.__name__ == 'Direction':
+ return direction
+ else:
+ raise SecurityGroupRuleConfigError(
+ 'Invalid class - ' + direction.__class__.__name__)
+ elif isinstance(direction, str):
dir_str = str(direction)
if dir_str == 'egress':
return Direction.egress
@@ -327,7 +332,7 @@ def map_direction(direction):
raise SecurityGroupRuleConfigError(
'Invalid Direction - ' + dir_str)
else:
- return map_direction(direction.value)
+ return map_direction(str(direction))
def map_protocol(protocol):
@@ -340,19 +345,22 @@ def map_protocol(protocol):
"""
if not protocol:
return None
- elif isinstance(protocol, Protocol):
- return protocol
- elif (isinstance(protocol, str) or isinstance(protocol, unicode)
- or isinstance(protocol, int)):
+ elif isinstance(protocol, enum.Enum):
+ if protocol.__class__.__name__ == 'Protocol':
+ return protocol
+ else:
+ raise SecurityGroupRuleConfigError(
+ 'Invalid class - ' + protocol.__class__.__name__)
+ elif isinstance(protocol, str) or isinstance(protocol, int):
for proto_enum in Protocol:
if proto_enum.name == protocol or proto_enum.value == protocol:
if proto_enum == Protocol.any:
return Protocol.null
return proto_enum
raise SecurityGroupRuleConfigError(
- 'Invalid Protocol - ' + protocol)
+ 'Invalid Protocol - ' + str(protocol))
else:
- return map_protocol(protocol.value)
+ return map_protocol(str(protocol))
def map_ethertype(ethertype):
@@ -363,12 +371,15 @@ def map_ethertype(ethertype):
:return: the Ethertype enum object
:raise: Exception if value is invalid
"""
- if not ethertype:
+ if not ethertype or 'None' == str(ethertype):
return None
- elif isinstance(ethertype, Ethertype):
- return ethertype
- elif (isinstance(ethertype, str) or isinstance(ethertype, unicode)
- or isinstance(ethertype, int)):
+ elif isinstance(ethertype, enum.Enum):
+ if ethertype.__class__.__name__ == 'Ethertype':
+ return ethertype
+ else:
+ raise SecurityGroupRuleConfigError(
+ 'Invalid class - ' + ethertype.__class__.__name__)
+ elif isinstance(ethertype, str) or isinstance(ethertype, int):
eth_str = str(ethertype)
if eth_str == 'IPv6' or eth_str == '6':
return Ethertype.IPv6
@@ -378,7 +389,7 @@ def map_ethertype(ethertype):
raise SecurityGroupRuleConfigError(
'Invalid Ethertype - ' + eth_str)
else:
- return map_ethertype(ethertype.value)
+ return map_ethertype(str(ethertype))
class SecurityGroupRuleConfigError(Exception):