3 from boto.ec2.regioninfo import RegionInfo
4 from boto.exception import EC2ResponseError
10 from euca2ools import Euca2ool
15 from sfa.util.sfalogging import logger
16 from sfa.openstack.nova_shell import NovaShell
17 from sfa.util.config import Config
21 A xmlrpc connection to the euca api.
24 def __init__(self, config):
27 def get_euca_connection(self):
29 logger.info('Unable to access EC2 API - boto library not found.')
32 logger.info('euca2ools library not found.')
35 self.euca2ool = Euca2ool()
36 nova = NovaShell(self.config)
37 admin_user = nova.auth_manager.get_user(self.config.SFA_NOVA_USER)
38 access_key = admin_user.access
39 secret_key = admin_user.secret
40 url = self.config.SFA_NOVA_API_URL
42 euca_port = self.config.SFA_NOVA_API_PORT
45 # Split the url into parts
46 if url.find('https://') >= 0:
48 url = url.replace('https://', '')
49 elif url.find('http://') >= 0:
51 url = url.replace('http://', '')
52 parts = url.split(':')
56 parts = parts.split('/')
59 path = '/'.join(parts)
61 return boto.connect_ec2(aws_access_key_id=access_key,
62 aws_secret_access_key=secret_key,
64 region=RegionInfo(None, 'eucalyptus', host),
68 def __getattr__(self, name):
69 def func(*args, **kwds):
70 conn = self.get_euca_connection()
71 return getattr(conn, name)(*args, **kwds)