Renamed UserDeployment back to UserDeployments
Sapan Bhatia [Wed, 19 Nov 2014 20:10:51 +0000 (15:10 -0500)]
12 files changed:
planetstack/core/migrations/0001_initial.py
planetstack/core/models/__init__.py
planetstack/core/models/userdeployments.py
planetstack/ec2_observer/deleters/user_deleter.py
planetstack/ec2_observer/deleters/user_deployment_deleter.py
planetstack/genapi.py
planetstack/model_policies/model_policy_User.py
planetstack/openstack_observer/steps/sync_site_privileges.py
planetstack/openstack_observer/steps/sync_slice_deployments.py
planetstack/openstack_observer/steps/sync_slice_memberships.py
planetstack/openstack_observer/steps/sync_user_deployments.py
planetstack/openstack_observer/steps/sync_users.py

index 3ce8e6e..80d9c9a 100644 (file)
@@ -948,7 +948,7 @@ class Migration(migrations.Migration):
             bases=(models.Model,),
         ),
         migrations.CreateModel(
-            name='UserDeployments',
+            name='UserDeploymentss',
             fields=[
                 ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                 ('created', models.DateTimeField(default=django.utils.timezone.now, auto_now_add=True)),
index b539bb8..2070e16 100644 (file)
@@ -12,7 +12,7 @@ from .serviceclass import ServiceClass
 from .site import DeploymentLinkManager,DeploymentLinkDeletionManager
 from .slice import Slice, SliceDeployments
 from .site import SitePrivilege, SiteDeployments
-from .userdeployments import UserDeployment
+from .userdeployments import UserDeployments
 from .image import Image, ImageDeployments
 from .node import Node
 from .serviceresource import ServiceResource
index d0337ba..d8051bf 100644 (file)
@@ -6,7 +6,7 @@ from django.db.models import F, Q
 from core.models import PlCoreBase,Site,User,Deployment
 from core.models import Deployment,DeploymentLinkManager,DeploymentLinkDeletionManager
 
-class UserDeployment(PlCoreBase):
+class UserDeployments(PlCoreBase):
     objects = DeploymentLinkManager()
     deleted_objects = DeploymentLinkDeletionManager()
 
@@ -19,7 +19,7 @@ class UserDeployment(PlCoreBase):
     @staticmethod
     def select_by_user(user):
         if user.is_admin:
-            qs = UserDeployment.objects.all()
+            qs = UserDeployments.objects.all()
         else:
             users = Users.select_by_user(user)
             qs = Usereployments.objects.filter(user__in=slices)
index 3f93060..3930eb0 100644 (file)
@@ -1,13 +1,13 @@
-from core.models import User, UserDeployment
+from core.models import User, UserDeployments
 from observer.deleter import Deleter
-from observer.deleters.user_deployment_deleter import UserDeploymentDeleter
+from observer.deleters.user_deployment_deleter import UserDeploymentsDeleter
 
 class UserDeleter(Deleter):
     model='User'
 
     def call(self, pk):
         user = User.objects.get(pk=pk)
-        user_deployment_deleter = UserDeploymentDeleter()
-        for user_deployment in UserDeployment.objects.filter(user=user):
+        user_deployment_deleter = UserDeploymentsDeleter()
+        for user_deployment in UserDeployments.objects.filter(user=user):
             user_deployment_deleter(user_deployment.id)
         user.delete()
index 6d3825c..4bc7619 100644 (file)
@@ -1,11 +1,11 @@
-from core.models import User, UserDeployment
+from core.models import User, UserDeployments
 from observer.deleter import Deleter
 
-class UserDeploymentDeleter(Deleter):
-    model='UserDeployment'
+class UserDeploymentsDeleter(Deleter):
+    model='UserDeployments'
 
     def call(self, pk):
-        user_deployment = UserDeployment.objects.get(pk=pk)
+        user_deployment = UserDeployments.objects.get(pk=pk)
         if user_deployment.user.kuser_id:
             driver = self.driver.admin_driver(deployment=user_deployment.deployment.name)
             driver.delete_user(user_deployment.user.kuser_id)
index c14f72b..1503431 100644 (file)
@@ -176,9 +176,9 @@ def get_REST_patterns():
         url(r'plstackapi/slicedeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', SliceDeploymentsDetail.as_view(), name ='slicedeployment-detail'),
 #        url(r'plstackapi/slicedeployments/!new/$', SliceDeploymentsNew.as_view(), name ='slicedeployment-new'),
     
-        url(r'plstackapi/userdeployments/$', UserDeploymentList.as_view(), name='userdeployment-list'),
-        url(r'plstackapi/userdeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', UserDeploymentDetail.as_view(), name ='userdeployment-detail'),
-#        url(r'plstackapi/userdeployments/!new/$', UserDeploymentNew.as_view(), name ='userdeployment-new'),
+        url(r'plstackapi/userdeployments/$', UserDeploymentsList.as_view(), name='userdeployment-list'),
+        url(r'plstackapi/userdeployments/(?P<pk>[a-zA-Z0-9\-]+)/$', UserDeploymentsDetail.as_view(), name ='userdeployment-detail'),
+#        url(r'plstackapi/userdeployments/!new/$', UserDeploymentsNew.as_view(), name ='userdeployment-new'),
     
         url(r'plstackapi/accounts/$', AccountList.as_view(), name='account-list'),
         url(r'plstackapi/accounts/(?P<pk>[a-zA-Z0-9\-]+)/$', AccountDetail.as_view(), name ='account-detail'),
@@ -1026,18 +1026,18 @@ class SliceDeploymentsIdSerializer(serializers.ModelSerializer):
 
 
 
-class UserDeploymentSerializer(serializers.HyperlinkedModelSerializer):
+class UserDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
     id = serializers.Field()
     
     class Meta:
-        model = UserDeployment
+        model = UserDeployments
         fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','kuser_id',)
 
-class UserDeploymentIdSerializer(serializers.ModelSerializer):
+class UserDeploymentsIdSerializer(serializers.ModelSerializer):
     id = serializers.Field()
     
     class Meta:
-        model = UserDeployment
+        model = UserDeployments
         fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','kuser_id',)
 
 
@@ -1306,7 +1306,7 @@ serializerLookUp = {
 
                  SliceDeployments: SliceDeploymentsSerializer,
 
-                 UserDeployment: UserDeploymentSerializer,
+                 UserDeployments: UserDeploymentsSerializer,
 
                  Account: AccountSerializer,
 
@@ -4378,10 +4378,10 @@ class SliceDeploymentsNew(GenericAPIView):
 
 
 
-class UserDeploymentList(generics.ListCreateAPIView):
-    queryset = UserDeployment.objects.select_related().all()
-    serializer_class = UserDeploymentSerializer
-    id_serializer_class = UserDeploymentIdSerializer
+class UserDeploymentsList(generics.ListCreateAPIView):
+    queryset = UserDeployments.objects.select_related().all()
+    serializer_class = UserDeploymentsSerializer
+    id_serializer_class = UserDeploymentsIdSerializer
     filter_backends = (filters.DjangoFilterBackend,)
     filter_fields = ('id','created','updated','enacted','backend_status','deleted','user','deployment','kuser_id',)
 
@@ -4393,7 +4393,7 @@ class UserDeploymentList(generics.ListCreateAPIView):
             return self.serializer_class
 
     def get_queryset(self):
-        return UserDeployment.select_by_user(self.request.user)
+        return UserDeployments.select_by_user(self.request.user)
 
     def create(self, request, *args, **kwargs):
         serializer = self.get_serializer(data=request.DATA, files=request.FILES)
@@ -4402,21 +4402,21 @@ class UserDeploymentList(generics.ListCreateAPIView):
         obj = serializer.object
         obj.caller = request.user
         if obj.can_update(request.user):
-            return super(UserDeploymentList, self).create(request, *args, **kwargs)
+            return super(UserDeploymentsList, self).create(request, *args, **kwargs)
         else:
             raise Exception("failed obj.can_update")
 
-        ret = super(UserDeploymentList, self).create(request, *args, **kwargs)
+        ret = super(UserDeploymentsList, self).create(request, *args, **kwargs)
         if (ret.status_code%100 != 200):
             raise Exception(ret.data)
 
         return ret
 
 
-class UserDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
-    queryset = UserDeployment.objects.select_related().all()
-    serializer_class = UserDeploymentSerializer
-    id_serializer_class = UserDeploymentIdSerializer
+class UserDeploymentsDetail(PlanetStackRetrieveUpdateDestroyAPIView):
+    queryset = UserDeployments.objects.select_related().all()
+    serializer_class = UserDeploymentsSerializer
+    id_serializer_class = UserDeploymentsIdSerializer
 
     def get_serializer_class(self):
         no_hyperlinks = self.request.QUERY_PARAMS.get('no_hyperlinks', False)
@@ -4426,7 +4426,7 @@ class UserDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
             return self.serializer_class
     
     def get_queryset(self):
-        return UserDeployment.select_by_user(self.request.user)
+        return UserDeployments.select_by_user(self.request.user)
 
     # update() is handled by PlanetStackRetrieveUpdateDestroyAPIView
 
@@ -4437,9 +4437,9 @@ class UserDeploymentDetail(PlanetStackRetrieveUpdateDestroyAPIView):
     filled with defaults. I solved it another way, so this code may soon be
     abandoned.
 
-class UserDeploymentNew(GenericAPIView):
-    serializer_class = UserDeploymentSerializer
-    id_serializer_class = UserDeploymentIdSerializer
+class UserDeploymentsNew(GenericAPIView):
+    serializer_class = UserDeploymentsSerializer
+    id_serializer_class = UserDeploymentsIdSerializer
 
     def get(self, request, *args, **kwargs):
         return self.makenew(request, *args, **kwargs)
@@ -4452,7 +4452,7 @@ class UserDeploymentNew(GenericAPIView):
             return self.serializer_class
 
     def makenew(self, request, *args, **kwargs):
-        obj = UserDeployment()
+        obj = UserDeployments()
         serializer = self.get_serializer(obj)
         return Response(serializer.data)
 """
index 7af6ff3..6118a7b 100644 (file)
@@ -1,7 +1,7 @@
 from core.models import *
 
 def handle(user):
-       from core.models import Deployment,SiteDeployments,UserDeployment
+       from core.models import Deployment,SiteDeployments,UserDeployments
        from collections import defaultdict
        deployments = Deployment.objects.all()
        site_deployments = SiteDeployments.objects.all()
@@ -10,7 +10,7 @@ def handle(user):
                site_deploy_lookup[site_deployment.site].append(site_deployment.deployment)
 
        user_deploy_lookup = defaultdict(list)
-       for user_deployment in UserDeployment.objects.all():
+       for user_deployment in UserDeployments.objects.all():
                user_deploy_lookup[user_deployment.user].append(user_deployment.deployment)
    
        all_deployments = Deployment.objects.filter() 
@@ -27,6 +27,6 @@ def handle(user):
                if not user in user_deploy_lookup or \
                  expected_deployment not in user_deploy_lookup[user]: 
                        # add new record
-                       ud = UserDeployment(user=user, deployment=expected_deployment)
+                       ud = UserDeployments(user=user, deployment=expected_deployment)
                        ud.save()    
 
index d1a1fed..d07b279 100644 (file)
@@ -3,7 +3,7 @@ import base64
 from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
-from core.models import User, UserDeployment, SitePrivilege, SiteDeployments   
+from core.models import User, UserDeployments, SitePrivilege, SiteDeployments   
 
 class SyncSitePrivileges(OpenStackSyncStep):
     requested_interval=0
@@ -20,7 +20,7 @@ class SyncSitePrivileges(OpenStackSyncStep):
         # sync site privileges at all site deployments
         site_deployments = SiteDeployments.objects.filter(site=site_priv.site)
         for site_deployment in site_deployments:
-            user_deployments = UserDeployment.objects.filter(deployment=site_deployment.deployment)
+            user_deployments = UserDeployments.objects.filter(deployment=site_deployment.deployment)
             if user_deployments:
                 kuser_id  = user_deployments[0].kuser_id
                 driver = self.driver.admin_driver(deployment=site_deployment.deployment.name)
index 9e79164..97196d6 100644 (file)
@@ -7,7 +7,7 @@ from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
 from core.models.site import Deployment, SiteDeployments
 from core.models.slice import Slice, SliceDeployments
-from core.models.userdeployments import UserDeployment
+from core.models.userdeployments import UserDeployments
 from util.logger import Logger, logging
 from observer.ansible import *
 
@@ -48,7 +48,7 @@ class SyncSliceDeployments(OpenStackSyncStep):
             logger.info("deployment %r has no admin_user, skipping" % slice_deployment.deployment)
             return
 
-       deployment_users = UserDeployment.objects.filter(user=slice_deployment.slice.creator,
+       deployment_users = UserDeployments.objects.filter(user=slice_deployment.slice.creator,
                                                              deployment=slice_deployment.deployment)            
        if not deployment_users:
            logger.info("slice createor %s has not accout at deployment %s" % (slice_deployment.slice.creator, slice_deployment.deployment.name))
index 88a182e..b1cd223 100644 (file)
@@ -4,7 +4,7 @@ from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
 from core.models.slice import *
-from core.models.userdeployments import UserDeployment
+from core.models.userdeployments import UserDeployments
 from util.logger import Logger, logging
 
 logger = Logger(level=logging.INFO)
@@ -26,7 +26,7 @@ class SyncSliceMemberships(OpenStackSyncStep):
         for slice_deployment in slice_deployments:
             if not slice_deployment.tenant_id:
                 continue
-            user_deployments = UserDeployment.objects.filter(deployment=slice_deployment.deployment,
+            user_deployments = UserDeployments.objects.filter(deployment=slice_deployment.deployment,
                                                               user=slice_memb.user)
             if user_deployments:
                 kuser_id  = user_deployments[0].kuser_id
index 54f6130..2e8256f 100644 (file)
@@ -7,23 +7,23 @@ from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
 from core.models.site import SiteDeployments, Deployment
 from core.models.user import User
-from core.models.userdeployments import UserDeployment
+from core.models.userdeployments import UserDeployments
 from util.logger import Logger, logging
 
 from observer.ansible import *
 
 logger = Logger(level=logging.INFO)
 
-class SyncUserDeployment(OpenStackSyncStep):
-    provides=[UserDeployment, User]
+class SyncUserDeployments(OpenStackSyncStep):
+    provides=[UserDeployments, User]
     requested_interval=0
 
     def fetch_pending(self, deleted):
 
         if (deleted):
-            return UserDeployment.deleted_objects.all()
+            return UserDeployments.deleted_objects.all()
         else:
-            return UserDeployment.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) 
+            return UserDeployments.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) 
 
     def sync_record(self, user_deployment):
         logger.info("sync'ing user %s at deployment %s" % (user_deployment.user, user_deployment.deployment.name))
index 242b8be..a22c213 100644 (file)
@@ -5,20 +5,20 @@ from django.db.models import F, Q
 from planetstack.config import Config
 from observer.openstacksyncstep import OpenStackSyncStep
 from core.models.user import User
-from core.models.userdeployments import  UserDeployment
-from observer.steps.sync_user_deployments import SyncUserDeployment
+from core.models.userdeployments import  UserDeployments
+from observer.steps.sync_user_deployments import SyncUserDeployments
 
 class SyncUsers(OpenStackSyncStep):
     provides=[User]
     requested_interval=0
 
     def sync_record(self, user):
-        for user_deployment in UserDeployment.objects.filter(user=user):
+        for user_deployment in UserDeployments.objects.filter(user=user):
             # bump the 'updated' field so user account are updated across 
             # deployments.
             user_deployment.save()
 
     def delete_record(self, user):
-        user_deployment_deleter = SyncUserDeployment().delete_record
-        for user_deployment in UserDeployment.objects.filter(user=user):
+        user_deployment_deleter = SyncUserDeployments().delete_record
+        for user_deployment in UserDeployments.objects.filter(user=user):
             user_deployment_deleter(user_deployment)