remove deployment_auth.py and move deployment auth parameters to deployment model
Tony Mack [Wed, 4 Jun 2014 03:02:00 +0000 (23:02 -0400)]
planetstack/core/models/deployment.py
planetstack/observer/steps/garbage_collector.py
planetstack/openstack/client.py
setup.py

index b97432b..738276a 100644 (file)
@@ -12,6 +12,10 @@ class ManyToManyField_NoSyncdb(models.ManyToManyField):
 
 class Deployment(PlCoreBase):
     name = models.CharField(max_length=200, unique=True, help_text="Name of the Deployment")
+    admin_user = models.CharField(max_length=200, null=True, blank=True, help_text="Username of an admin user at this deployment")
+    admin_password = models.CharField(max_length=200, null=True, blank=True, help_text="Password of theadmin user at this deployment")
+    admin_tenant = models.CharField(max_length=200, null=True, blank=True, help_text="Name of the tenant the admin user belongs to") 
+    auth_url = models.CharField(max_length=200, null=True, blank=True, help_text="Auth url for the deployment")
 #    sites = ManyToManyField_NoSyncdb('Site', through=Site.deployments.through, blank=True)
 
     def __unicode__(self):  return u'%s' % (self.name)
index b9a588b..6feff14 100644 (file)
@@ -6,7 +6,7 @@ from django.db.models import F, Q
 from planetstack.config import Config
 from util.logger import Logger, logging
 from observer.openstacksyncstep import OpenStackSyncStep
-from deployment_auth import deployment_auth
+from core.models.deployment import Deployment
 from core.models import *
 
 logger = Logger(logfile='/var/log/observer.log', level=logging.INFO)
@@ -46,9 +46,9 @@ class GarbageCollector(OpenStackSyncStep):
         # some deployments are at the same url. Keep track of the urls we've visited
         # to make sure we aren't making redundant calls
         completed_urls = []
-        for deployment in deployment_auth:
+        for deployment in Deployment.objects.all():
             # skip deployments that we've already processed
-            if deployment_auth[deployment]['url'] in completed_urls:
+            if deployment.auth_url in completed_urls:
                 continue
             try:
                 driver = self.driver.admin_driver(deployment=deployment)
@@ -68,7 +68,7 @@ class GarbageCollector(OpenStackSyncStep):
             except:
                 logger.log_exc("GarbageCollector: Error at deployment %s" % deployment)
                                 
-            completed_urls.append(deployment_auth[deployment]['url']) 
+            completed_urls.append(deployment.auth_url) 
 
     def gc_tenants(self):
         """
@@ -95,9 +95,9 @@ class GarbageCollector(OpenStackSyncStep):
         # some deployments are at the same url. Keep track of the urls we've visited
         # to make sure we aren't making redundant calls
         completed_urls = []
-        for deployment in deployment_auth:
+        for deployment in Deployment.objects.all():
             # skip deployments that we've already processed
-            if deployment_auth[deployment]['url'] in completed_urls:
+            if deployment.auth_url in completed_urls:
                 continue
 
             driver = self.driver.admin_driver(deployment=deployment)
@@ -111,7 +111,7 @@ class GarbageCollector(OpenStackSyncStep):
                         driver.delete_tenant(tenant.id)
                     except:
                         logger.log_exc("GarbageCollector: delete tenant failed: %s" % tenant)
-            completed_urls.append(deployment_auth[deployment]['url'])
+            completed_urls.append(deployment.auth_url)
 
     def gc_users(self):
         """
@@ -133,9 +133,9 @@ class GarbageCollector(OpenStackSyncStep):
         # some deployments are at the same url. Keep track of the urls we've visited
         # to make sure we aren't making redundant calls
         completed_urls = []
-        for deployment in deployment_auth:
+        for deployment in Deployment.objects.all():
             # skip deployments that we've already processed
-            if deployment_auth[deployment]['url'] in completed_urls:
+            if deployment.auth_url in completed_urls:
                 continue
 
             driver = self.driver.admin_driver(deployment=deployment)
@@ -149,7 +149,7 @@ class GarbageCollector(OpenStackSyncStep):
                         self.driver.delete_user(user.id)
                     except:
                         logger.log_exc("GarbageCollector: delete user failed: %s" % user)
