summaryrefslogtreecommitdiffstats
path: root/tools/upgrade.py
blob: 030dc298842d4a00f763d95df00922fdb1a05dcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python

'''This script updates to fully qualified hostnames for 0.6.11'''
__revision__ = '$Revision:$'

from ConfigParser import ConfigParser
from elementtree.ElementTree import XML, tostring
from socket import gethostbyname
from sys import argv
from glob import glob
from os import system

if __name__ == '__main__':
    hostcache = {}
    if len(argv) > 1:
        domainlist = argv[-1].split(':')
    else:
        domainlist = ['mcs.anl.gov']
    cf = ConfigParser()
    cf.read(['/etc/bcfg2.conf'])
    metadata = XML(open(cf.get('server', 'metadata') + '/metadata.xml').read())
    for client in metadata.findall('.//Client'):
        if client.get('name').count('.') == 0:
            for dom in domainlist:
                print "resolving name %s.%s..." % (client.get('name'), dom),
                try:
                    hostinfo = gethostbyname(client.get('name') + '.' + dom)
                    hostcache[client.get('name')] = dom
                    client.set('name', "%s.%s" % (client.get('name'), dom))
                    print ""
                    break
                except:
                    print "FAILED"
                    continue
                print hostinfo

    open(cf.get('server', 'metadata') + '/metadata.xml.new', 'w').write(tostring(metadata))

    metadata = XML(open(cf.get('server', 'metadata') + '/statistics.xml').read())
    for client in metadata.findall('.//Node'):
        if client.get('name').count('.') == 0:
            if hostcache.has_key(client.get('name')):
                client.set('name', "%s.%s" % (client.get('name'), hostcache[client.get('name')]))
                continue
            for dom in domainlist:
                print "resolving name %s.%s..." % (client.get('name'), dom),
                try:
                    hostinfo = gethostbyname(client.get('name') + '.' + dom)
                    hostcache[client.get('name')] = dom
                    client.set('name', "%s.%s" % (client.get('name'), dom))
                    print ""
                    break
                except:
                    print "FAILED"
                    continue
                print hostinfo

    open(cf.get('server', 'metadata') + '/statistics.xml.new', 'w').write(tostring(metadata))


    sshdir = cf.get('server', 'repository') + '/SSHbase/'
    for key in glob(sshdir + "*key*.H_*"):
        hostname = key.split('.H_')[1]
        if not hostcache.has_key(hostname):
            for dom in domainlist:
                try:
                    hostinfo = gethostbyname(hostname + '.' + dom)
                    hostcache[hostname] = dom
                    break
                except:
                    continue
        if hostcache.has_key(hostname):
            system("mv %s %s.%s" % (key, key, hostcache[hostname]))