Added new model policies for images and controllerslices
Sapan Bhatia [Fri, 23 Jan 2015 16:11:51 +0000 (16:11 +0000)]
planetstack/model_policies/__init__.py
planetstack/model_policies/model_policy_ControllerSlice.py [new file with mode: 0644]
planetstack/model_policies/model_policy_Image.py [new file with mode: 0644]

index f1c8071..cfcbe8f 100644 (file)
@@ -4,3 +4,6 @@ from .model_policy_Network import *
 from .model_policy_Site import *
 from .model_policy_SitePrivilege import *
 from .model_policy_SlicePrivilege import *
+from .model_policy_ControllerSlice import *
+from .model_policy_Controller import *
+from .model_policy_Image import *
diff --git a/planetstack/model_policies/model_policy_ControllerSlice.py b/planetstack/model_policies/model_policy_ControllerSlice.py
new file mode 100644 (file)
index 0000000..a7f6c9a
--- /dev/null
@@ -0,0 +1,16 @@
+def handle(controller_slice):
+    from core.models import ControllerSlice, Slice
+   
+    try:
+        my_status_code = int(controller_slice.backend_status[0])
+        try:
+            his_status_code = int(controller_slice.slice.backend_status[0])
+        except:
+            his_status_code = 0
+        print "My: %d His: %d"%(my_status_code, his_status_code)
+        if (my_status_code not in [0,his_status_code]):
+            controller_slice.slice.backend_status = controller_slice.backend_status
+    except Exception,e:
+        print str(e)   
+        pass
diff --git a/planetstack/model_policies/model_policy_Image.py b/planetstack/model_policies/model_policy_Image.py
new file mode 100644 (file)
index 0000000..72f76fa
--- /dev/null
@@ -0,0 +1,13 @@
+def handle(image):
+    from core.models import Controller, ControllerImages, Image
+    from collections import defaultdict
+
+    controller_images = ControllerImages.objects.filter(image=image)
+    existing_controllers = [cs.controller for cs in controller_images] 
+    
+    all_controllers = Controller.objects.all() 
+    for controller in all_controllers:
+        if controller not in existing_controllers:
+            sd = ControllerImages(image=image, controller=controller)
+            sd.save()
+