From: Evan Broder Date: Sun, 9 Aug 2009 18:01:25 +0000 (-0400) Subject: Add the update-contacts script for updating xvm-contacts. X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/update-contacts.git/commitdiff_plain/4281f1747e4c15010a9e6ab786d267cf715bb92e Add the update-contacts script for updating xvm-contacts. svn path=/trunk/scripts/update-contacts/; revision=2377 --- 4281f1747e4c15010a9e6ab786d267cf715bb92e diff --git a/update-contacts b/update-contacts new file mode 100755 index 0000000..03087a2 --- /dev/null +++ b/update-contacts @@ -0,0 +1,47 @@ +#!/usr/bin/python + +"""Update the xvm-contacts list. + +This script finds all e-mail addresses currently listed as contacts +for a VM and updates the xvm-contacts list to match, adding or +removing as necessary. +""" + +import socket +import subprocess + +from invirt import database +from invirt import remctl + +def getContacts(): + contacts = set() + + for m in database.Machine.query(): + if '@' in m.contact: + contacts.add(m.contact.lower()) + else: + contacts.add(m.contact.lower() + '@mit.edu') + + return sorted(contacts) + +def stripDomain(c): + if c.endswith('@mit.edu'): + return c[:-8] + else: + return c + +def updateContacts(contacts): + p = subprocess.Popen(['blanche', '-f', '-', 'xvm-contacts'], + stdin=subprocess.PIPE, + ) + + p.communicate('\n'.join(stripDomain(c) for c in contacts)) + +def main(): + database.connect() + subprocess.call(['kinit', '-k']) + + updateContacts(getContacts()) + +if __name__ == '__main__': + main()