include ip addresses in manifest rspec
[sfa.git] / sfa / openstack / nova_shell.py
1 import sys
2 import xmlrpclib
3 import socket
4 from urlparse import urlparse
5 from sfa.util.sfalogging import logger
6 try:
7     from nova import db
8     from nova import flags
9     from nova import context
10     from nova.auth.manager import AuthManager
11     from nova.compute.manager import ComputeManager
12     from nova.network.manager import NetworkManager
13     from nova.scheduler.manager import SchedulerManager
14     from nova.image.glance import GlanceImageService
15     has_nova = True
16 except:
17     has_nova = False
18
19
20 class InjectContext:
21     """
22     Wraps the module and injects the context when executing methods 
23     """     
24     def __init__(self, proxy, context):
25         self.proxy = proxy
26         self.context = context
27     
28     def __getattr__(self, name):
29         def func(*args, **kwds):
30             result=getattr(self.proxy, name)(self.context, *args, **kwds)
31             return result
32         return func
33
34 class NovaShell:
35     """
36     A simple native shell to a nova backend. 
37     This class can receive all nova calls to the underlying testbed
38     """
39     
40     # dont care about limiting calls yet 
41     direct_calls = []
42     alias_calls = {}
43
44
45     # use the 'capability' auth mechanism for higher performance when the PLC db is local    
46     def __init__ ( self, config ) :
47         self.auth_manager = None
48         self.compute_manager = None
49         self.network_manager = None
50         self.scheduler_manager = None
51         self.db = None
52         self.image_manager = None
53
54         if has_nova:
55             logger.debug('nova access - native')
56             # load the config
57             flags.FLAGS(['foo', '--flagfile=/etc/nova/nova.conf', 'foo', 'foo'])
58             # instantiate managers 
59             self.auth_manager = AuthManager()
60             self.compute_manager = ComputeManager()
61             self.network_manager = NetworkManager()
62             self.scheduler_manager = SchedulerManager()
63             self.db = InjectContext(db, context.get_admin_context())
64             self.image_manager = InjectContext(GlanceImageService(), context.get_admin_context())
65         else:
66             logger.debug('nova access - REST')
67             raise SfaNotImplemented('nova access - Rest')