X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=mailer.py;h=dc0799dc9170c4339a7629e3f7a21ff64f212a0a;hb=dbfe6652a8654ec633c4ffb9e86e9a61a5516dc6;hp=ca194ed0c4caa0fc4df2bd86d7fae67c00fce176;hpb=e31f3074815c6980b8ea7f63ec996f1d9b52a776;p=monitor.git diff --git a/mailer.py b/mailer.py index ca194ed..dc0799d 100755 --- a/mailer.py +++ b/mailer.py @@ -4,30 +4,14 @@ # # Faiyaz Ahmed # -# $Id: $ +# $Id: mailer.py,v 1.4 2006/11/14 19:20:13 faiyaza Exp $ from emailTxt import * -import xml, xmlrpclib import smtplib +import config MTA="localhost" FROM="support@planet-lab.org" -XMLRPC_SERVER = 'https://www.planet-lab.org/PLCAPI/' - -def siteId(hostname): - api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False) - anon = {'AuthMethod': "anonymous"} - site_id = api.AnonAdmQuerySite (anon, {"node_hostname": hostname}) - if len(site_id) == 1: - loginbase = api.AnonAdmGetSites (anon, site_id, ["login_base"]) - return loginbase[0]['login_base'] - - -def slices(loginbase): - api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False) - return api.SliceListNames (auth.auth, loginbase) - - def email (subject, text, to): """Create a mime-message that will render HTML in popular MUAs, text in better ones""" @@ -78,14 +62,19 @@ def email (subject, text, to): writer.lastpart() msg = out.getvalue() out.close() - server = smtplib.SMTP(MTA) - server.sendmail(FROM, to, msg) - server.quit() + if not config.debug: + try: + server = smtplib.SMTP(MTA) + server.sendmail(FROM, to, msg) + server.quit() + except Exception, err: + print "Mailer error: %s" % err if __name__=="__main__": import smtplib import emailTxt - id = siteId("alice.cs.princeton.edu") + import plc + id = plc.siteId("alice.cs.princeton.edu") print id #if id: #email('TEST', emailTxt.mailtxt.ssh % {'hostname': "ALICE.cs.princeton.edu"}, "tech-" + id + "@sites.planet-lab.org")