- I don't know how these ended up in cvs.
[monitor.git] / mailer.py
index ca194ed..a1cd735 100755 (executable)
--- a/mailer.py
+++ b/mailer.py
@@ -4,30 +4,14 @@
 #
 # Faiyaz Ahmed <faiyaza@cs.princeton.edu>
 #
-# $Id: $
+# $Id: mailer.py,v 1.6 2007/01/24 19:29:44 mef 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,20 @@ 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:
+                       print "Mailing %s" %to
+                       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")