Index: trunk/extensions/OpenStackManager/scripts/mail-instance-creator.py |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | #!/usr/bin/python |
3 | 3 | import urllib |
4 | | -import os |
| 4 | +import subprocess |
5 | 5 | |
6 | 6 | from xml.dom import minidom |
7 | 7 | from optparse import OptionParser |
— | — | @@ -24,17 +24,16 @@ |
25 | 25 | dom = minidom.parse(urllib.urlopen(subjecturl)) |
26 | 26 | subject = dom.getElementsByTagName('expandtemplates')[0].firstChild.data |
27 | 27 | dom = minidom.parse(urllib.urlopen(bodyurl)) |
| 28 | + p = subprocess.Popen("ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub", shell=True, stdout=subprocess.PIPE) |
| 29 | + fingerprint = p.communicate()[0] |
| 30 | + fingerprint = fingerprint.split(' ')[1] |
28 | 31 | body = dom.getElementsByTagName('expandtemplates')[0].firstChild.data |
29 | | - body = body + ' ' + gethostname() |
30 | | - sendmail_location = "/usr/sbin/sendmail" # sendmail location |
31 | | - p = os.popen("%s -t" % sendmail_location, "w") |
32 | | - p.write("From: %s\n" % fromaddress) |
33 | | - p.write("To: %s\n" % toaddress) |
34 | | - p.write("Subject: %s\n" % subject) |
35 | | - p.write("\n") # blank line separating headers from body |
36 | | - p.write(body) |
37 | | - status = p.close() |
38 | | - return status |
| 32 | + body = body + ' ' + gethostname() + ' (' + fingerprint + ')' |
| 33 | + message = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (fromaddress, toaddress, subject, body) |
| 34 | + p = subprocess.Popen("/usr/sbin/sendmail -t", shell=True, stdin=subprocess.PIPE) |
| 35 | + p.communicate(message) |
| 36 | + if p.wait() != 0: |
| 37 | + return 1 |
39 | 38 | |
40 | 39 | if __name__ == "__main__": |
41 | 40 | main() |