+ 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] <vm-list',
+ description = __doc__.strip())
+ parser.add_option('-m', '--message',
+ type = 'string',
+ dest = 'message',
+ help = 'filename with body of message')
+ parser.add_option('-s', '--subject',
+ type = 'string',
+ dest = 'subject',
+ default = '[xvm] Unexpected reboot of your VM %s',
+ help = 'subject line of message; %s for VM name')
+ parser.add_option('-f', '--from',
+ type = 'string',
+ dest = 'from_addr',
+ help = 'for From: and envelope-from; first word is %(sig)s')
+ parser.add_option('--host',
+ type = 'string',
+ dest = 'host',
+ help = 'host that failed; %(host)s in message')
+ parser.add_option('--time',
+ type = 'string',
+ dest = 'time',
+ help = 'time of failure; %(time)s in message')
+ opts, args = parser.parse_args()
+
+ if len(args) or not opts.message or not opts.from_addr:
+ parser.print_help(sys.stderr)
+ return 2
+
+ opts.sig = opts.from_addr.split()[0]
+ message = file(opts.message).read() % opts.__dict__
+
+ vms = sys.stdin.read().split()
+
+ database.connect()
+ s = smtplib.SMTP()
+ s.connect()