fix openstack integration
Tony Mack [Sat, 11 May 2013 00:20:03 +0000 (20:20 -0400)]
planetstack/core/admin.py
planetstack/core/models/__init__.py
planetstack/core/models/key.py
planetstack/core/models/role.py
planetstack/core/models/site.py
planetstack/core/models/slice.py
planetstack/core/models/sliver.py
planetstack/core/models/subnet.py [deleted file]
planetstack/core/models/user.py
planetstack/openstack/driver.py
planetstack/openstack/manager.py

index 58e9689..20c3a81 100644 (file)
@@ -423,14 +423,14 @@ class UserAdmin(UserAdmin, OSModelAdmin):
     list_filter = ('site',)
     inlines = [SitePrivilegeInline, SliceMembershipInline]
     fieldsets = (
-        (None, {'fields': ('email', 'password', 'site')}),
+        (None, {'fields': ('email', 'password', 'site', 'is_admin')}),
         ('Personal info', {'fields': ('firstname','lastname','phone', 'key')}),
         #('Important dates', {'fields': ('last_login',)}),
     )
     add_fieldsets = (
         (None, {
             'classes': ('wide',),
-            'fields': ('email', 'firstname', 'lastname', 'phone', 'site', 'key','password1', 'password2')}
+            'fields': ('email', 'firstname', 'lastname', 'phone', 'site', 'key','password1', 'password2', 'is_admin')}
         ),
     )
     search_fields = ('email',)
index 0fe5e47..d922802 100644 (file)
@@ -10,7 +10,5 @@ from .node import Node
 from .slice import Slice
 from .slice import SliceMembership
 from .sliver import Sliver
-from .subnet import Subnet
 from .serviceclass import ServiceClass
 from .serviceresource import ServiceResource
-
index 7a8b322..6fd7c34 100644 (file)
@@ -1,8 +1,6 @@
 import os
 from django.db import models
 from core.models import PlCoreBase
-from openstack.manager import OpenStackManager
-
 
 # Create your models here.
 
@@ -17,13 +15,15 @@ class Key(PlCoreBase):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_key(self)
+        self.os_manager.save_key(self)
         super(Key, self).save(*args, **kwds)
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_key(self)
+        self.os_manager.delete_key(self)
         super(Key, self).delete(*args, **kwds) 
     
index d3c577d..f6c2f2c 100644 (file)
@@ -2,7 +2,6 @@ import os
 import datetime
 from django.db import models
 from core.models import PlCoreBase
-from openstack.manager import OpenStackManager
 
 class Role(PlCoreBase):
 
@@ -15,13 +14,15 @@ class Role(PlCoreBase):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_role(self)
+        self.os_manager.save_role(self)
         super(Role, self).save(*args, **kwds)
     
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_role(self)   
+        self.os_manager.delete_role(self)   
         super(Role, self).delete(*args, **kwds)
             
index 11e6a28..8626a0d 100644 (file)
@@ -2,7 +2,6 @@ import os
 from django.db import models
 from core.models import PlCoreBase
 from core.models import DeploymentNetwork
-from openstack.manager import OpenStackManager
 
 class Site(PlCoreBase):
 
@@ -22,15 +21,17 @@ class Site(PlCoreBase):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_site(self)
+        self.os_manager.save_site(self)
         super(Site, self).save(*args, **kwds)               
 
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_site(self)
+        self.os_manager.delete_site(self)
         super(Site, self).delete(*args, **kwds)         
         
 
@@ -44,12 +45,14 @@ class SitePrivilege(PlCoreBase):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
             self.os_manager.driver.add_user_role(self.user.kuser_id, self.site.tenant_id, self.role.role_type)
         super(SitePrivilege, self).save(*args, **kwds)
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
             self.os_manager.driver.delete_user_role(self.user.kuser_id, self.site.tenant_id, self.role.role_type)
         super(SitePrivilege, self).delete(*args, **kwds)
index 2fd9fd3..edbe824 100644 (file)
@@ -5,7 +5,6 @@ from core.models import Site
 from core.models import User
 from core.models import Role
 from core.models import DeploymentNetwork
-from openstack.manager import OpenStackManager
 
 # Create your models here.
 
@@ -29,14 +28,16 @@ class Slice(PlCoreBase):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_slice(self)
+        self.os_manager.save_slice(self)
         super(Slice, self).save(*args, **kwds)
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_slice(self)
+        self.os_manager.delete_slice(self)
         super(Slice, self).delete(*args, **kwds)    
 
 class SliceMembership(PlCoreBase):
