Revision 675
Added by Borja Sotomayor over 14 years ago
trunk/src/haizea/cli/commands.py | ||
---|---|---|
24 | 24 |
from haizea.cli.optionparser import Option |
25 | 25 |
from haizea.cli import Command |
26 | 26 |
from mx.DateTime import TimeDelta |
27 |
import xml.etree.ElementTree as ET |
|
28 | 27 |
import haizea.common.defaults as defaults |
29 | 28 |
import sys |
30 | 29 |
import os |
... | ... | |
32 | 31 |
import signal |
33 | 32 |
from time import sleep |
34 | 33 |
|
34 |
try: |
|
35 |
import xml.etree.ElementTree as ET |
|
36 |
except ImportError: |
|
37 |
# Compatibility with Python <=2.4 |
|
38 |
import elementtree.ElementTree as ET |
|
35 | 39 |
|
40 |
|
|
36 | 41 |
class haizea(Command): |
37 | 42 |
""" |
38 | 43 |
This is the main Haizea command. By default, it will start Haizea as a daemon, which |
trunk/src/haizea/cli/rpc_commands.py | ||
---|---|---|
24 | 24 |
import xmlrpclib |
25 | 25 |
import sys |
26 | 26 |
from mx.DateTime import ISO, now, DateTimeDelta, Parser |
27 |
import xml.etree.ElementTree as ET |
|
28 | 27 |
|
28 |
try: |
|
29 |
import xml.etree.ElementTree as ET |
|
30 |
except ImportError: |
|
31 |
# Compatibility with Python <=2.4 |
|
32 |
import elementtree.ElementTree as ET |
|
33 |
|
|
29 | 34 |
class RPCCommand(Command): |
30 | 35 |
def __init__(self, argv): |
31 | 36 |
Command.__init__(self, argv) |
trunk/src/haizea/common/opennebula_xmlrpc.py | ||
---|---|---|
1 | 1 |
import xmlrpclib |
2 | 2 |
import os |
3 | 3 |
import hashlib |
4 |
import xml.etree.ElementTree as ET |
|
5 | 4 |
|
5 |
try: |
|
6 |
import xml.etree.ElementTree as ET |
|
7 |
except ImportError: |
|
8 |
# Compatibility with Python <=2.4 |
|
9 |
import elementtree.ElementTree as ET |
|
10 |
|
|
6 | 11 |
class OpenNebulaXMLRPCClient(object): |
7 | 12 |
def __init__(self, host, port, user, password): |
8 | 13 |
uri = "http://%s:%i" % (host, port) |
trunk/src/haizea/common/utils.py | ||
---|---|---|
107 | 107 |
fq_name = fq_name.split(".") |
108 | 108 |
package_name = ".".join(fq_name[:-1]) |
109 | 109 |
class_name = fq_name[-1] |
110 |
module = __import__(package_name, fromlist=[class_name])
|
|
110 |
module = __import__(package_name, globals(), locals(), [class_name])
|
|
111 | 111 |
exec("cls = module.%s" % class_name) |
112 | 112 |
return cls |
113 | 113 |
|
trunk/src/haizea/core/manager.py | ||
---|---|---|
277 | 277 |
handler = logging.FileHandler(self.config.get("logfile")) |
278 | 278 |
else: |
279 | 279 |
handler = logging.StreamHandler() |
280 |
formatter = logging.Formatter('[%(haizeatime)s] %(name)-7s %(message)s') |
|
280 |
if sys.version_info[1] <= 4: |
|
281 |
formatter = logging.Formatter('%(name)-7s %(message)s') |
|
282 |
else: |
|
283 |
formatter = logging.Formatter('[%(haizeatime)s] %(name)-7s %(message)s') |
|
281 | 284 |
handler.setFormatter(formatter) |
282 | 285 |
logger.addHandler(handler) |
283 | 286 |
level = logging.getLevelName(self.config.get("loglevel")) |
trunk/src/haizea/core/leases.py | ||
---|---|---|
40 | 40 |
from mx.DateTime import DateTime, TimeDelta, Parser |
41 | 41 |
|
42 | 42 |
import logging |
43 |
import xml.etree.ElementTree as ET |
|
44 | 43 |
|
44 |
try: |
|
45 |
import xml.etree.ElementTree as ET |
|
46 |
except ImportError: |
|
47 |
# Compatibility with Python <=2.4 |
|
48 |
import elementtree.ElementTree as ET |
|
45 | 49 |
|
46 | 50 |
|
47 | 51 |
|
52 |
|
|
48 | 53 |
class Lease(object): |
49 | 54 |
"""A resource lease |
50 | 55 |
|
trunk/src/haizea/core/log.py | ||
---|---|---|
17 | 17 |
# -------------------------------------------------------------------------- # |
18 | 18 |
|
19 | 19 |
import logging |
20 |
import sys |
|
20 | 21 |
from haizea.common.utils import get_clock |
21 | 22 |
from haizea.common.constants import LOGLEVEL_VDEBUG, LOGLEVEL_STATUS |
22 | 23 |
|
... | ... | |
26 | 27 |
# Custom logger that uses our log record |
27 | 28 |
class HaizeaLogger(logging.Logger): |
28 | 29 |
|
29 |
def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra):
|
|
30 |
def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func=None, extra=None):
|
|
30 | 31 |
# Modify "extra" parameter keyword |
31 | 32 |
try: |
32 | 33 |
haizeatime = get_clock().get_time() |
33 |
extra = { "haizeatime" : haizeatime} |
|
34 | 34 |
except: |
35 | 35 |
# This is a kludge. Basically, calling get_clock will |
36 | 36 |
# fail if Manager is not yet fully constructed (since it's |
... | ... | |
38 | 38 |
# separate the initialization code in the Manager from the |
39 | 39 |
# initialization that actually involves interacting with |
40 | 40 |
# other components (which may want to use the logger) |
41 |
extra = { "haizeatime" : " "} |
|
42 |
return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra) |
|
41 |
haizeatime = " " |
|
42 |
extra = { "haizeatime" : haizeatime} |
|
43 |
if sys.version_info[1] <= 4: |
|
44 |
name = "[%s] %s" % (haizeatime, name) |
|
45 |
return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info) |
|
46 |
else: |
|
47 |
return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra) |
|
43 | 48 |
|
44 | 49 |
def status(self, msg): |
45 | 50 |
self.log(logging.getLevelName("STATUS"), msg) |
Also available in: Unified diff
A few minor changes so Haizea will work with Python 2.4