From 0195d090cffb7244333f8b686740a594ca3df6e7 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 14 Feb 2012 08:16:07 -0500 Subject: [PATCH] initial checkin --- sfa/openstack/euca_shell.py | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sfa/openstack/euca_shell.py diff --git a/sfa/openstack/euca_shell.py b/sfa/openstack/euca_shell.py new file mode 100644 index 00000000..c67d60ec --- /dev/null +++ b/sfa/openstack/euca_shell.py @@ -0,0 +1,53 @@ +import boto +from boto.ec2.regioninfo import RegionInfo +from boto.exception import EC2ResponseError +from sfa.util.sfalogging import logger + + +class EucaShell: + """ + A xmlrpc connection to the euca api. + """ + + def __init__(self, config): + self.config = Config + + def get_euca_connection(self): + + access_key = self.config.SFA_EUCA_ACCESS_KEY + secret_key = self.config.SFA_EUCA_SECRET_KEY + url = self.config.SFA_EUCA_URL + path = "/" + euca_port = self.config.SFA_EUCA_PORT + use_ssl = False + + # Split the url into parts + if url.find('https://') >= 0: + use_ssl = True + url = url.replace('https://', '') + elif url.find('http://') >= 0: + use_ssl = False + url = url.replace('http://', '') + (host, parts) = url.split(':') + if len(parts) > 1: + parts = parts.split('/') + port = int(parts[0]) + parts = parts[1:] + path = '/'.join(parts) + + if not access_key or not secret_key or not url: + logger.error('Please set ALL of the required environment ' \ + 'variables by sourcing the eucarc file.') + return None + return boto.connect_ec2(aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + is_secure=use_ssl, + region=RegionInfo(None, 'eucalyptus', host), + port=port, + path=path) + + def __getattr__(self, name): + def func(*args, **kwds): + conn = self.get_euca_connection() + return getattr(conn, name)(*args, **kwds) + return func -- 2.45.2