@@ -48,6 +49,7 @@ class SliceMembership(PlCoreBase):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
             if self.os_manager.driver:
                 self.os_manager.driver.add_user_role(self.user.kuser_id, self.slice.tenant_id, self.role.role_type)
@@ -55,6 +57,7 @@ class SliceMembership(PlCoreBase):
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
             if self.os_manager.driver:
                 self.os_manager.driver.delete_user_role(self.user.kuser_id, self.slice.tenant_id, self.role.role_type)
index 8ebcbd4..ff074a6 100644 (file)
@@ -8,7 +8,6 @@ from core.models import Slice
 from core.models import Node
 from core.models import Site
 from core.models import DeploymentNetwork
-from openstack.manager import OpenStackManager
 
 # Create your models here.
 class Sliver(PlCoreBase):
@@ -30,12 +29,14 @@ class Sliver(PlCoreBase):
         if not self.name:
             self.name = self.slice.name
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_sliver(self)
+        self.os_manager.save_sliver(self)
         super(Sliver, self).save(*args, **kwds)
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_sliver(self)
+        self.os_manager.delete_sliver(self)
         super(Sliver, self).delete(*args, **kwds)
diff --git a/planetstack/core/models/subnet.py b/planetstack/core/models/subnet.py
deleted file mode 100644 (file)
index 37175ec..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-import os
-import commands    
-from django.db import models
-from core.models import PlCoreBase
-from core.models import Slice
-from openstack.manager import OpenStackManager
-
-# Create your models here.
-
-class Subnet(PlCoreBase):
-    subnet_id = models.CharField(max_length=256, unique=True)
-    cidr = models.CharField(max_length=20)
-    ip_version = models.IntegerField()
-    start = models.IPAddressField()
-    end = models.IPAddressField()
-    slice = models.ForeignKey(Slice, related_name='subnet')
-
-    def __unicode__(self):  return u'%s' % (self.slice.name)
-
-    def save(self, *args, **kwds):
-        if not hasattr(self, 'os_manager'):
-            setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_subnet(self)
-        super(Subnet, self).save(*args, **kwds)
-
-    def delete(self, *args, **kwds):
-        if not hasattr(self, 'os_manager'):
-            setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_subnet(self)
-        super(Subnet, self).delete(*args, **kwds)
index 38c0d89..e6c42e7 100644 (file)
@@ -5,7 +5,6 @@ from django.db import models
 from core.models import PlCoreBase
 from core.models import Site
 from core.models import Key
-from openstack.manager import OpenStackManager
 from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
 
 # Create your models here.
@@ -110,8 +109,9 @@ class User(AbstractBaseUser):
 
     def save(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager 
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.save_user(self)
+        self.os_manager.save_user(self)
 
         if not self.id:
             self.set_password(self.password)    
@@ -119,7 +119,8 @@ class User(AbstractBaseUser):
 
     def delete(self, *args, **kwds):
         if not hasattr(self, 'os_manager'):
+            from openstack.manager import OpenStackManager
             setattr(self, 'os_manager', OpenStackManager())
-            self.os_manager.delete_user(self)
+        self.os_manager.delete_user(self)
 
         super(User, self).delete(*args, **kwds)    
index eba424a..f84fbb8 100644 (file)
@@ -2,7 +2,6 @@ import commands
 from planetstack.config import Config
 from openstack.client import OpenStackClient
 
-has_openstack = False
 class OpenStackDriver:
 
     def __init__(self, config = None, client=None): 
@@ -12,10 +11,7 @@ class OpenStackDriver:
             self.config = Config() 
 
         self.admin_client = OpenStackClient()
-        if has_openstack:
-            self.admin_user = self.admin_client.keystone.users.find(name=self.admin_client.keystone.username)
-        else:
-            self.admin_user = None
+        self.admin_user = self.admin_client.keystone.users.find(name=self.admin_client.keystone.username)
 
         if client:
             self.shell = client
index 788699b..857e225 100644 (file)
@@ -1,3 +1,6 @@
+import os
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
+
 from netaddr import IPAddress, IPNetwork
 from planetstack import settings
 from django.core import management
@@ -10,8 +13,7 @@ try:
 except:
     has_openstack = False
 
-#manager_enabled = Config().api_nova_enabled
-manager_enabled = False
+manager_enabled = Config().api_nova_enabled
 
 def require_enabled(callable):
     def wrapper(*args, **kwds):
@@ -277,6 +279,7 @@ class OpenStackManager:
         Node.objects.filter(name__in=old_node_names).delete()
 
     def refresh_images(self):
+        from core.models.image import Image
         # collect local images
         images = Image.objects.all()
         images_dict = {}