Permalink
Browse files

Coding style

  • Loading branch information...
CyrilPeponnet committed Mar 25, 2016
1 parent d025aed commit ec9c6c68f46ccd87907a4f781a8ee403d42850b7
@@ -25,10 +25,3 @@
#
[MODULES]
centraldb = True
#
# CENTRALDB module configuration
#
[CENTRALDB]
# jid (without domain) of the central agent
central_agent_jid = centralagent@%(xmpp_server)s
@@ -24,7 +24,7 @@ import sys
import socket
import signal as sig
## Error codes
# Error codes
ARCHIPEL_INIT_SUCCESS = 0
ARCHIPEL_INIT_ERROR_NO_CONFIG = 1
ARCHIPEL_INIT_ERROR_NO_MODULE = 2
@@ -36,14 +36,14 @@ ARCHIPEL_INIT_ERROR_STATELESS_MODE = 7
# Import and check essential modules
try:
from archipelcore.scriptutils import error, msg, success
from archipelcore.scriptutils import error
except ImportError as ex:
print "FATAL: you need to install archipel-core"
sys.exit(ARCHIPEL_INIT_ERROR_NO_MODULE)
try:
from archipelcore.utils import init_log
from archipelcore.runutils import format_version, versions, initialize_config
from archipelcore.runutils import versions, initialize_config
from archipel.archipelHypervisor import TNArchipelHypervisor
from archipel.libvirtEventLoop import virEventLoopNativeStart
from archipelcore import xmpp
@@ -51,6 +51,7 @@
log = logging.getLogger('archipel')
class TNArchipelLogger:
"""
archipel logger implt
@@ -73,7 +74,7 @@ def __log(self, level, msg):
elif level == ARCHIPEL_LOG_WARNING:
log.warning(msg)
elif level == ARCHIPEL_LOG_ERROR:
log.error(msg)
log.error(msg)
# if self.xmppclient and self.pubSubNode:
# log = xmpp.Node(tag="log", attrs={"date": datetime.datetime.now(), "level": str(level)})
@@ -122,17 +123,18 @@ def init_conf(paths):
conf.read(paths)
if conf.has_option("GLOBAL", "modules_configuration_path"):
plugins_path = conf.get("GLOBAL", "modules_configuration_path")
plugins_conf = glob.glob(plugins_path+"/*.conf")
plugins_conf = glob.glob(plugins_path + "/*.conf")
conf.read(plugins_conf)
for section in conf.sections():
for option in conf.options(section):
value = conf.get(section, option, raw=True)
if (not value):
raise Exception("Missing value for option %s in section [%s]" %(option,section))
raise Exception("Missing value for option %s in section [%s]" % (option,section))
value = value.replace("@HOSTNAME@", socket.gethostname())
conf.set(section, "%s" % option, value)
return conf
def init_log(conf):
"""
Initialize the logger
@@ -162,8 +164,8 @@ def init_log(conf):
logger.addHandler(handler)
logger.setLevel(level)
def build_error_iq(originclass, ex, iq, code=-1, ns=ARCHIPEL_NS_GENERIC_ERROR):
#traceback.print_exc(file=sys.stdout, limit=20)
caller = inspect.stack()[1][3]
log.error("%s.%s: exception raised is: '%s' triggered by stanza :\n%s" % (originclass, caller, ex, str(iq)))
t, v, tr = sys.exc_info()
@@ -183,11 +185,13 @@ def build_error_iq(originclass, ex, iq, code=-1, ns=ARCHIPEL_NS_GENERIC_ERROR):
reply.addChild(node=error)
return reply
def build_error_message(originclass, ex, msg):
caller = inspect.stack()[3][3]
log.error("%s: exception raised is: '%s' triggered by message:\n %s" % (caller, str(ex), str(msg)))
return str(ex)
def get_default_gateway_interface():
"""
Reads the ip address of default gateway interface
@@ -200,6 +204,7 @@ def get_default_gateway_interface():
return get_ip_address(fields[0])
def get_ip_address(ifname):
"""
Returns the IP address associated with the given interface

0 comments on commit ec9c6c6

Please sign in to comment.