4 from core.models import *
5 #from openstack.manager import OpenStackManager
6 from planetstack.config import Config
10 from fofum import Fofum
12 # decorator that marks dispatachable event methods
14 setattr(func, 'event', func.__name__)
18 # This code is currently not in use.
20 pass #self.manager = OpenStackManager()
25 for name in dir(EventHandler):
26 attribute = getattr(EventHandler, name)
27 if hasattr(attribute, 'event'):
28 events.append(getattr(attribute, 'event'))
31 def dispatch(self, event, *args, **kwds):
32 if hasattr(self, event):
33 return getattr(self, event)(*args, **kwds)
37 def save_site(self, id):
38 sites = Site.objects.filter(id=id)
40 self.manager.save_site(sites[0])
43 def delete_site(self, tenant_id):
44 self.manager.driver.delete_tenant(tenant_id)
47 def save_site_privilege(self, id):
48 site_privileges = SitePrivilege.objects.filter(id=id)
50 site_priv = self.manager.save_site_privilege(site_privileges[0])
53 def delete_site_privilege(self, kuser_id, tenant_id, role_type):
54 self.manager.driver.delete_user_role(kuser_id, tenant_id, role_type)
57 def save_slice(self, id):
58 slices = Slice.objects.filter(id=id)
60 self.manager.save_slice(slices[0])
63 def delete_slice(self, tenant_id, network_id, router_id, subnet_id):
64 self.manager._delete_slice(tenant_id, network_id, router_id, subnet_id)
67 def save_user(self, id):
68 users = User.objects.filter(id=id)
70 self.manager.save_user(users[0])
73 def delete_user(self, kuser_id):
74 self.manager.driver.delete_user(kuser_id)
77 def save_sliver(self, id):
78 slivers = Sliver.objects.filter(id=id)
80 self.manager.save_sliver(slivers[0])
83 def delete_sliver(self, instance_id):
84 self.manager.destroy_instance(instance_id)
88 def __init__(self,user=None,clientid=None):
90 clid = Config().feefie_client_id
91 user = Config().feefie_client_user
93 clid = 'planetstack_core_team'
96 self.fofum = Fofum(user=user)
103 def __init__(self,wake_up=None):
104 self.handler = EventHandler()
105 self.wake_up = wake_up
107 def handle_event(self, payload):
108 payload_dict = json.loads(payload)
110 # The code below will come back when we optimize the observer syncs
111 # into 'small' and 'big' syncs.
113 #event = payload_dict['event']
114 #ctx = payload_dict['ctx']
115 #self.handler.dispatch(event,**ctx)
122 # This is our unique client id, to be used when firing and receiving events
123 # It needs to be generated once and placed in the config file
126 clid = Config().feefie_client_id
127 user = Config().feefie_client_user
129 clid = 'planetstack_core_team'
134 listener_thread = threading.Thread(target=f.listen_for_event,args=(clid,self.handle_event))
135 listener_thread.start()