-            completed_urls.append(deployment_auth[deployment]['url'])          
+            completed_urls.append(deployment.auth_url)          
 
     def gc_user_tenant_roles(self):
         """
@@ -172,9 +172,9 @@ class GarbageCollector(OpenStackSyncStep):
         # 2. Never remove a user's role at a slice they've created.
         # Keep track of all roles that must be preserved.     
         users = User.objects.all()
-        for deployment in deployment_auth:
+        for deployment in Deployment.objects.all():
             # skip deployments that we've already processed
-            if deployment_auth[deployment]['url'] in completed_urls:
+            if deployment.auth_url in completed_urls:
                 continue
 
             driver = self.driver.admin_driver(deployment=deployment)
@@ -213,7 +213,7 @@ class GarbageCollector(OpenStackSyncStep):
                             logger.info("GarbageCollector: removing user role %s for %s at %s" % \
                                        (k_user_role, k_user.username, tenant.name))
                             driver.shell.keyston.remove_user_role(k_user, k_user_role, tenant)
-            completed_urls.append(deployment_auth[deployment]['url']) 
+            completed_urls.append(deployment.auth_url) 
  
     def gc_slivers(self):
         """
@@ -231,9 +231,9 @@ class GarbageCollector(OpenStackSyncStep):
         # some deployments are at the same url. Keep track of the urls we've visited
         # to make sure we aren't making redundant calls
         completed_urls = []
-        for deployment in deployment_auth:
+        for deployment in Deployment.objects.all():
             # skip deployments that we've already processed
-            if deployment_auth[deployment]['url'] in completed_urls:
+            if deployment.auth_url in completed_urls:
                 continue
 
             try:
@@ -252,7 +252,7 @@ class GarbageCollector(OpenStackSyncStep):
                                 logger.log_exc("GarbageCollector: destroy sliver failed: %s" % instance)
             except:
                 logger.log_exc("GarbageCollector: Error at deployment %s" % deployment) 
-            completed_urls.append(deployment_auth[deployment]['url'])
+            completed_urls.append(deployment.auth_url)
                
 
     def gc_sliver_ips(self):
@@ -284,7 +284,7 @@ class GarbageCollector(OpenStackSyncStep):
 
         # collect nova nodes:
         compute_nodes_dict = {}
-        for deployment in deployment_auth:
+        for deployment in Deployment.objets.all():
             driver = self.driver.admin_driver(deployment=deployment) 
             compute_nodes = driver.nova.hypervisors.list()
             for compute_node in compute_nodes:
@@ -303,7 +303,7 @@ class GarbageCollector(OpenStackSyncStep):
 
         # collect glance images
         glance_images_dict = {}
-        for deployment in deployment_auth:
+        for deployment in Deployment.objects.all():
             driver = self.driver.admin_driver(deployment=deployment)
             glance_images = driver.shell.glance.get_images()
             for glance_image in glance_images:
index 465425d..162e506 100644 (file)
@@ -15,7 +15,6 @@ except:
     has_openstack = False
 
 from planetstack.config import Config
-from deployment_auth import deployment_auth
 
 def require_enabled(callable):
     def wrapper(*args, **kwds):
@@ -44,21 +43,12 @@ def parse_novarc(filename):
 class Client:
     def __init__(self, username=None, password=None, tenant=None, url=None, token=None, endpoint=None, deployment=None, admin=True, *args, **kwds):
         
-            
-        if not deployment or deployment not in deployment_auth:
-            auth = deployment_auth['default']
-        else:
-            auth = deployment_auth[deployment]
-            
         self.has_openstack = has_openstack
-
-        self.url = auth['url']
+        self.url = deployment.auth_url
         if admin:
-            self.username = auth['user']
-            self.password = auth['password']
-            self.tenant = auth['tenant']
-            self.endpoint = auth['endpoint']
-            self.token = auth['token']  
+            self.username = deployment.admin_user
+            self.password = deployment.admin_password
+            self.tenant = deployment.admin_tenant
         else:
             self.username = None
             self.password = None
@@ -98,9 +88,7 @@ class KeystoneClient(Client):
             self.client = keystone_client.Client(username=self.username,
                                                  password=self.password,
                                                  tenant_name=self.tenant,
-                                                 auth_url=self.url,
-                                                 endpoint=self.endpoint,
-                                                 token=self.token
+                                                 auth_url=self.url
                                                 )
 
     @require_enabled
index 267f282..a250b29 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -19,7 +19,7 @@ setup(name='planetstack',
       description='PlanetStack',
       scripts=['planetstack/planetstack-backend.py'],
       data_files=[
-        ('/etc/planetstack/', ['planetstack/plstackapi_config', 'planetstack/deployment_auth.py']),
+        ('/etc/planetstack/', ['planetstack/plstackapi_config']),
         ('/lib/systemd/system/', ['planetstack/redhat/planetstack-backend.service']),
         ])