source: trunk/scripts/update-contacts/update-contacts @ 2619

Last change on this file since 2619 was 2377, checked in by broder, 15 years ago

Add the update-contacts script for updating xvm-contacts.

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1#!/usr/bin/python
2
3"""Update the xvm-contacts list.
4
5This script finds all e-mail addresses currently listed as contacts
6for a VM and updates the xvm-contacts list to match, adding or
7removing as necessary.
8"""
9
10import socket
11import subprocess
12
13from invirt import database
14from invirt import remctl
15
16def getContacts():
17    contacts = set()
18
19    for m in database.Machine.query():
20        if '@' in m.contact:
21            contacts.add(m.contact.lower())
22        else:
23            contacts.add(m.contact.lower() + '@mit.edu')
24
25    return sorted(contacts)
26
27def stripDomain(c):
28    if c.endswith('@mit.edu'):
29        return c[:-8]
30    else:
31        return c
32
33def updateContacts(contacts):
34    p = subprocess.Popen(['blanche', '-f', '-', 'xvm-contacts'],
35                         stdin=subprocess.PIPE,
36                         )
37
38    p.communicate('\n'.join(stripDomain(c) for c in contacts))
39
40def main():
41    database.connect()
42    subprocess.call(['kinit', '-k'])
43
44    updateContacts(getContacts())
45
46if __name__ == '__main__':
47    main()
Note: See TracBrowser for help on using the repository browser.