Changed pattern on how objects lookup themselves by name and project.
[snaps.git] / snaps / config / router.py
index 72164f2..f5bbbf0 100644 (file)
@@ -70,23 +70,23 @@ class RouterConfig(object):
         TODO - expand automated testing to exercise all parameters
         :param neutron: The neutron client to retrieve external network
                         information if necessary
-        :param os_creds: The OpenStack credentials
+        :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
         :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)
-            project_id = None
             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 - ' +
@@ -95,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