X-Git-Url: http://git.onelab.eu/?p=mom.git;a=blobdiff_plain;f=pl_mom.py;h=ad7559f8033df25e699a68b3a8a0f2136f097800;hp=532dfd54bf5f443816d94a1bcfde589024ed8b83;hb=a7ab53cbaf3037b67fbda98fed3887c905d93e96;hpb=ecd1bafa033312db81872294a5bf099177952821 diff --git a/pl_mom.py b/pl_mom.py index 532dfd5..ad7559f 100644 --- a/pl_mom.py +++ b/pl_mom.py @@ -5,8 +5,6 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ -# import os import sys @@ -23,8 +21,8 @@ except: print "Warning: Configuration file /etc/planetlab/plc_config.py not found" PLC_NAME = "PlanetLab" PLC_SLICE_PREFIX = "pl" - PLC_MAIL_SUPPORT_ADDRESS = "support@planet-lab.org" - PLC_MAIL_SLICE_ADDRESS = "SLICE@slices.planet-lab.org" + PLC_MAIL_SUPPORT_ADDRESS = "root@" + socket.gethostname() + PLC_MAIL_SLICE_ADDRESS = "SLICE@" + socket.gethostname() def format_bytes(bytes, si = True): """ @@ -86,13 +84,9 @@ def removepid(prog): os.unlink("/var/run/%s.pid" % prog) def slicemail(slice, subject, body): - sendmail = os.popen("/usr/sbin/sendmail -t -f%s" % PLC_MAIL_SUPPORT_ADDRESS, "w") + sendmail = os.popen("/usr/sbin/sendmail -N never -t -f%s" % PLC_MAIL_SUPPORT_ADDRESS, "w") - # PLC has a separate list for pl_mom messages - if PLC_MAIL_SUPPORT_ADDRESS == "support@planet-lab.org": - to = ["pl-mom@planet-lab.org"] - else: - to = [PLC_MAIL_SUPPORT_ADDRESS] + to = [PLC_MAIL_MOM_LIST_ADDRESS] if slice is not None and slice != "root": to.append(PLC_MAIL_SLICE_ADDRESS.replace("SLICE", slice)) @@ -167,11 +161,10 @@ class NM: Simple interface to local Node Manager API """ - def __init__(self, url = "http://localhost:812/", timeout = 10): + def __init__(self, url = "http://localhost:812/", timeout = 30): """ Open a new connection to the local Node Manager """ - socket.setdefaulttimeout(timeout) try: self.nm = xmlrpclib.ServerProxy(url) @@ -179,42 +172,23 @@ class NM: print "Warning: Exception received while opening connection to Node Manager:", err self.nm = None - def close(self): - """ - Close connection to the local Node Manager - """ - - if self.nm is not None: - self.nm.close() - def query(self, slice, attributes): """ Get values of various slice attributes from the local Node Manager slice - slice name - attributes - [attribute_name, (attribute_name, return_value_if_not_set), ...] + attributes - [(attribute_name, return_value_if_not_set), ...] """ - values = [None for attribute in attributes] + values = [attribute[1] for attribute in attributes] if self.nm is not None: - try: - # Read rspec (the NM hash code for the slice) + # Read rspec (the NM hash code for the slice) rcap = open("/var/run/pl_nm/%s.vm_rcap" % slice, "r") rspec = rcap.readline().strip() rcap.close() - for i, attribute in enumerate(attributes): - # NM interface allows you to pass in a tuple - # (attribute, default) instead of just an - # attribute name. default is returned if the - # attribute is not set. - if type(attribute) != tuple: - attribute = (attribute, 0) - (rc, (value,)) = self.nm.nm_inspect(rspec, [attribute]) - if rc == 0 and value != attribute[1]: - values[i] = value - except Exception, err: - print "Warning: Exception received while querying Node Manager:", err - + (rc, result) = self.nm.nm_inspect(rspec, attributes) + if rc == 0 and type(result) == list and len(result) == len(values): + values = result return values