diff options
Diffstat (limited to 'snaps/config')
-rw-r--r-- | snaps/config/network.py | 20 | ||||
-rw-r--r-- | snaps/config/router.py | 13 | ||||
-rw-r--r-- | snaps/config/security_group.py | 12 |
3 files changed, 20 insertions, 25 deletions
diff --git a/snaps/config/network.py b/snaps/config/network.py index 85e2bb0..a2d008a 100644 --- a/snaps/config/network.py +++ b/snaps/config/network.py @@ -435,16 +435,10 @@ class PortConfig(object): out = dict() - project_id = None - if self.project_name: - keystone = keystone_utils.keystone_client(os_creds) - project = keystone_utils.get_project( - keystone=keystone, project_name=self.project_name) - if project: - project_id = project.id - + keystone = keystone_utils.keystone_client(os_creds) network = neutron_utils.get_network( - neutron, network_name=self.network_name, project_id=project_id) + neutron, keystone, network_name=self.network_name, + project_name=self.project_name) if not network: raise PortConfigError( 'Cannot locate network with name - ' + self.network_name) @@ -456,6 +450,11 @@ class PortConfig(object): if self.name: out['name'] = self.name if self.project_name: + project = keystone_utils.get_project( + keystone=keystone, project_name=self.project_name) + project_id = None + if project: + project_id = project.id if project_id: out['tenant_id'] = project_id else: @@ -473,7 +472,8 @@ class PortConfig(object): sec_grp_ids = list() for sec_grp_name in self.security_groups: sec_grp = neutron_utils.get_security_group( - neutron, sec_grp_name=sec_grp_name, project_id=project_id) + neutron, sec_grp_name=sec_grp_name, + project_name=self.project_name) if sec_grp: sec_grp_ids.append(sec_grp.id) out['security_groups'] = sec_grp_ids diff --git a/snaps/config/router.py b/snaps/config/router.py index ae84038..f5bbbf0 100644 --- a/snaps/config/router.py +++ b/snaps/config/router.py @@ -61,7 +61,7 @@ class RouterConfig(object): if not self.name: raise RouterConfigError('Name is required') - def dict_for_neutron(self, neutron, os_creds, project_id): + def dict_for_neutron(self, neutron, os_creds): """ Returns a dictionary object representing this object. This is meant to be converted into JSON designed for use by the Neutron @@ -73,23 +73,20 @@ class RouterConfig(object): :param os_creds: The OpenStack credentials for retrieving the keystone client for looking up the project ID when the self.project_name is not None - :param project_id: the associated project ID to use when - self.project_name is None :return: the dictionary object """ out = dict() ext_gw = dict() + keystone = keystone_utils.keystone_client(os_creds) + if self.name: out['name'] = self.name if self.project_name: - keystone = keystone_utils.keystone_client(os_creds) project = keystone_utils.get_project( keystone=keystone, project_name=self.project_name) if project: - project_id = project.id - if project_id: - out['tenant_id'] = project_id + out['tenant_id'] = project.id else: raise RouterConfigError( 'Could not find project ID for project named - ' + @@ -98,7 +95,7 @@ class RouterConfig(object): out['admin_state_up'] = self.admin_state_up if self.external_gateway: ext_net = neutron_utils.get_network( - neutron, network_name=self.external_gateway) + neutron, keystone, network_name=self.external_gateway) if ext_net: ext_gw['network_id'] = ext_net.id out['external_gateway_info'] = ext_gw diff --git a/snaps/config/security_group.py b/snaps/config/security_group.py index 65aabe1..4be7d31 100644 --- a/snaps/config/security_group.py +++ b/snaps/config/security_group.py @@ -59,7 +59,7 @@ class SecurityGroupConfig(object): 'Rule settings must correspond with the name of this ' 'security group') - def dict_for_neutron(self, keystone, project_id): + def dict_for_neutron(self, keystone): """ Returns a dictionary object representing this object. This is meant to be converted into JSON designed for use by the Neutron @@ -67,7 +67,6 @@ class SecurityGroupConfig(object): TODO - expand automated testing to exercise all parameters :param keystone: the Keystone client - :param project_id: the default project ID :return: the dictionary object """ out = dict() @@ -88,8 +87,6 @@ class SecurityGroupConfig(object): raise SecurityGroupConfigError( 'Could not find project ID for project named - ' + self.project_name) - else: - out['tenant_id'] = project_id return {'security_group': out} @@ -207,13 +204,13 @@ class SecurityGroupRuleConfig(object): raise SecurityGroupRuleConfigError( 'direction and sec_grp_name are required') - def dict_for_neutron(self, neutron, project_id): + 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 project_id: the ID of the project associated with the group + :param project_name: the name of the project associated with the group :return: the dictionary object """ out = dict() @@ -232,7 +229,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, project_id=project_id) + neutron, keystone, sec_grp_name=self.sec_grp_name, + project_name=project_name) if sec_grp: out['security_group_id'] = sec_grp.id else: |