Commits

Anonymous committed 464361d Merge
  • Participants
  • Parent commits 4a5b0cb, cfa7cf4

Comments (0)

Files changed (62)

 \.svn$
 lib/*
 bin/*
+build/*
 
 syntax: glob
 
-import config, logging, logging.config, sys
+import config
+import logging
+import logging.config
+import sys
 from cm.util import misc
 from cm.util import paths
 from cm.framework import messages
 class CMLogHandler(logging.Handler):
     def __init__(self, app):
         logging.Handler.__init__(self)
-        self.formatter = logging.Formatter("%(asctime)s - %(message)s", "%H:%M:%S")
-        # self.formatter = logging.Formatter("[%(levelname)s] %(module)s:%(lineno)d %(asctime)s: %(message)s")
+        self.formatter = logging.Formatter(
+            "%(asctime)s - %(message)s", "%H:%M:%S")
+        # self.formatter = logging.Formatter("[%(levelname)s]
+        # %(module)s:%(lineno)d %(asctime)s: %(message)s")
         self.setFormatter(self.formatter)
         self.logmessages = []
 
         self.use_object_store = self.ud.get("use_object_store", True)
         # From user data determine if block storage (EBS/nova-volume) should be used.
         # (OpenNebula and dummy clouds do not support volumes yet so skip those)
-        self.use_volumes = self.ud.get("use_volumes", self.cloud_type not in ['opennebula', 'dummy'])
+        self.use_volumes = self.ud.get(
+            "use_volumes", self.cloud_type not in ['opennebula', 'dummy'])
         # Read config file and check for errors
         self.config = config.Configuration(**kwargs)
         self.config.check()
         # Setup logging
         self.logger = CMLogHandler(self)
-        if self.ud.has_key("testflag"):
+        if "testflag" in self.ud:
             self.TESTFLAG = bool(self.ud['testflag'])
             self.logger.setLevel(logging.DEBUG)
         else:
             self.TESTFLAG = False
             self.logger.setLevel(logging.INFO)
 
-        if self.ud.has_key("localflag"):
+        if "localflag" in self.ud:
             self.LOCALFLAG = bool(self.ud['localflag'])
             self.logger.setLevel(logging.DEBUG)
         else:
         config.configure_logging(self.config, self.ud)
         log.debug("Initializing app")
         log.debug("Running on '{0}' type of cloud in zone '{1}' using image '{2}'."
-            .format(self.cloud_type, self.cloud_interface.get_zone(),
-            self.cloud_interface.get_ami()))
+                  .format(self.cloud_type, self.cloud_interface.get_zone(),
+                          self.cloud_interface.get_ami()))
 
         # App-wide object to store messages that need to travel between the back-end
         # and the UI.
         # Check that we actually got user creds in user data and inform user
         if not ('access_key' in self.ud or 'secret_key' in self.ud):
             self.msgs.error("No access credentials provided in user data. "
-                "You will not be able to add any services.")
+                            "You will not be able to add any services.")
         # Update user data to include persistent data stored in cluster's bucket, if it exists
-        # This enables cluster configuration to be recovered on cluster re-instantiation
+        # This enables cluster configuration to be recovered on cluster re-
+        # instantiation
         self.manager = None
-        if self.use_object_store and self.ud.has_key('bucket_cluster'):
+        if self.use_object_store and 'bucket_cluster' in self.ud:
             log.debug("Getting pd.yaml")
             if misc.get_file_from_bucket(self.cloud_interface.get_s3_connection(), self.ud['bucket_cluster'], 'persistent_data.yaml', 'pd.yaml'):
                 pd = misc.load_yaml_file('pd.yaml')
                 self.ud = misc.merge_yaml_objects(self.ud, pd)
                 self.ud = misc.normalize_user_data(self, self.ud)
-        if self.ud.has_key('role'):
+        if 'role' in self.ud:
             if self.ud['role'] == 'master':
                 log.info("Master starting")
                 from cm.util import master
             self.path_resolver = paths.PathResolver(self.manager)
             self.manager.console_monitor.start()
         else:
-            log.error("************ No ROLE in %s - this is a fatal error. ************" % paths.USER_DATA_FILE)
+            log.error("************ No ROLE in %s - this is a fatal error. ************" %
+                      paths.USER_DATA_FILE)
 
     def shutdown(self, delete_cluster=False):
         if self.manager:
             self.manager.shutdown(delete_cluster=delete_cluster)
-
-

File cm/base/controller.py

 """Contains functionality needed in every webapp interface"""
-import os, time, logging
+import os
+import time
+import logging
 from cm import util
 
-log = logging.getLogger( 'cloudman' )
+log = logging.getLogger('cloudman')
 
-class BaseController( object ):
+
+class BaseController(object):
     """Base class for CM webapp application controllers."""
-    def __init__( self, app ):
+    def __init__(self, app):
         """Initialize an interface for application 'app'"""
-        self.app = app
+        self.app = app

File cm/buildapp.py

 Provides factory methods to assemble the CM web application
 """
 
-import logging, atexit
-import os, os.path
+import logging
+import atexit
+import os
+import os.path
 
 from inspect import isclass
 
 from paste.deploy.converters import asbool
 import pkg_resources
 
-log = logging.getLogger( 'cloudman' )
+log = logging.getLogger('cloudman')
 
 import cm.framework
 from cm.util import misc
 from cm.util import paths
 from cm.app import UniverseApplication
 
-def add_controllers( webapp, app ):
+
+def add_controllers(webapp, app):
     """
-    Search for controllers in the 'cm.controllers' module and add 
+    Search for controllers in the 'cm.controllers' module and add
     them to the webapp.
     """
     from cm.base.controller import BaseController
     import cm.controllers
     controller_dir = cm.controllers.__path__[0]
-    
-    for fname in os.listdir( controller_dir ):
-        if not fname.startswith( "_" ) and not fname.startswith( "." ) and fname.endswith( ".py" ):
+
+    for fname in os.listdir(controller_dir):
+        if not fname.startswith("_") and not fname.startswith(".") and fname.endswith(".py"):
             name = fname[:-3]
             module_name = "cm.controllers." + name
-            module = __import__( module_name )
-            for comp in module_name.split( "." )[1:]:
-                module = getattr( module, comp )
+            module = __import__(module_name)
+            for comp in module_name.split(".")[1:]:
+                module = getattr(module, comp)
             # Look for a controller inside the modules
-            for key in dir( module ):
-                T = getattr( module, key )
-                if isclass( T ) and T is not BaseController and issubclass( T, BaseController ):
-                    webapp.add_controller( name, T( app ) )
+            for key in dir(module):
+                T = getattr(module, key)
+                if isclass(T) and T is not BaseController and issubclass(T, BaseController):
+                    webapp.add_controller(name, T(app))
 
-def app_factory( global_conf, **kwargs ):
+
+def app_factory(global_conf, **kwargs):
     """Return a wsgi application serving the root object"""
     # Create the CM application
-    app = UniverseApplication( global_conf = global_conf, **kwargs )
-    atexit.register( app.shutdown )
+    app = UniverseApplication(global_conf=global_conf, **kwargs)
+    atexit.register(app.shutdown)
     # Create the universe WSGI application
-    webapp = cm.framework.WebApplication( app )
-    add_controllers( webapp, app )
+    webapp = cm.framework.WebApplication(app)
+    add_controllers(webapp, app)
     # These two routes handle our simple needs at the moment
-    webapp.add_route( '/:controller/:action', controller="root", action='index' )
-    webapp.add_route( '/:action', controller='root', action='index' )
+    webapp.add_route(
+        '/:controller/:action', controller="root", action='index')
+    webapp.add_route('/:action', controller='root', action='index')
     webapp.finalize_config()
     # Wrap the webapp in some useful middleware
-    if kwargs.get( 'middleware', True ):
-        webapp = wrap_in_middleware( webapp, global_conf, **kwargs )
-    if kwargs.get( 'static_enabled', True ):
-        webapp = wrap_in_static( webapp, global_conf, **kwargs )
+    if kwargs.get('middleware', True):
+        webapp = wrap_in_middleware(webapp, global_conf, **kwargs)
+    if kwargs.get('static_enabled', True):
+        webapp = wrap_in_static(webapp, global_conf, **kwargs)
     # Return
     return webapp
 
+
 def cm_authfunc(environ, username, password):
     ud = misc.load_yaml_file(paths.USER_DATA_FILE)
     if 'password' in ud:
             return True
     return False
 
-def wrap_in_middleware( app, global_conf, **local_conf ):
+
+def wrap_in_middleware(app, global_conf, **local_conf):
     """Based on the configuration wrap `app` in a set of common and useful middleware."""
     # Merge the global and local configurations
     conf = global_conf.copy()
     conf.update(local_conf)
-    debug = asbool( conf.get( 'debug', False ) )
+    debug = asbool(conf.get('debug', False))
     # First put into place httpexceptions, which must be most closely
     # wrapped around the application (it can interact poorly with
     # other middleware):
-    app = httpexceptions.make_middleware( app, conf )
-    log.debug( "Enabling 'httpexceptions' middleware" )
-    # The recursive middleware allows for including requests in other 
+    app = httpexceptions.make_middleware(app, conf)
+    log.debug("Enabling 'httpexceptions' middleware")
+    # The recursive middleware allows for including requests in other
     # requests or forwarding of requests, all on the server side.
     if asbool(conf.get('use_recursive', True)):
         from paste import recursive
-        app = recursive.RecursiveMiddleware( app, conf )
-        log.debug( "Enabling 'recursive' middleware" )
+        app = recursive.RecursiveMiddleware(app, conf)
+        log.debug("Enabling 'recursive' middleware")
     # Various debug middleware that can only be turned on if the debug
     # flag is set, either because they are insecure or greatly hurt
     # performance
     if debug:
         # Middleware to check for WSGI compliance
-        if asbool( conf.get( 'use_lint', True ) ):
+        if asbool(conf.get('use_lint', True)):
             from paste import lint
-            app = lint.make_middleware( app, conf )
-            log.debug( "Enabling 'lint' middleware" )
+            app = lint.make_middleware(app, conf)
+            log.debug("Enabling 'lint' middleware")
         # Middleware to run the python profiler on each request
-        if asbool( conf.get( 'use_profile', False ) ):
+        if asbool(conf.get('use_profile', False)):
             import profile
-            app = profile.ProfileMiddleware( app, conf )
-            log.debug( "Enabling 'profile' middleware" )
+            app = profile.ProfileMiddleware(app, conf)
+            log.debug("Enabling 'profile' middleware")
         # Middleware that intercepts print statements and shows them on the
         # returned page
-        if asbool( conf.get( 'use_printdebug', True ) ):
+        if asbool(conf.get('use_printdebug', True)):
             from paste.debug import prints
-            app = prints.PrintDebugMiddleware( app, conf )
-            log.debug( "Enabling 'print debug' middleware" )
-    if debug and asbool( conf.get( 'use_interactive', False ) ):
+            app = prints.PrintDebugMiddleware(app, conf)
+            log.debug("Enabling 'print debug' middleware")
+    if debug and asbool(conf.get('use_interactive', False)):
         # Interactive exception debugging, scary dangerous if publicly
         # accessible, if not enabled we'll use the regular error printing
         # middleware.
-        pkg_resources.require( "WebError" )
+        pkg_resources.require("WebError")
         from weberror import evalexception
-        app = evalexception.EvalException( app, conf,
-                                           templating_formatters=build_template_error_formatters() )
-        log.debug( "Enabling 'eval exceptions' middleware" )
+        app = evalexception.EvalException(app, conf,
+                                          templating_formatters=build_template_error_formatters())
+        log.debug("Enabling 'eval exceptions' middleware")
     else:
         # Not in interactive debug mode, just use the regular error middleware
         from paste.exceptions import errormiddleware
-        app = errormiddleware.ErrorMiddleware( app, conf )
-        log.debug( "Enabling 'error' middleware" )
+        app = errormiddleware.ErrorMiddleware(app, conf)
+        log.debug("Enabling 'error' middleware")
     # Transaction logging (apache access.log style)
-    if asbool( conf.get( 'use_translogger', True ) ):
+    if asbool(conf.get('use_translogger', True)):
         from paste.translogger import TransLogger
-        app = TransLogger( app )
-        log.debug( "Enabling 'trans logger' middleware" )
+        app = TransLogger(app)
+        log.debug("Enabling 'trans logger' middleware")
     # Config middleware just stores the paste config along with the request,
     # not sure we need this but useful
     from paste.deploy.config import ConfigMiddleware
-    app = ConfigMiddleware( app, conf )
-    log.debug( "Enabling 'config' middleware" )
+    app = ConfigMiddleware(app, conf)
+    log.debug("Enabling 'config' middleware")
     # X-Forwarded-Host handling
     from cm.framework.middleware.xforwardedhost import XForwardedHostMiddleware
-    app = XForwardedHostMiddleware( app )
-    log.debug( "Enabling 'x-forwarded-host' middleware" )
+    app = XForwardedHostMiddleware(app)
+    log.debug("Enabling 'x-forwarded-host' middleware")
     # Paste digest authentication
     ud = misc.load_yaml_file(paths.USER_DATA_FILE)
-    if ud.has_key('password'):
+    if 'password' in ud:
         if ud['password'] != '':
             from paste.auth.basic import AuthBasicHandler
             app = AuthBasicHandler(app, 'CM Administration', cm_authfunc)
     return app
 
-def wrap_in_static( app, global_conf, **local_conf ):
+
+def wrap_in_static(app, global_conf, **local_conf):
     from paste.urlmap import URLMap
     from cm.framework.middleware.static import CacheableStaticURLParser as Static
     urlmap = URLMap()
     conf = global_conf.copy()
     conf.update(local_conf)
     # Get cache time in seconds
-    cache_time = conf.get( "static_cache_time", None )
+    cache_time = conf.get("static_cache_time", None)
     if cache_time is not None:
-        cache_time = int( cache_time )
+        cache_time = int(cache_time)
     # Send to dynamic app by default
     urlmap["/"] = app
     # Define static mappings from config
-    urlmap["/static"] = Static( conf.get( "static_dir" ), cache_time )
-    urlmap["/images"] = Static( conf.get( "static_images_dir" ), cache_time )
-    urlmap["/static/scripts"] = Static( conf.get( "static_scripts_dir" ), cache_time )
-    urlmap["/static/style"] = Static( conf.get( "static_style_dir" ), cache_time )
-    urlmap["/favicon.ico"] = Static( conf.get( "static_favicon_dir" ), cache_time )
+    urlmap["/static"] = Static(conf.get("static_dir"), cache_time)
+    urlmap["/images"] = Static(conf.get("static_images_dir"), cache_time)
+    urlmap["/static/scripts"] = Static(
+        conf.get("static_scripts_dir"), cache_time)
+    urlmap["/static/style"] = Static(conf.get("static_style_dir"),
+                                     cache_time)
+    urlmap["/favicon.ico"] = Static(conf.get("static_favicon_dir"),
+                                    cache_time)
     # URL mapper becomes the root webapp
     return urlmap
 
+
 def build_template_error_formatters():
     """
     Build a list of template error formatters for WebError. When an error
     formatters = []
     # Formatter for mako
     import mako.exceptions
-    def mako_html_data( exc_value ):
-        if isinstance( exc_value, ( mako.exceptions.CompileException, mako.exceptions.SyntaxException ) ):
-            return mako.exceptions.html_error_template().render( full=False, css=False )
-        if isinstance( exc_value, AttributeError ) and exc_value.args[0].startswith( "'Undefined' object has no attribute" ):
-            return mako.exceptions.html_error_template().render( full=False, css=False )
-    
-    formatters.append( mako_html_data )
+
+    def mako_html_data(exc_value):
+        if isinstance(exc_value, (mako.exceptions.CompileException, mako.exceptions.SyntaxException)):
+            return mako.exceptions.html_error_template().render(full=False, css=False)
+        if isinstance(exc_value, AttributeError) and exc_value.args[0].startswith("'Undefined' object has no attribute"):
+            return mako.exceptions.html_error_template().render(full=False, css=False)
+
+    formatters.append(mako_html_data)
     return formatters

File cm/clouds/__init__.py

 import logging
 log = logging.getLogger('cloudman')
 
+
 class CloudInterface(object):
     # Global fields
     ec2_conn = None
     ami = None
     instance_type = None
     instance_id = None
-    instance = None # boto object representation of the instance
+    instance = None  # boto object representation of the instance
     zone = None
     security_groups = None
     key_pair_name = None
         """
         log.warning("Unimplemented")
         pass
-

File cm/clouds/cloud_config.py

 from cm.clouds.dummy import DummyInterface
 from cm.clouds.eucalyptus import EucaInterface
 
+
 class CloudConfig(object):
     """ Configuration class that is used as a mediator for support between
         different clouds.
     """
     def __init__(self, app):
         self.app = app
-    
+
     def get_cloud_type(self):
-        """ Determine the type of cloud currently being running on. 
+        """ Determine the type of cloud currently being running on.
             If needed, this method should be extended to include other
             (or alternative) methods for detecting the type of cloud.
-            
+
             The current assumption is that the type of cloud is included as
             part of user data and stored in paths.USER_DATA_FILE file
             under 'cloud_type' key.
         """
         return misc.load_yaml_file(paths.USER_DATA_FILE).get('cloud_type', 'ec2').lower()
-    
+
     def get_cloud_interface(self, cloud_type=None):
         """ Return the approprtae cloud interface object based on the cloud_type
-            
+
             :type cloud_type: string
-            :param cloud_type: The type of cloud currently running on. 
+            :param cloud_type: The type of cloud currently running on.
                                Currently, the accepted values include:
                                'ec2', 'openstack', 'opennebula', and 'dummy'
-                               
+
             :return: The cloud interface object for the specific cloud type
         """
         if cloud_type is None:
             cloud_interface = ONInterface(app=self.app)
         elif cloud_type == 'dummy':
             cloud_interface = DummyInterface(app=self.app)
-        elif cloud_type == 'euca' or cloud_type.lower()=='eucalyptus':
+        elif cloud_type == 'euca' or cloud_type.lower() == 'eucalyptus':
             cloud_interface = EucaInterface(app=self.app)
         return cloud_interface
-        
-    

File cm/clouds/dummy.py

-import urllib, socket
+import urllib
+import socket
 from cm.clouds import CloudInterface
 from cm.services.data.filesystem import Volume
 
 import subprocess
 
 import logging
-log = logging.getLogger( 'cloudman' )
+log = logging.getLogger('cloudman')
+
 
 class DummyInterface(CloudInterface):
-    
+
     def __init__(self, app):
         super(DummyInterface, self).__init__()
         self.app = app
         self.bridge = 72
-        
+
     def set_configuration(self):
         if self.user_data is None:
             self.get_user_data()
         self.on_username = self.user_data.get('on_username', None)
         self.on_password = self.user_data.get('on_password', None)
         self.on_host = self.user_data.get('on_host', None)
-    
+
     def _getIpAddress(self, ifname):
         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
         try:
             ip = socket.inet_ntoa(fcntl.ioctl(
-                                            s.fileno(),
-                                            0x8915,  # SIOCGIFADDR
-                                            struct.pack('256s', ifname[:15])
-                                            )[20:24])
+                s.fileno(),
+                0x8915,  # SIOCGIFADDR
+                struct.pack('256s', ifname[:15])
+            )[20:24])
         except IOError:
             return None
         return ip
 
     def _getMacAddress(self, ifname):
         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        info = fcntl.ioctl(s.fileno(), 0x8927,  struct.pack('256s', ifname[:15]))
+        info = fcntl.ioctl(
+            s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
         return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
 
-    def get_ami( self ):
+    def get_ami(self):
         pass
-    
-    def get_type( self ):
-        #return 'worker'
+
+    def get_type(self):
+        # return 'worker'
         pass
-    
-    def get_instance_id( self ):
+
+    def get_instance_id(self):
         pass
-    
-    def get_zone( self ):
+
+    def get_zone(self):
         pass
-    
-    def get_security_groups( self ):
+
+    def get_security_groups(self):
         pass
-    
-    def get_key_pair_name( self ):
+
+    def get_key_pair_name(self):
         pass
-    
-    def get_private_ip( self ):
+
+    def get_private_ip(self):
         return self._getIpAddress('eth0')
-    
-    def get_public_ip( self ):
+
+    def get_public_ip(self):
         pass
-    
+
     def get_fqdn(self):
         # Return the hostname
         return socket.getfqdn()
-    
-    def get_ec2_connection( self ):
+
+    def get_ec2_connection(self):
         pass
-    
-    def get_s3_connection( self ):
-       pass
-    
+
+    def get_s3_connection(self):
+        pass
+
     def run_instances(self, image_id, min_count, max_count, key_name, security_groups, user_data, instance_type, placement):
         pass
 
 
     def get_all_volumes(self, *args, **kwargs):
         pass
-    
+
     def terminate_instances(self, instances):
         log.debug("Terminate instances")
-        
+
         return True
 
     def reboot_instances(self, instances, *args, **kwargs):
         pass
-    
 
 
-        
 class Reservations(object):
     def __init__(self):
         self.instances = []
 
 # A EC2 instance object has a add_tag method
 # which is lacking in the OpenNebula object
+
+
 def add_tag(self, key, value, *args, **kwargs):
     self.tags[key] = value
 
+
 def update(self):
     """Should update instance"""
     log.debug("Trying to update")
     log.debug("Instance id: %s" % self.id)
 
 
-
-#def get_m_state(self):
+# def get_m_state(self):
 #    print "GET M STATE"
 #    print self.state
-
-#TODO: Work on Bucket System!!
+# TODO: Work on Bucket System!!
 # A EC2 connection object has lookup method
 # which is lacking in the oca Client object
 def lookup(self, *args, **kwargs):
     pass
 
+
 def create_bucket(self, *args, **kwargs):
-    pass
+    pass

File cm/clouds/ec2.py

 from cm.util.decorators import TestFlag
 
 import logging
-log = logging.getLogger( 'cloudman' )
+log = logging.getLogger('cloudman')
 
 
 class EC2Interface(CloudInterface):
         self.public_hostname_updated = time.time()
         self.set_configuration()
 
-    def get_ami( self ):
+    def get_ami(self):
         if self.ami is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get key pair name, but TESTFLAG is set. Returning 'ami-l0cal1'")
+                log.debug(
+                    "Attempted to get key pair name, but TESTFLAG is set. Returning 'ami-l0cal1'")
                 self.ami = 'ami-l0cal1'
                 return self.ami
             for i in range(0, 5):
                 try:
                     log.debug('Gathering instance ami, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/ami-id')
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/ami-id')
                     self.ami = fp.read()
                     fp.close()
                     if self.ami:
         return self.ami
 
     @TestFlag('something.good')
-    def get_type( self ):
+    def get_type(self):
         if self.instance_type is None:
             for i in range(0, 5):
                 try:
                     log.debug('Gathering instance type, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/instance-type')
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/instance-type')
                     self.instance_type = fp.read()
                     fp.close()
                     if self.instance_type:
                     pass
         return self.instance_type
 
-    def get_instance_id( self ):
+    def get_instance_id(self):
         if self.instance_id is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get instance ID, but TESTFLAG is set. Returning 'id-LOCAL'")
+                log.debug(
+                    "Attempted to get instance ID, but TESTFLAG is set. Returning 'id-LOCAL'")
                 self.instance_id = 'id-LOCAL'
                 return self.instance_id
             for i in range(0, 5):
                 try:
                     log.debug('Gathering instance id, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/instance-id')
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/instance-id')
                     self.instance_id = fp.read()
                     fp.close()
                     if self.instance_id:
         log.debug("Getting instance object: %s" % self.instance)
         if self.instance is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get instance object, but TESTFLAG is set. Returning 'None'")
+                log.debug(
+                    "Attempted to get instance object, but TESTFLAG is set. Returning 'None'")
                 return self.instance
             log.debug("Getting instance boto object")
             i_id = self.get_instance_id()
                 log.debug("Error retrieving instance object: {0}".format(e))
         return self.instance
 
-    def get_zone( self ):
+    def get_zone(self):
         if self.zone is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get instance zone, but TESTFLAG is set. Returning 'us-east-1a'")
+                log.debug(
+                    "Attempted to get instance zone, but TESTFLAG is set. Returning 'us-east-1a'")
                 self.zone = 'us-east-1a'
                 return self.zone
             for i in range(0, 5):
                 try:
                     log.debug('Gathering instance zone, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/placement/availability-zone')
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/placement/availability-zone')
                     self.zone = fp.read()
                     fp.close()
                     if self.zone:
                     pass
         return self.zone
 
-    def get_security_groups( self ):
+    def get_security_groups(self):
         if self.security_groups is None:
             if self.app.TESTFLAG is True:
                 log.debug("Attempted to get key pair name, but TESTFLAG is set. Returning 'cloudman_sg'")
                 return self.security_groups
             for i in range(0, 5):
                 try:
-                    log.debug('Gathering instance security group, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/security-groups')
+                    log.debug(
+                        'Gathering instance security group, attempt %s' % i)
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/security-groups')
                     self.security_groups = []
                     for line in fp.readlines():
-                        self.security_groups.append(urllib.unquote_plus(line.strip()))
+                        self.security_groups.append(
+                            urllib.unquote_plus(line.strip()))
                     fp.close()
                     if self.security_groups:
                         break
                     pass
         return self.security_groups
 
-    def get_key_pair_name( self ):
+    def get_key_pair_name(self):
         if self.key_pair_name is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get key pair name, but TESTFLAG is set. Returning 'local_keypair'")
+                log.debug(
+                    "Attempted to get key pair name, but TESTFLAG is set. Returning 'local_keypair'")
                 self.key_pair_name = 'local_keypair'
                 return self.key_pair_name
             for i in range(0, 5):
                 try:
-                    log.debug('Gathering instance public keys (i.e., key pairs), attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/public-keys')
+                    log.debug(
+                        'Gathering instance public keys (i.e., key pairs), attempt %s' % i)
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/public-keys')
                     public_keys = fp.read()
                     self.key_pair_name = public_keys.split('=')[1]
                     fp.close()
                     if self.key_pair_name:
-                        log.debug( "Got key pair: '%s'" % self.key_pair_name )
+                        log.debug("Got key pair: '%s'" % self.key_pair_name)
                         break
                 except IOError:
                     pass
         return self.key_pair_name
 
-    def get_private_ip( self ):
+    def get_private_ip(self):
         if self.self_private_ip is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get key pair name, but TESTFLAG is set. Returning '127.0.0.1'")
+                log.debug(
+                    "Attempted to get key pair name, but TESTFLAG is set. Returning '127.0.0.1'")
                 self.self_private_ip = '127.0.0.1'
                 return self.self_private_ip
             for i in range(0, 5):
                 try:
                     log.debug('Gathering instance private IP, attempt %s' % i)
-                    # fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/local-hostname')
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/local-ipv4')
+                    # fp = urllib.urlopen('http://169.254.169.254/latest/meta-
+                    # data/local-hostname')
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/local-ipv4')
                     self.self_private_ip = fp.read()
                     fp.close()
                     if self.self_private_ip:
     def get_local_hostname(self):
         if self.local_hostname is None:
             if self.app.TESTFLAG is True:
-                log.debug("Attempted to get key pair name, but TESTFLAG is set. Returning 'localhost'")
+                log.debug(
+                    "Attempted to get key pair name, but TESTFLAG is set. Returning 'localhost'")
                 self.local_hostname = 'localhost'
                 return self.local_hostname
             for i in range(0, 5):
                 try:
-                    log.debug('Gathering instance local hostname, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/local-hostname')
+                    log.debug(
+                        'Gathering instance local hostname, attempt %s' % i)
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/local-hostname')
                     self.local_hostname = fp.read()
                     fp.close()
                     if self.local_hostname:
                     pass
         return self.local_hostname
 
-    def get_public_hostname( self ):
+    def get_public_hostname(self):
         """
         Return the current public hostname reported by Amazon.
         Public hostname can be changed -- check it every self.update_frequency.
         """
         if self.app.TESTFLAG is True:
-            log.debug("Attempted to get public hostname, but TESTFLAG is set. Returning '127.0.0.1'")
+            log.debug(
+                "Attempted to get public hostname, but TESTFLAG is set. Returning '127.0.0.1'")
             self.self_public_hostname = 'localhost'
             self.public_hostname_updated = time.time()
             return self.public_hostname
         if self.public_hostname is None or (time.time() - self.public_hostname_updated > self.update_frequency):
             for i in range(0, 5):
                 try:
-                    log.debug('Gathering instance public hostname, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/public-hostname')
+                    log.debug(
+                        'Gathering instance public hostname, attempt %s' % i)
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/public-hostname')
                     self.public_hostname = fp.read()
                     fp.close()
                     if self.public_hostname:
                         self.public_hostname_updated = time.time()
                         break
                 except Exception, e:
-                    log.error ( "Error retrieving FQDN: %s" % e )
+                    log.error("Error retrieving FQDN: %s" % e)
         return self.public_hostname
 
-    def get_public_ip( self ):
+    def get_public_ip(self):
         if self.self_public_ip is None:
             if self.app.TESTFLAG is True:
                 log.debug("Attempted to get public IP, but TESTFLAG is set. Returning '127.0.0.1'")
                 return self.self_public_ip
             for i in range(0, 5):
                 try:
-                    log.debug('Gathering instance public hostname, attempt %s' % i)
-                    fp = urllib.urlopen('http://169.254.169.254/latest/meta-data/public-ipv4')
+                    log.debug(
+                        'Gathering instance public hostname, attempt %s' % i)
+                    fp = urllib.urlopen(
+                        'http://169.254.169.254/latest/meta-data/public-ipv4')
                     self.self_public_ip = fp.read()
                     fp.close()
                     if self.self_public_ip:
                         break
                 except Exception, e:
-                    log.error ( "Error retrieving FQDN: %s" % e )
+                    log.error("Error retrieving FQDN: %s" % e)
 
         return self.self_public_ip
 
     def get_fqdn(self):
-        log.debug( "Retrieving FQDN" )
+        log.debug("Retrieving FQDN")
         if self.fqdn == None:
             try:
                 self.fqdn = socket.getfqdn()
                 pass
         return self.fqdn
 
-    def get_ec2_connection( self ):
+    def get_ec2_connection(self):
         if self.ec2_conn == None:
             try:
                 if self.app.TESTFLAG is True:
                     log.debug("Attempted to establish EC2 connection, but TESTFLAG is set. "
-                        "Returning default EC2 connection.")
-                    self.ec2_conn = EC2Connection(self.aws_access_key, self.aws_secret_key)
+                              "Returning default EC2 connection.")
+                    self.ec2_conn = EC2Connection(
+                        self.aws_access_key, self.aws_secret_key)
                     return self.ec2_conn
                 log.debug('Establishing boto EC2 connection')
-                # In order to get a connection for the correct region, get instance zone and go from there
-                zone = self.get_zone()[:-1] # truncate zone and be left with region name
-                tmp_conn = EC2Connection(self.aws_access_key, self.aws_secret_key) # get conn in default region
+                # In order to get a connection for the correct region, get
+                # instance zone and go from there
+                zone = self.get_zone(
+                )[:-1]  # truncate zone and be left with region name
+                tmp_conn = EC2Connection(self.aws_access_key,
+                                         self.aws_secret_key)  # get conn in default region
                 try:
                     regions = tmp_conn.get_all_regions()
                 except EC2ResponseError, e:
-                    log.error("Cannot validate provided AWS credentials: %s" % e)
-                # Find region that matches instance zone and then create ec2_conn
+                    log.error(
+                        "Cannot validate provided AWS credentials: %s" % e)
+                # Find region that matches instance zone and then create
+                # ec2_conn
                 for r in regions:
                     if zone in r.name:
                         region = r
                         break
-                self.ec2_conn = EC2Connection(self.aws_access_key, self.aws_secret_key, region=region)
+                self.ec2_conn = EC2Connection(
+                    self.aws_access_key, self.aws_secret_key, region=region)
                 # Do a simple query to test if provided credentials are valid
                 try:
                     self.ec2_conn.get_all_instances()
-                    log.debug("Got boto EC2 connection for region '%s'" % self.ec2_conn.region.name)
+                    log.debug("Got boto EC2 connection for region '%s'" %
+                              self.ec2_conn.region.name)
                 except EC2ResponseError, e:
-                    log.error("Cannot validate provided AWS credentials (A:%s, S:%s): %s" \
-                        % (self.aws_access_key, self.aws_secret_key, e))
+                    log.error("Cannot validate provided AWS credentials (A:%s, S:%s): %s"
+                              % (self.aws_access_key, self.aws_secret_key, e))
                     self.ec2_conn = False
             except Exception, e:
                 log.error(e)
         return self.ec2_conn
 
-    def get_s3_connection( self ):
+    def get_s3_connection(self):
         # log.debug( 'Getting boto S3 connection' )
         if self.s3_conn == None:
             log.debug("No S3 Connection, creating a new one.")
             try:
-                self.s3_conn = S3Connection(self.aws_access_key, self.aws_secret_key)
-                log.debug( 'Got boto S3 connection.' )
+                self.s3_conn = S3Connection(
+                    self.aws_access_key, self.aws_secret_key)
+                log.debug('Got boto S3 connection.')
                 # try:
                 #     self.s3_conn.get_bucket('test_creds') # Any bucket name will do - just testing the call
                 #     log.debug( 'Got boto S3 connection.' )
         """
         if self.tags_supported:
             try:
-                log.debug("Adding tag '%s:%s' to resource '%s'" % (key, value, resource.id if resource.id else resource))
+                log.debug("Adding tag '%s:%s' to resource '%s'" % (
+                    key, value, resource.id if resource.id else resource))
                 resource.add_tag(key, value)
             except EC2ResponseError, e:
-                log.error("Exception adding tag '%s:%s' to resource '%s': %s" % (key, value, resource, e))
+                log.error(
+                    "Exception adding tag '%s:%s' to resource '%s': %s" % (key,
+                                                                           value, resource, e))
                 self.tags_supported = False
         resource_tags = self.tags.get(resource.id, {})
         resource_tags[key] = value
         value = None
         if self.tags_supported:
             try:
-                log.debug("Getting tag '%s' on resource '%s'" % (key, resource.id))
+                log.debug(
+                    "Getting tag '%s' on resource '%s'" % (key, resource.id))
                 value = resource.tags.get(key, None)
             except EC2ResponseError, e:
-                log.error("Exception getting tag '%s' on resource '%s': %s" % (key, resource, e))
+                log.error("Exception getting tag '%s' on resource '%s': %s" %
+                          (key, resource, e))
                 self.tags_supported = False
         if not value:
-            resource_tags = self.tags.get(resource.id,{})
+            resource_tags = self.tags.get(resource.id, {})
             value = resource_tags.get(key)
         return value
 
         use_spot = False
         if spot_price is not None:
             use_spot = True
-        log.info("Adding {0} {1} instance(s)".format(num, 'spot' if use_spot else 'on-demand'))
+        log.info("Adding {0} {1} instance(s)".format(
+            num, 'spot' if use_spot else 'on-demand'))
         if self.app.TESTFLAG is True:
             log.debug("Attempted to start instance(s), but TESTFLAG is set.")
             return
         if use_spot:
             self._make_spot_request(num, instance_type, spot_price, worker_ud)
         else:
-            self._run_ondemand_instances(num, instance_type, spot_price, worker_ud)
+            self._run_ondemand_instances(
+                num, instance_type, spot_price, worker_ud)
 
     def _run_ondemand_instances(self, num, instance_type, spot_price, worker_ud, min_num=1):
-        worker_ud_str = "\n".join(['%s: %s' % (key, value) for key, value in worker_ud.iteritems()])
+        worker_ud_str = "\n".join(
+            ['%s: %s' % (key, value) for key, value in worker_ud.iteritems()])
         log.debug("Starting instance(s) with the following command : ec2_conn.run_instances( "
-              "image_id='{iid}', min_count='{min_num}', max_count='{num}', key_name='{key}', "
-              "security_groups=['{sgs}'], user_data=[{ud}], instance_type='{type}', placement='{zone}')"
-              .format(iid=self.get_ami(), min_num=min_num, num=num, key=self.get_key_pair_name(), \
-              sgs=", ".join(self.get_security_groups()), ud=worker_ud_str, type=instance_type, \
-              zone=self.get_zone()))
+                  "image_id='{iid}', min_count='{min_num}', max_count='{num}', key_name='{key}', "
+                  "security_groups=['{sgs}'], user_data=[{ud}], instance_type='{type}', placement='{zone}')"
+                  .format(
+                  iid=self.get_ami(), min_num=min_num, num=num, key=self.get_key_pair_name(),
+                      sgs=", ".join(self.get_security_groups()), ud=worker_ud_str, type=instance_type,
+                      zone=self.get_zone()))
         try:
             # log.debug( "Would be starting worker instance(s)..." )
             reservation = None
             ec2_conn = self.get_ec2_connection()
-            reservation = ec2_conn.run_instances( image_id=self.get_ami(),
-                                                  min_count=min_num,
-                                                  max_count=num,
-                                                  key_name=self.get_key_pair_name(),
-                                                  security_groups=self.get_security_groups(),
-                                                  user_data=worker_ud_str,
-                                                  instance_type=instance_type,
-                                                  placement=self.get_zone() )
-            time.sleep(3) # Rarely, instances take a bit to register,
-                          # so wait a few seconds (although this is a very poor 'solution')
+            reservation = ec2_conn.run_instances(image_id=self.get_ami(),
+                                                 min_count=min_num,
+                                                 max_count=num,
+                                                 key_name=self.get_key_pair_name(
+                                                 ),
+                                                 security_groups=self.get_security_groups(
+                                                 ),
+                                                 user_data=worker_ud_str,
+                                                 instance_type=instance_type,
+                                                 placement=self.get_zone())
+            time.sleep(3)  # Rarely, instances take a bit to register,
+                          # so wait a few seconds (although this is a very poor
+                          # 'solution')
             if reservation:
                 for instance in reservation.instances:
-                    self.add_tag(instance, 'clusterName', self.app.ud['cluster_name'])
+                    self.add_tag(
+                        instance, 'clusterName', self.app.ud['cluster_name'])
                     self.add_tag(instance, 'role', worker_ud['role'])
-                    i = Instance(app=self.app, inst=instance, m_state=instance.state)
+                    i = Instance(
+                        app=self.app, inst=instance, m_state=instance.state)
                     log.debug("Adding Instance %s" % instance)
-                    self.app.manager.worker_instances.append( i )
+                    self.app.manager.worker_instances.append(i)
         except BotoServerError, e:
-            log.error( "boto server error when starting an instance: %s" % str( e ) )
+            log.error(
+                "boto server error when starting an instance: %s" % str(e))
             return False
         except EC2ResponseError, e:
-            err = "EC2 response error when starting worker nodes: %s" % str( e )
-            log.error( err )
+            err = "EC2 response error when starting worker nodes: %s" % str(e)
+            log.error(err)
             return False
         except Exception, ex:
-            err = "Error when starting worker nodes: %s" % str( ex )
-            log.error( err )
+            err = "Error when starting worker nodes: %s" % str(ex)
+            log.error(err)
             return False
-        log.debug( "Started %s instance(s)" % num )
+        log.debug("Started %s instance(s)" % num)
 
     def _make_spot_request(self, num, instance_type, price, worker_ud):
-        worker_ud_str = "\n".join(['%s: %s' % (key, value) for key, value in worker_ud.iteritems()])
+        worker_ud_str = "\n".join(
+            ['%s: %s' % (key, value) for key, value in worker_ud.iteritems()])
         log.debug("Making a Spot request with the following command: "
                   "ec2_conn.request_spot_instances(price='{price}', image_id='{iid}', "
                   "count='{num}', key_name='{key}', security_groups=['{sgs}'], "
-                  "instance_type='{type}', placement='{zone}', user_data='{ud}')"\
-                  .format(price=price, iid=self.get_ami(), num=num, key=self.get_key_pair_name(), \
-                  sgs=", ".join(self.get_security_groups()), type=instance_type, \
+                  "instance_type='{type}', placement='{zone}', user_data='{ud}')"
+                  .format(
+                      price=price, iid=self.get_ami(), num=num, key=self.get_key_pair_name(),
+                  sgs=", ".join(self.get_security_groups()), type=instance_type,
                   zone=self.get_zone(), ud=worker_ud_str))
         reqs = None
         try:
             reqs = ec2_conn.request_spot_instances(price=price,
                                                    image_id=self.get_ami(),
                                                    count=num,
-                                                   key_name=self.get_key_pair_name(),
-                                                   security_groups=self.get_security_groups(),
+                                                   key_name=self.get_key_pair_name(
+                                                   ),
+                                                   security_groups=self.get_security_groups(
+                                                   ),
                                                    instance_type=instance_type,
                                                    placement=self.get_zone(),
                                                    user_data=worker_ud_str)
             if reqs is not None:
                 for req in reqs:
                     i = Instance(app=self.app, spot_request_id=req.id)
-                    log.debug("Adding Spot request {0} as an Instance".format(req.id))
+                    log.debug("Adding Spot request {0} as an Instance".format(
+                        req.id))
                     self.app.manager.worker_instances.append(i)
         except EC2ResponseError, e:
             log.error("Trouble issuing a spot instance request: {0}".format(e))
         try:
             log.info("Terminating instance {0}".format(instance_id))
             ec2_conn.terminate_instances([instance_id])
-            log.debug("Initiated termination of instance {0}".format(instance_id))
+            log.debug(
+                "Initiated termination of instance {0}".format(instance_id))
             # Make sure the instance was terminated
-            time.sleep(3) # First give the middleware a chance to register the termination
+            time.sleep(
+                3)  # First give the middleware a chance to register the termination
             rs = ec2_conn.get_all_instances([instance_id])
             if len(rs) == 0 or rs[0].instances[0].state == 'shutting-down' or \
-                rs[0].instances[0].state == 'terminated':
+                    rs[0].instances[0].state == 'terminated':
                 log.debug("Instance {0} terminated.".format(instance_id))
                 return True
         except EC2ResponseError, e:
             if e.errors[0][0] == 'InstanceNotFound':
                 return True
             else:
-                log.error("EC2 exception terminating instance '%s': %s" % (instance_id, e))
+                log.error(
+                    "EC2 exception terminating instance '%s': %s" % (instance_id, e))
         except Exception, ex:
-            log.error("Exception terminating instance %s: %s" % (instance_id, ex))
+            log.error(
+                "Exception terminating instance %s: %s" % (instance_id, ex))
         return False
 
     def _cancel_spot_request(self, request_id):
             ec2_conn.cancel_spot_instance_requests([request_id])
             return True
         except EC2ResponseError, e:
-            log.error("Trouble canceling spot request {0}: {1}".format(request_id, e))
+            log.error("Trouble canceling spot request {0}: {1}".format(
+                request_id, e))
             return False
 
     def _compose_worker_user_data(self):

File cm/clouds/eucalyptus.py

-import socket, time
+import socket
+import time
 from cm.clouds.ec2 import EC2Interface
 from cm.util import misc
 from cm.util import paths
 
 ## debugging
 import traceback
+
+
 class DebugException(Exception):
     pass
 
+
 def stacktrace_wrapper(old_method):
 
-    def _w(self,*args,**kwargs):
+    def _w(self, *args, **kwargs):
         try:
             raise DebugException()
         except DebugException:
             log.debug('get_all_instances() called. Trace follows...')
             traceback.print_stack()
-        return old_method(self,*args,**kwargs)
+        return old_method(self, *args, **kwargs)
 
     return _w
 
-# EC2Connection.get_all_instances = stacktrace_wrapper(EC2Connection.get_all_instances)
-
+# EC2Connection.get_all_instances =
+# stacktrace_wrapper(EC2Connection.get_all_instances)
 
 
 import logging
-log = logging.getLogger( 'cloudman' )
+log = logging.getLogger('cloudman')
+
 
 class _DummyApp:
     """to allow for checking TESTFLAG attribute if no app passed"""
     def __init__(self):
         self.TESTFLAG = False
 
+
 class EucaInterface(EC2Interface):
     """
         A specialization of cm.clouds.ec2 allowing use of private Eucalyptus clouds.
         self._last_volume_check = None
 
     def set_configuration(self):
-        super(EucaInterface,self).set_configuration()
-        self.s3_url = self.user_data.get('s3_url',None)
-        self.ec2_url = self.user_data.get('ec2_url',None)
+        super(EucaInterface, self).set_configuration()
+        self.s3_url = self.user_data.get('s3_url', None)
+        self.ec2_url = self.user_data.get('ec2_url', None)
 
-    def get_ec2_connection( self ):
+    def get_ec2_connection(self):
         if not self.ec2_conn:
             if self.ec2_url:
                 url = urlparse(self.ec2_url)
                 else:
                     is_secure = False
                 try:
-                    log.debug('Establishing local boto EC2 connection to %s' % self.ec2_url)
+                    log.debug(
+                        'Establishing local boto EC2 connection to %s' % self.ec2_url)
                     zone = self.get_zone()
-                    region = RegionInfo(name=zone,endpoint=host)
+                    region = RegionInfo(name=zone, endpoint=host)
                     self.ec2_conn = EC2Connection(
-                                             aws_access_key_id = self.aws_access_key,
-                                             aws_secret_access_key = self.aws_secret_key,
-                                             is_secure = is_secure,
-                                             host = host,
-                                             port = port,
-                                             path = path,
-                                             region = region,
-                                             debug = 2,
+                        aws_access_key_id=self.aws_access_key,
+                        aws_secret_access_key=self.aws_secret_key,
+                        is_secure=is_secure,
+                        host=host,
+                        port=port,
+                        path=path,
+                        region=region,
+                        debug=2,
                     )
-                    # Do a simple query to test if provided credentials are valid
+                    # Do a simple query to test if provided credentials are
+                    # valid
                     try:
                         self.ec2_conn.get_all_instances()
-                        log.debug("Got local boto EC2 connection to %s for region '%s'" % (self.ec2_url,self.ec2_conn.region.name))
+                        log.debug("Got local boto EC2 connection to %s for region '%s'" %
+                                  (self.ec2_url, self.ec2_conn.region.name))
                     except EC2ResponseError, e:
-                        log.error("Cannot validate provided local AWS credentials to %s (A:%s, S:%s): %s" % (self.ec2_url, self.aws_access_key, self.aws_secret_key, e))
+                        log.error("Cannot validate provided local AWS credentials to %s (A:%s, S:%s): %s" % (
+                            self.ec2_url, self.aws_access_key, self.aws_secret_key, e))
                         self.ec2_conn = False
                 except Exception, e:
-                    log.error(e) # to match interface for Ec2Interface
+                    log.error(e)  # to match interface for Ec2Interface
 
             else:
-                super(EucaInterface,self).get_ec2_connection() # default to ec2 connection
+                super(EucaInterface,
+                      self).get_ec2_connection()  # default to ec2 connection
         return self.ec2_conn
 
-
     def get_s3_connection(self):
-        log.debug( 'Getting boto S3 connection' )
+        log.debug('Getting boto S3 connection')
         if self.s3_conn == None:
             log.debug("No S3 Connection, creating a new one.")
             if self.s3_url:
                 host = url.hostname
                 port = url.port
                 path = url.path
-                calling_format=SubdomainCallingFormat()
+                calling_format = SubdomainCallingFormat()
                 if host.find('amazon') == -1:  # assume that non-amazon won't use <bucket>.<hostname> format
-                    calling_format=OrdinaryCallingFormat()
+                    calling_format = OrdinaryCallingFormat()
                 if url.scheme == 'https':
                     is_secure = True
                 else:
                     is_secure = False
                 try:
                     self.s3_conn = S3Connection(
-                        aws_access_key_id = self.aws_access_key,
-                        aws_secret_access_key = self.aws_secret_key,
-                        is_secure = is_secure,
-                        port = port,
-                        host = host,
-                        path = path,
-                        calling_format = calling_format,
+                        aws_access_key_id=self.aws_access_key,
+                        aws_secret_access_key=self.aws_secret_key,
+                        is_secure=is_secure,
+                        port=port,
+                        host=host,
+                        path=path,
+                        calling_format=calling_format,
                         # debug = 2
                     )
                     log.debug('Got boto S3 connection to %s' % self.s3_url)
                 except Exception, e:
                     log.error("Exception getting S3 connection: %s" % e)
-            else: # default to Amazon connection
-                super(EucaInterface,self).get_s3_connection()
+            else:  # default to Amazon connection
+                super(EucaInterface, self).get_s3_connection()
         return self.s3_conn
 
     def get_user_data(self, force=False):
             self.user_data = misc.load_yaml_file(paths.USER_DATA_FILE)
             self.aws_access_key = self.user_data.get('access_key', None)
             self.aws_secret_key = self.user_data.get('secret_key', None)
-            self.s3_url = self.user_data.get('s3_url',None)
-            self.ec2_url = self.user_data.get('ec2_url',None)
+            self.s3_url = self.user_data.get('s3_url', None)
+            self.ec2_url = self.user_data.get('ec2_url', None)
         return self.user_data
 
     def get_local_hostname(self):
-        # Currently, Eucalyptus meta-data/local-hostname returns the IP address, not the hostname. Pull from system hostname instead
-        super(EucaInterface,self).get_local_hostname()
+        # Currently, Eucalyptus meta-data/local-hostname returns the IP
+        # address, not the hostname. Pull from system hostname instead
+        super(EucaInterface, self).get_local_hostname()
         if self.local_hostname:
             toks = self.local_hostname.split('.')
             if len(toks) == 4:
                 r = filter(lambda x: int(x) < 256 and x > 0, toks)
                 if len(r) == 4:
-                    log.debug('local hostname ({0}) appears to be an IP address.'.format(self.local_hostname))
+                    log.debug('local hostname ({0}) appears to be an IP address.'.format(
+                        self.local_hostname))
                     self.local_hostname = None
 
             if not self.local_hostname:
         return self.local_hostname
 
     def get_public_hostname(self):
-        # Eucalyptus meta-data/public-hostname return the IP address. Fake it, assuming that it will be ip-NUM-NUM-NUM-NUM
-        super(EucaInterface,self).get_public_hostname()
+        # Eucalyptus meta-data/public-hostname return the IP address. Fake it,
+        # assuming that it will be ip-NUM-NUM-NUM-NUM
+        super(EucaInterface, self).get_public_hostname()
         if self.public_hostname:
             toks = self.public_hostname.split('.')
             if len(toks) == 4:
                     self.public_hostname = None
 
             if not self.public_hostname:
-                log.debug('Faking local hostname based on IP address {0}'.format('.'.join(toks)))
+                log.debug('Faking local hostname based on IP address {0}'.format(
+                    '.'.join(toks)))
                 self.public_hostname = 'ip-%s' % '-'.join(toks)
         return self.public_hostname
 
     def run_instances(self, num, instance_type, spot_price=None, **kwargs):
         use_spot = False
         if spot_price is not None:
-            log.warning('Eucalyptus does not support spot instances -- submitting normal request')
+            log.warning(
+                'Eucalyptus does not support spot instances -- submitting normal request')
         log.info("Adding {0} instance(s)".format(num))
         if self.app.TESTFLAG is True:
             log.debug("Attempted to start instance(s), but TESTFLAG is set.")
         # log.debug( "Worker user data: %s " % worker_ud )
         if instance_type == '':
             instance_type = self.get_type()
-        self._run_ondemand_instances(num, instance_type, spot_price, worker_ud, min_num=num) # eucalyptus only starts min_num instances
+        self._run_ondemand_instances(num, instance_type, spot_price, worker_ud,
+                                     min_num=num)  # eucalyptus only starts min_num instances
 
-    def get_all_instances(self,instance_ids=None, filters=None):
+    def get_all_instances(self, instance_ids=None, filters=None):
 
-        if isinstance(instance_ids,basestring):
-            instance_ids=(instance_ids,)
+        if isinstance(instance_ids, basestring):
+            instance_ids = (instance_ids,)
             cache_key = instance_ids
         elif instance_ids:
             cache_key = ','.join(instance_ids)
 
         # eucalyptus stops responding if you check the same thing too often
         if self._last_instance_check and cache_key in self._instances and time.time() <= self._last_instance_check + self._min_boto_delay:
-            log.debug('Using cached instance information for {0}'.format(str(instance_ids)))
+            log.debug('Using cached instance information for {0}'.format(
+                str(instance_ids)))
             reservations = self._instances[cache_key]
         else:
-            reservations = self.get_ec2_connection().get_all_instances(instance_ids=instance_ids)
-            # Filter for only reservations that include the filtered instance IDs. Needed because Eucalyptus doesn't filter properly
+            reservations = self.get_ec2_connection(
+            ).get_all_instances(instance_ids=instance_ids)
+            # Filter for only reservations that include the filtered instance
+            # IDs. Needed because Eucalyptus doesn't filter properly
             if instance_ids:
-                reservations = [r for r in reservations if [i for i in r.instances if i.id in instance_ids ] ]
+                reservations = [r for r in reservations if [
+                    i for i in r.instances if i.id in instance_ids]]
             self._instances[cache_key] = reservations
             self._last_instance_check = time.time()
 
                 val = filters[key]
                 if key.startswith('tag:'):
                     tag = key[4:]
-                    if self.get_tag(r.id,tag) != val:
+                    if self.get_tag(r.id, tag) != val:
                         excluded.append(r)
                         continue
                 else:
-                    log.error('Could not filter instance on unknown filter key {0}'.format(key))
-        res = [ i for i in reservations if i not in excluded]
+                    log.error(
+                        'Could not filter instance on unknown filter key {0}'.format(key))
+        res = [i for i in reservations if i not in excluded]
 
         return res
 
-    def get_all_volumes(self,volume_ids=None, filters=None):
+    def get_all_volumes(self, volume_ids=None, filters=None):
         # eucalyptus does not allow filters in get_all_volumes
-        if isinstance(volume_ids,basestring):
+        if isinstance(volume_ids, basestring):
             volume_ids = (volume_ids,)
             cache_key = volume_ids
         elif volume_ids:
         else:
             # need to go this roundabout way to get the volume because euca does not filter the get_all_volumes request by the volume ID,
             # but keep the filter, in case it eventually does
-            volumes = [ v for v in self.get_ec2_connection().get_all_volumes( volume_ids= volume_ids ) if not volume_ids or (v.id in volume_ids) ]
+            volumes = [v for v in self.get_ec2_connection().get_all_volumes(
+                volume_ids=volume_ids) if not volume_ids or (v.id in volume_ids)]
             self._last_volume_check = time.time()
-            self._volumes[cache_key] = volumes # cache returned volumes (for this set of filters)
+            self._volumes[
+                cache_key] = volumes  # cache returned volumes (for this set of filters)
 
         if not filters:
             filters = {}
                 val = filters[key]
                 if key.startswith('tag:'):
                     tag = key[4:]
-                    if self.get_tag(v.id,tag) != val:
-                        # log.debug('(get_all_volumes) Excluding volume {0} because tag {1} != {2}. (is {3})'.format(v.id,tag,val,self.get_tag(v.id,tag)))
+                    if self.get_tag(v.id, tag) != val:
+                        # log.debug('(get_all_volumes) Excluding volume {0}
+                        # because tag {1} != {2}. (is
+                        # {3})'.format(v.id,tag,val,self.get_tag(v.id,tag)))
                         excluded_vols.append(v)
                 elif key == 'attachment.device':
                     if v.attach_data.device != val:
-                        # log.debug('(get_all_volumes) Excluding volume {0} because it is not attached as {1} (is {2})'.format(v.id,val,v.attach_data.device))
+                        # log.debug('(get_all_volumes) Excluding volume {0}
+                        # because it is not attached as {1} (is
+                        # {2})'.format(v.id,val,v.attach_data.device))
                         excluded_vols.append(v)
                 elif key == 'attachment.instance-id':
                     if v.attach_data.instance_id != val:
-                        # log.debug('(get_all_volume) Excluding vol {0} because it is not attached to {1} (is {2})'.format(v.id,val,v.attach_data.instance_id))
+                        # log.debug('(get_all_volume) Excluding vol {0} because
+                        # it is not attached to {1} (is
+                        # {2})'.format(v.id,val,v.attach_data.instance_id))
                         excluded_vols.append(v)
                 else:
-                    log.error('Could not filter on unknown filter key {0}'.format(key))
+                    log.error(
+                        'Could not filter on unknown filter key {0}'.format(key))
         vols = [v for v in volumes if v not in excluded_vols]
         # log.debug("(get_all_volumes) Returning volumes: {0}".format(vols))
         return vols
-

File cm/clouds/opennebula.py

-import urllib, socket
+import urllib
+import socket
 from cm.clouds import CloudInterface
 from cm.services.data.filesystem import Volume
 
 import subprocess
 
 import logging
-log = logging.getLogger( 'cloudman' )
+log = logging.getLogger('cloudman')
+
 
 class ONInterface(CloudInterface):
-    
+
     def __init__(self, aws_access_key=None, aws_secret_key=None, app=None, on_username=None, on_password=None, on_host=None, on_proxy=None):
         super(ONInterface, self).__init__()
         self.app = app
         self.bridge = 72
         self.tags = {}
-    
+
     def set_configuration(self):
         if self.user_data is None:
             self.get_user_data()
         self.on_password = self.user_data.get('on_password', None)
         self.on_host = self.user_data.get('on_host', None)
         self.on_proxy = self.user_data.get('on_proxy', None)
-    
+
     def _getIpAddress(self, ifname):
         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
         try:
             ip = socket.inet_ntoa(fcntl.ioctl(
-                                            s.fileno(),
-                                            0x8915,  # SIOCGIFADDR
-                                            struct.pack('256s', ifname[:15])
-                                            )[20:24])
+                s.fileno(),
+                0x8915,  # SIOCGIFADDR
+                struct.pack('256s', ifname[:15])
+            )[20:24])
         except IOError:
             return None
         return ip
 
     def _getMacAddress(self, ifname):
         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        info = fcntl.ioctl(s.fileno(), 0x8927,  struct.pack('256s', ifname[:15]))
+        info = fcntl.ioctl(
+            s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
         return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
 
-    def get_ami( self ):
+    def get_ami(self):
         pass
-    
-    def get_type( self ):
-        #return 'worker'
+
+    def get_type(self):
+        # return 'worker'
         pass
-    
-    def get_instance_id( self ):
+
+    def get_instance_id(self):
         # There does not exist a method (yet) to get the instance
         # of a running virtual machine
         # The instance is now identified by its MAC address
         # All connected instances are checked if they
-        # match with the current mac address and that VM ID 
+        # match with the current mac address and that VM ID
         # is returned
         mac = self._getMacAddress('eth0')
-        #log.debug(mac)
+        # log.debug(mac)
         vmpool = VirtualMachinePool(self.s3_conn)
         vmpool.info(CONNECTED)
         for vm in list(vmpool):
             if mac in vm_info:
                 return str(vm.id)
         return None
-    
-    def get_zone( self ):
+
+    def get_zone(self):
         pass
-    
-    def get_security_groups( self ):
+
+    def get_security_groups(self):
         pass
-    
-    def get_key_pair_name( self ):
+
+    def get_key_pair_name(self):
         pass
-    
-    def get_private_ip( self ):
+
+    def get_private_ip(self):
         # TODO: Change this to the masters IP
         log.debug("Asking for private IP")
         return self._getIpAddress('eth1')
-    
-    def get_public_ip( self ):
+
+    def get_public_ip(self):
         # TODO: Change this to the masters IP
         log.debug("Asking for public IP")
         return self._getIpAddress('eth0')
-    
+
     def get_fqdn(self):
         # Return the hostname
         return socket.getfqdn()
-    
-    def get_ec2_connection( self ):
-        log.debug( 'Getting OpenNebula connection' )
+
+    def get_ec2_connection(self):
+        log.debug('Getting OpenNebula connection')
         if self.ec2_conn == None:
             log.debug("No OpenNebula Connection, creating a new one.")
             try:
-                self.ec2_conn = Client("%s:%s" % (self.on_username, self.on_password), self.on_host, self.on_proxy)
-                self.ec2_conn.lookup = new.instancemethod(lookup, self.ec2_conn, self.ec2_conn.__class__)
-                self.ec2_conn.create_bucket = new.instancemethod(create_bucket, self.ec2_conn, self.ec2_conn.__class__)
+                self.ec2_conn = Client("%s:%s" % (
+                    self.on_username, self.on_password), self.on_host, self.on_proxy)
+                self.ec2_conn.lookup = new.instancemethod(
+                    lookup, self.ec2_conn, self.ec2_conn.__class__)
+                self.ec2_conn.create_bucket = new.instancemethod(
+                    create_bucket, self.ec2_conn, self.ec2_conn.__class__)
 
                 try:
-                     vmpool = VirtualMachinePool(self.ec2_conn)
-                     vmpool.info(CONNECTED)
-                     list(vmpool)
-                     log.debug( 'Got OpenNebula connection.' )
+                    vmpool = VirtualMachinePool(self.ec2_conn)
+                    vmpool.info(CONNECTED)
+                    list(vmpool)
+                    log.debug('Got OpenNebula connection.')
                 except OpenNebulaException, e:
-                     log.error("Cannot validate provided credentials: %s" % e)
-                     self.ec2_conn = False
+                    log.error("Cannot validate provided credentials: %s" % e)
+                    self.ec2_conn = False
             except Exception, e:
                 log.error(e)
         return self
-    
-    def get_s3_connection( self ):
-        #Note: S3 = storage (bucket)
-        #Opennebula cloud has no storage
-        log.debug( 'Getting OpenNebula connection' )
+
+    def get_s3_connection(self):
+        # Note: S3 = storage (bucket)
+        # Opennebula cloud has no storage
+        log.debug('Getting OpenNebula connection')
         if self.s3_conn == None:
             log.debug("No OpenNebula Connection, creating a new one.")
             try:
-                self.s3_conn = Client("%s:%s" % (self.on_username, self.on_password), self.on_host, self.on_proxy)
-                self.s3_conn.lookup = new.instancemethod(lookup, self.s3_conn, self.s3_conn.__class__)
-                self.s3_conn.create_bucket = new.instancemethod(create_bucket, self.s3_conn, self.s3_conn.__class__)
- 
-                           
+                self.s3_conn = Client("%s:%s" % (
+                    self.on_username, self.on_password), self.on_host, self.on_proxy)
+                self.s3_conn.lookup = new.instancemethod(
+                    lookup, self.s3_conn, self.s3_conn.__class__)
+                self.s3_conn.create_bucket = new.instancemethod(
+                    create_bucket, self.s3_conn, self.s3_conn.__class__)
+
                 try:
-                     vmpool = VirtualMachinePool(self.s3_conn)
-                     vmpool.info(CONNECTED)
-                     list(vmpool)
-                     log.debug( 'Got OpenNebula connection.' )
+                    vmpool = VirtualMachinePool(self.s3_conn)
+                    vmpool.info(CONNECTED)
+                    list(vmpool)
+                    log.debug('Got OpenNebula connection.')
                 except OpenNebulaException, e:
-                     log.error("Cannot validate provided credentials: %s" % e)
-                     self.s3_conn = False
+                    log.error("Cannot validate provided credentials: %s" % e)
+                    self.s3_conn = False
             except socket.error, e:
-                log.debug( "Socket error: %s:" % e )
+                log.debug("Socket error: %s:" % e)
                 log.debug("Trying to reboot the machine")
                 # It should be prevented that its reboot on a local machine (kvm)
                 # local machine hwaddr = 00:22:64:ae:3d:fd
                 # TODO
                 if self._getMacAddress('eth0') != '00:22:64:ae:3d:fd':
-                #if int(self.get_private_ip().split('.')[2]) == int(self.bridge):
-                    ret_code = subprocess.call( 'sudo telinit 6', shell=True )
+                # if int(self.get_private_ip().split('.')[2]) ==
+                # int(self.bridge):
+                    ret_code = subprocess.call('sudo telinit 6', shell=True)
 
-                
             except Exception, e:
                 log.error(e)
         return self.s3_conn
-        #return None
-    
+        # return None
+
     def run_instances(self, num, instance_type, **kwargs):
 
-        #TODO: Change this!!
+        # TODO: Change this!!
         username = 'mdhollander'
         diskimage = 'vm-lucid-amd64-serial-galaxy-worker.img'
         vmname = "Cloudman_Node"
-        
+
         log.debug("Adding {0} OpenNebula Worker nodes".format(num))
         # TODO: Remove public NIC? Save disk?
 #        vmtemplatestring ="""
-#NAME=\"%s\" MEMORY=1024 CPU=1 OS=[BOOT=\"hd\"] 
-#GRAPHICS=[type=\"vnc\"] 
-#DISK=[TYPE=\"disk\", SOURCE=\"/home/%s/images/%s\", TARGET=\"hda\", CLONE=\"yes\", SAVE=\"no\", READONLY=\"n\" ]
-#NIC=[NETWORK=\"%s\", MODEL=\"virtio\"]
-#NIC=[NETWORK=\"public\", MODEL=\"virtio\"]
+# NAME=\"%s\" MEMORY=1024 CPU=1 OS=[BOOT=\"hd\"]
+# GRAPHICS=[type=\"vnc\"]
+# DISK=[TYPE=\"disk\", SOURCE=\"/home/%s/images/%s\", TARGET=\"hda\", CLONE=\"yes\", SAVE=\"no\", READONLY=\"n\" ]
+# NIC=[NETWORK=\"%s\", MODEL=\"virtio\"]
+# NIC=[NETWORK=\"public\", MODEL=\"virtio\"]
 #""" % (vmname, username, diskimage, username)
 
         vmtemplatestring = """
 VCPU=1
 """
         r = Reservations()
-        for i in range(1,num+1):
+        for i in range(1, num + 1):
             new_vm_id = VirtualMachine.allocate(self.s3_conn, vmtemplatestring)
-            
+
             # Get the just initiated instances
             # TODO: Is there another way to retrieve it? Using new_vm_id?
             vmpool = VirtualMachinePool(self.s3_conn)
             vmpool.info(CONNECTED)
             vm_instance = list(vmpool)[-1]
-            
-            vm_instance.add_tag = new.instancemethod(add_tag, vm_instance, vm_instance.__class__)
-            vm_instance.update = new.instancemethod(update, vm_instance, vm_instance.__class__)
 
-            #vm_instance.id = str(vm_instance.id)
-            
+            vm_instance.add_tag = new.instancemethod(
+                add_tag, vm_instance, vm_instance.__class__)
+            vm_instance.update = new.instancemethod(
+                update, vm_instance, vm_instance.__class__)
+
+            # vm_instance.id = str(vm_instance.id)
+
             # Add tags dictionary
             vm_instance.tags = {}
 
             r.instances.append(vm_instance)
-        
+
         return r
 
 # Emulate EC2 objects
 
     def get_all_instances(self, filters={}, *args, **kwargs):
-        client = Client("%s:%s" % (self.on_username, self.on_password), self.on_host, self.on_proxy)
+        client = Client("%s:%s" % (
+            self.on_username, self.on_password), self.on_host, self.on_proxy)
         vmpool = VirtualMachinePool(client)
         vmpool.info(CONNECTED)
         reservations = []
         log.debug("Get all instances")
-        
+
         for vm_instance in vmpool:
             # Make a distinction between worker and the master node
             # The workers nodes have a role defined as worker (dictionary)
             # The master node has a empty list as filter string
-            
+
             # Instance ID needs to be a string
             vm_instance.id = str(vm_instance.id)
-            
+
             # Hold tags in a dictionary
             vm_instance.tags = {}
             try:
                 if int(req_id) == int(vm_instance.id):
                     reservations = []
                     r = Reservations()
-                    vm_instance.add_tag = new.instancemethod(add_tag, vm_instance, vm_instance.__class__)
-                    vm_instance.update = new.instancemethod(update, vm_instance, vm_instance.__class__)
+                    vm_instance.add_tag = new.instancemethod(
+                        add_tag, vm_instance, vm_instance.__class__)
+                    vm_instance.update = new.instancemethod(
+                        update, vm_instance, vm_instance.__class__)
                     r.instances.append(vm_instance)
                     reservations.append(r)
                     return reservations
             except:
                 pass
-            # TODO Add tags to instance? (unsure if this it the right way to do it)
+            # TODO Add tags to instance? (unsure if this it the right way to do
+            # it)
             try:
                 for key, value in filters.iteritems():
                     tag = key.split(':')[1]
                     vm_instance.tags[tag] = value
             except AttributeError:
                 pass
-            
+
             try:
-                role = filters['tag:role'] 
+                role = filters['tag:role']
                 if role == "worker" and vm_instance.name.strip() == "Cloudman_Node":
                     r = Reservations()
-                    vm_instance.add_tag = new.instancemethod(add_tag, vm_instance, vm_instance.__class__)
-                    vm_instance.update = new.instancemethod(update, vm_instance, vm_instance.__class__)
-                    #vm_instance.get_m_state = get_m_state
-                    
+                    vm_instance.add_tag = new.instancemethod(
+                        add_tag, vm_instance, vm_instance.__class__)
+                    vm_instance.update = new.instancemethod(
+                        update, vm_instance, vm_instance.__class__)
+                    # vm_instance.get_m_state = get_m_state
+
                     r.instances.append(vm_instance)
                     reservations.append(r)
-            except TypeError :
+            except TypeError:
                 # TODO: don't hardcode the name of the master instance
-                #if vm_instance.name.strip() == "Galaxy_Main":
+                # if vm_instance.name.strip() == "Galaxy_Main":
                 if vm_instance.name.strip() == "one-1592":
                     r = Reservations()
-                    vm_instance.add_tag = new.instancemethod(add_tag, vm_instance, vm_instance.__class__)
-                    vm_instance.update = new.instancemethod(update, vm_instance, vm_instance.__class__)
+                    vm_instance.add_tag = new.instancemethod(
+                        add_tag, vm_instance, vm_instance.__class__)
+                    vm_instance.update = new.instancemethod(
+                        update, vm_instance, vm_instance.__class__)
                     r.instances.append(vm_instance)
                     reservations.append(r)
-                    
+
         return reservations
 
     def get_all_volumes(self, *args, **kwargs):
         pass
-    
+
     def terminate_instances(self, instances):
         log.debug("Terminate instances")
-        
+
         return True
 
     def reboot_instances(self, instances, *args, **kwargs):
                         log.debug("rebooting")
                         vm_instance.resume()
                         return True
-                    
+
     # EC2 can add volumes to a image
     # For ON we will create a filesystem
     # Call: Filesystem.add
 
     def add_tag(self, key, value, *args, **kwargs):
         self.tags[key] = value
-        
+
+
 class Reservations(object):
     def __init__(self):
         self.instances = []
 
 # A EC2 instance object has a add_tag method
 # which is lacking in the OpenNebula object
+
+
 def add_tag(self, key, value, *args, **kwargs):
     self.tags[key] = value
 
+
 def update(self):
     """Should update instance"""
     log.debug("Trying to update")
     log.debug("Instance id: %s" % self.id)
 
 
-
-#def get_m_state(self):
+# def get_m_state(self):
 #    print "GET M STATE"
 #    print self.state
-
-#TODO: Work on Bucket System!!
+# TODO: Work on Bucket System!!
 # A EC2 connection object has lookup method
 # which is lacking in the oca Client object
 def lookup(self, *args, **kwargs):
     pass
 
+
 def create_bucket(self, *args, **kwargs):
     pass

File cm/clouds/openstack.py

         self.s3_conn_path = self.user_data.get('s3_conn_path', None)
         self.calling_format = OrdinaryCallingFormat()
 
-    def get_ec2_connection( self ):
+    def get_ec2_connection(self):
         if self.ec2_conn == None:
             try:
                 if self.app.TESTFLAG is True:
-                    log.debug("Attempted to establish Nova connection, but TESTFLAG is set. " \
+                    log.debug("Attempted to establish Nova connection, but TESTFLAG is set. "
                               "Returning a default connection.")
                     self.ec2_conn = self._get_default_ec2_conn()
                     return self.ec2_conn
                 # Do a simple query to test if provided credentials are valid
                 try:
                     self.ec2_conn.get_all_instances()
-                    log.debug("Got boto Nova connection for region {0}".format(self.ec2_conn.region.name))
+                    log.debug("Got boto Nova connection for region {0}".format(
+                        self.ec2_conn.region.name))
                 except EC2ResponseError, e:
-                    log.error("Cannot validate provided OpenStack credentials or configuration " \
+                    log.error("Cannot validate provided OpenStack credentials or configuration "
                               "(AK:{0}, SK:{1}): {2}".format(self.aws_access_key, self.aws_secret_key, e))
                     self.ec2_conn = None
             except Exception, e:
         ec2_conn = None
         try:
             if region is None:
-                region = RegionInfo(name=self.region_name, endpoint=self.region_endpoint)
+                region = RegionInfo(
+                    name=self.region_name, endpoint=self.region_endpoint)
             ec2_conn = boto.connect_ec2(aws_access_key_id=self.aws_access_key,
                                         aws_secret_access_key=self.aws_secret_key,
                                         is_secure=self.is_secure,
                                         region=region,
                                         port=self.ec2_port,
                                         path=self.ec2_conn_path,
-                                        validate_certs=False) # https://github.com/boto/boto/wiki/2.6.0-release-notes
+                                        validate_certs=False)  # https://github.com/boto/boto/wiki/2.6.0-release-notes
         except EC2ResponseError, e:
             log.error("Trouble creating a Nova connection: {0}".format(e))
         return ec2_conn
         if self.s3_conn == None:
             log.debug("Establishing a boto Swift connection.")
             try:
-                self.s3_conn = boto.connect_s3(aws_access_key_id=self.aws_access_key,
-                                               aws_secret_access_key=self.aws_secret_key,
-                                               is_secure=self.is_secure,
-                                               host=self.s3_host,
-                                               port=self.s3_port,
-                                               path=self.s3_conn_path,