Skip to content

Commit

Permalink
Start py3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Dec 20, 2016
1 parent a25c58d commit 005be83
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 34 deletions.
22 changes: 11 additions & 11 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))

Expand Down
15 changes: 6 additions & 9 deletions IM/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import ConfigParser
import configparser
import os
import logging

Expand All @@ -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(
Expand Down Expand Up @@ -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'])

Expand Down
14 changes: 7 additions & 7 deletions IM/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions im_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)

0 comments on commit 005be83

Please sign in to comment.