diff --git a/IM/InfrastructureManager.py b/IM/InfrastructureManager.py index ed1d80fa8..32e93f14d 100755 --- a/IM/InfrastructureManager.py +++ b/IM/InfrastructureManager.py @@ -186,7 +186,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c "Launching %d VMs of type %s" % (remain_vm, concrete_system.name)) launched_vms = cloud.cloud.getCloudConnector().launch( sel_inf, launch_radl, requested_radl, remain_vm, auth) - except Exception, e: + except Exception as e: InfrastructureManager.logger.exception("Error launching some of the VMs: %s" % e) exceptions.append("Error launching the VMs of type %s to cloud ID %s" " of type %s. Cloud Provider Error: %s" % (concrete_system.name, @@ -525,7 +525,7 @@ def AddResource(inf_id, radl_data, auth, context=True, failed_clouds=[]): InfrastructureManager._launch_group(sel_inf, ds, deploys_group_cloud_list[id(ds)], cloud_list, concrete_systems, radl, auth, deployed_vm, cancel_deployment) - except Exception, e: + except Exception as e: # Please, avoid exception to arrive to this level, because some virtual # machine may lost. cancel_deployment.append(e) @@ -620,7 +620,7 @@ def RemoveResource(inf_id, vm_list, auth, context=True): cont += 1 else: exceptions.append(msg) - except Exception, e: + except Exception as e: exceptions.append(e) IM.InfrastructureList.InfrastructureList.save_data(inf_id) @@ -748,7 +748,7 @@ def AlterVM(inf_id, vm_id, radl_data, auth): exception = None try: (success, alter_res) = vm.alter(radl, auth) - except Exception, e: + except Exception as e: exception = e if exception: @@ -908,7 +908,7 @@ def _stop_vm(vm, auth, exceptions): success = False InfrastructureManager.logger.debug("Stopping the VM id: " + vm.id) (success, msg) = vm.stop(auth) - except Exception, e: + except Exception as e: msg = str(e) if not success: InfrastructureManager.logger.info("The VM cannot be stopped") @@ -961,7 +961,7 @@ def _start_vm(vm, auth, exceptions): success = False InfrastructureManager.logger.debug("Starting the VM id: " + vm.id) (success, msg) = vm.start(auth) - except Exception, e: + except Exception as e: msg = str(e) if not success: InfrastructureManager.logger.info("The VM cannot be restarted") @@ -1030,7 +1030,7 @@ def StartVM(inf_id, vm_id, auth): success = False try: (success, msg) = vm.start(auth) - except Exception, e: + except Exception as e: msg = str(e) if not success: @@ -1065,7 +1065,7 @@ def StopVM(inf_id, vm_id, auth): success = False try: (success, msg) = vm.stop(auth) - except Exception, e: + except Exception as e: msg = str(e) if not success: @@ -1084,7 +1084,7 @@ def _delete_vm(vm, auth, exceptions): InfrastructureManager.logger.debug( "Finalizing the VM id: " + str(vm.id)) (success, msg) = vm.finalize(auth) - except Exception, e: + except Exception as e: msg = str(e) if not success: InfrastructureManager.logger.info("The VM cannot be finalized") @@ -1216,7 +1216,7 @@ def CreateInfrastructure(radl, auth): # Add the resources in radl_data try: InfrastructureManager.AddResource(inf.id, radl, auth) - except Exception, e: + except Exception as e: InfrastructureManager.logger.exception( "Error Creating Inf id " + str(inf.id)) inf.delete() @@ -1278,7 +1278,7 @@ def ImportInfrastructure(str_inf, auth_data): try: new_inf = IM.InfrastructureInfo.InfrastructureInfo.deserialize(str_inf) - except Exception, ex: + except Exception as ex: InfrastructureManager.logger.exception("Error importing the infrastructure, incorrect data") raise Exception("Error importing the infrastructure, incorrect data: " + str(ex)) diff --git a/IM/config.py b/IM/config.py index 66e05d04c..0d4dde0a2 100644 --- a/IM/config.py +++ b/IM/config.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import ConfigParser +import configparser import os import logging @@ -25,17 +25,14 @@ def parse_options(config, section_name, config_class): option = option.upper() if option in config_class.__dict__ and not option.startswith("__"): if isinstance(config_class.__dict__[option], bool): - config_class.__dict__[option] = config.getboolean( - section_name, option) + setattr(config_class, option, config.getboolean(section_name, option)) elif isinstance(config_class.__dict__[option], int): - config_class.__dict__[option] = config.getint( - section_name, option) + setattr(config_class, option, config.getint(section_name, option)) elif isinstance(config_class.__dict__[option], list): str_value = config.get(section_name, option) - config_class.__dict__[option] = str_value.split(',') + setattr(config_class, option, str_value.split(',')) else: - config_class.__dict__[option] = config.get( - section_name, option) + setattr(config_class, option, config.get(section_name, option)) else: logger = logging.getLogger('InfrastructureManager') logger.warn( @@ -91,7 +88,7 @@ class Config: UPDATE_CTXT_LOG_INTERVAL = 20 ANSIBLE_INSTALL_TIMEOUT = 900 -config = ConfigParser.ConfigParser() +config = configparser.ConfigParser() config.read([Config.IM_PATH + '/../im.cfg', Config.IM_PATH + '/../etc/im.cfg', '/etc/im/im.cfg']) diff --git a/IM/request.py b/IM/request.py index 554771b59..c65d3ee56 100644 --- a/IM/request.py +++ b/IM/request.py @@ -15,13 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys -from Queue import Queue, Empty +from queue import Queue, Empty import threading -from SimpleXMLRPCServer import SimpleXMLRPCServer -import SocketServer +from xmlrpc.server import SimpleXMLRPCServer +import socketserver import time -from timedcall import TimedCall -from config import Config +from IM.timedcall import TimedCall +from IM.config import Config class RequestQueue(Queue): @@ -248,7 +248,7 @@ def process(self): self.__thread.start() -class AsyncXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer): +class AsyncXMLRPCServer(socketserver.ThreadingMixIn, SimpleXMLRPCServer): def serve_forever_in_thread(self): """ @@ -266,7 +266,7 @@ def serve_forever_in_thread(self): if Config.XMLRCP_SSL: from springpython.remoting.xmlrpc import SSLServer - class AsyncSSLXMLRPCServer(SocketServer.ThreadingMixIn, SSLServer): + class AsyncSSLXMLRPCServer(socketserver.ThreadingMixIn, SSLServer): def __init__(self, *args, **kwargs): super(AsyncSSLXMLRPCServer, self).__init__(*args, **kwargs) diff --git a/im_service.py b/im_service.py index 37a6a0050..c50ef05ca 100755 --- a/im_service.py +++ b/im_service.py @@ -33,7 +33,7 @@ from IM import __version__ as version if sys.version_info <= (2, 6): - print "Must use python 2.6 or greater" + print("Must use python 2.6 or greater") sys.exit(1) logger = logging.getLogger('InfrastructureManager') @@ -253,8 +253,8 @@ def config_logging(): try: # First look at /etc/im/logging.conf file logging.config.fileConfig('/etc/im/logging.conf') - except Exception, ex: - print ex + except Exception as ex: + print(ex) log_dir = os.path.dirname(Config.LOG_FILE) if not os.path.isdir(log_dir): os.makedirs(log_dir) @@ -296,8 +296,8 @@ def config_logging(): log.addFilter(filt) log = logging.getLogger('InfrastructureManager') log.addFilter(filt) - except Exception, ex: - print ex + except Exception as ex: + print(ex) def im_stop(): diff --git a/setup.py b/setup.py index 23c991a09..5b01f0ff2 100644 --- a/setup.py +++ b/setup.py @@ -55,8 +55,8 @@ "the user with a fully functional infrastructure."), description="IM is a tool to manage virtual infrastructures on Cloud deployments", platforms=["any"], - install_requires=["ansible >= 1.8", "paramiko >= 1.14", "PyYAML", "suds", + install_requires=["ansible >= 1.8", "paramiko >= 1.14", "PyYAML", "suds-py3", "boto >= 2.29", "apache-libcloud >= 0.17", "RADL", "bottle", "netaddr", "requests", - "scp", "cherrypy", "MySQL-python", "pysqlite", + "scp", "cherrypy", "mysqlclient", "azure-mgmt-storage", "azure-mgmt-compute", "azure-mgmt-network", "azure-mgmt-resource"] )