#!/usr/bin/python """ VM names on stdin. """ import smtplib import optparse import sys from email.mime.text import MIMEText from invirt import database def send_mail(smtp, opts, message, vm): contact = database.Machine.query.filter_by(name=vm).first().contact if '@' not in contact: contact += '@mit.edu' msg = MIMEText(message % vm) msg['To'] = contact msg['From'] = opts.from_addr msg['Reply-To'] = 'XVM ' msg['Subject'] = opts.subject % vm smtp.sendmail(opts.from_addr, [contact], msg.as_string()) return msg.as_string() def send_summary(smtp, opts, messages): msg = MIMEText('\n\n\n'.join(messages)) msg['To'] = 'xvm-team@mit.edu' msg['From'] = opts.from_addr msg['Subject'] = ("xvm outage-mail summary (%d): %s" % (len(messages), opts.subject)) smtp.sendmail(opts.from_addr, ['xvm-team@mit.edu'], msg.as_string()) def main(argv): parser = optparse.OptionParser( usage = '%prog {-m message, -f from} [options]