Abstracted out deleters
diff --git a/planetstack/core/models/plcorebase.py b/planetstack/core/models/plcorebase.py
index 00dc2d0..d20b08b 100644
--- a/planetstack/core/models/plcorebase.py
+++ b/planetstack/core/models/plcorebase.py
@@ -35,6 +35,11 @@
def get_field_diff(self, field_name):
return self.diff.get(field_name, None)
+ def delete(self, *args, **kwds):
+ super(PlCoreBase, self).delete(*args, **kwds)
+
+ EventSender().fire({'delete_flag':True,'model':self.__name__})
+
def save(self, *args, **kwargs):
super(PlCoreBase, self).save(*args, **kwargs)
diff --git a/planetstack/observer/deleter.py b/planetstack/observer/deleter.py
new file mode 100644
index 0000000..9a62ccd
--- /dev/null
+++ b/planetstack/observer/deleter.py
@@ -0,0 +1,13 @@
+import os
+import base64
+from planetstack.config import Config
+
+class Deleter:
+ model=None # Must be overridden
+
+ def call(self,pk):
+ # Fetch object from PlanetStack db and delete it
+ pass
+
+ def __call__(self):
+ return self.call()
diff --git a/planetstack/observer/deleters/__init__.py b/planetstack/observer/deleters/__init__.py
new file mode 100755
index 0000000..28e88cf
--- /dev/null
+++ b/planetstack/observer/deleters/__init__.py
@@ -0,0 +1,16 @@
+import os
+
+deleters = {}
+_path = os.path.join('.',os.path.dirname(__file__))
+
+_files = os.listdir(_path)
+_files = filter(lambda x:x.endswith('deleter.py'),_files)
+_files = map(lambda x:x.rstrip('.py'),_files)
+
+for f in _files:
+ m = __import__(f)
+ deleter = getattr(m,f.title().replace('_',''))
+ try:
+ deleters[deleter.model].append(deleter)
+ except KeyError:
+ deleters[deleter.model]=[deleter]
diff --git a/planetstack/observer/deleters/slice_deleter.py b/planetstack/observer/deleters/slice_deleter.py
new file mode 100644
index 0000000..4cb0a72
--- /dev/null
+++ b/planetstack/observer/deleters/slice_deleter.py
@@ -0,0 +1,9 @@
+#from code.models import Slice
+
+class SliceDeleter:
+ model='Slice'
+
+ def call(self, pk):
+ s = Slice.objects.get(pk=pk)
+
+ # Proceed with delete
diff --git a/planetstack/observer/deleters/slice_deleter.pyc b/planetstack/observer/deleters/slice_deleter.pyc
new file mode 100644
index 0000000..9fc8022
--- /dev/null
+++ b/planetstack/observer/deleters/slice_deleter.pyc
Binary files differ
diff --git a/planetstack/observer/event_manager.py b/planetstack/observer/event_manager.py
index f24026a..c4215ac 100644
--- a/planetstack/observer/event_manager.py
+++ b/planetstack/observer/event_manager.py
@@ -4,10 +4,12 @@
from core.models import *
#from openstack.manager import OpenStackManager
from planetstack.config import Config
+from observer.deleters import deleters
import os
import base64
from fofum import Fofum
+import json
# decorator that marks dispatachable event methods
def event(func):
@@ -33,57 +35,6 @@
return getattr(self, event)(*args, **kwds)
- @event
- def save_site(self, id):
- sites = Site.objects.filter(id=id)
- if sites:
- self.manager.save_site(sites[0])
-
- @event
- def delete_site(self, tenant_id):
- self.manager.driver.delete_tenant(tenant_id)
-
- @event
- def save_site_privilege(self, id):
- site_privileges = SitePrivilege.objects.filter(id=id)
- if site_privileges:
- site_priv = self.manager.save_site_privilege(site_privileges[0])
-
- @event
- def delete_site_privilege(self, kuser_id, tenant_id, role_type):
- self.manager.driver.delete_user_role(kuser_id, tenant_id, role_type)
-
- @event
- def save_slice(self, id):
- slices = Slice.objects.filter(id=id)
- if slices:
- self.manager.save_slice(slices[0])
-
- @event
- def delete_slice(self, tenant_id, network_id, router_id, subnet_id):
- self.manager._delete_slice(tenant_id, network_id, router_id, subnet_id)
-
- @event
- def save_user(self, id):
- users = User.objects.filter(id=id)
- if users:
- self.manager.save_user(users[0])
-
- @event
- def delete_user(self, kuser_id):
- self.manager.driver.delete_user(kuser_id)
-
- @event
- def save_sliver(self, id):
- slivers = Sliver.objects.filter(id=id)
- if slivers:
- self.manager.save_sliver(slivers[0])
-
- @event
- def delete_sliver(self, instance_id):
- self.manager.destroy_instance(instance_id)
-
-
class EventSender:
def __init__(self,user=None,clientid=None):
try:
@@ -96,8 +47,8 @@
self.fofum = Fofum(user=user)
self.fofum.make(clid)
- def fire(self):
- self.fofum.fire()
+ def fire(self,**args):
+ self.fofum.fire(json.dumps(args))
class EventListener:
def __init__(self,wake_up=None):
@@ -107,19 +58,14 @@
def handle_event(self, payload):
payload_dict = json.loads(payload)
- # The code below will come back when we optimize the observer syncs
- # into 'small' and 'big' syncs.
-
- #event = payload_dict['event']
- #ctx = payload_dict['ctx']
- #self.handler.dispatch(event,**ctx)
-
try:
deletion = payload_dict['deletion_flag']
if (deletion):
- cmd = payload_dict['command']
- ctx = payload_dict['ctx']
- self.handler.dispatch(cmd,**ctx)
+ model = payload_dict['model']
+ pk = payload_dict['pk']
+
+ for deleter in deleters[model]:
+ deleter(pk)
except:
deletion = False
diff --git a/planetstack/plstackapi_config b/planetstack/plstackapi_config
index 1d7b761..deaf2e3 100644
--- a/planetstack/plstackapi_config
+++ b/planetstack/plstackapi_config
@@ -27,3 +27,6 @@
default_image=None
default_flavor=m1.small
default_security_group=default
+
+[observer]
+pl_dependency_graph='/opt/planetstack/model-deps'