import repository from arizona
[raven.git] / lib / ravenlib / platform / platform_planetlab.py
1 import os
2 import sys
3 import xmlrpclib
4
5 SLICENAME_FN = "/etc/slicename"
6
7 glo_planetlab_groups = []
8
9 def init():
10     if os.path.exists(SLICENAME_FN) and os.path.exists("/etc/planetlab"):
11         return True
12     else:
13         return False
14
15 def get_slice_names():
16    try:
17       if os.path.isfile(SLICENAME_FN):
18          slicefile = open(SLICENAME_FN)
19          slicename = slicefile.read().strip()
20          slicefile.close()
21       else:
22          return []
23    except (NameError, IOError):
24       return []
25
26    return [slicename]
27
28 def get_node_names():
29    return []
30
31 def read_plc_config():
32    global glo_planetlab_groups
33
34    glo_planetlab_groups = ["planetlab"]
35    if (os.path.exists("/etc/planetlab")):
36        origPath = None
37        # nested try-except within try-finally for Python 2.4 compatibility
38        try:
39            try:
40                if not ("/etc/planetlab" in sys.path):
41                    origPath = sys.path
42                    sys.path.append("/etc/planetlab")
43
44                import plc_config
45
46                if (hasattr(plc_config, "PLC_NAME")):
47                    if plc_config.PLC_NAME!="PlanetLab":
48                        glo_planetlab_groups.append(plc_config.PLC_NAME)
49
50            except ImportError:
51                pass
52
53        finally:
54            if origPath:
55                sys.path = origPath
56
57 def get_group_names():
58    global glo_planetlab_groups
59
60    if glo_planetlab_groups == []:
61        read_plc_config()
62
63    return glo_planetlab_groups
64
65 def get_keys():
66    slice_names = get_slice_names()
67
68    # quick hack to use Scott's public key for VINI demo
69    if "VINI" in get_group_names():
70        keys=[]
71        key_dict = {"kind": "ssh", "value": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA8gtU3Obrsofcoi+PihMHf/ek6tYlPNtWVdhTu8nw4e7jazQJ7dKaS1w9p2Pnqs7mxrb3m6mDJLzU4wTZeuAMy1RHmgRV9VpcBSYyTvbLWfg7Q/+ZAsREYuWSLX2NnJJhsf6H9OMka3+6kljauvxmdBqGYsQxti8nBxxdwL4J8xE= smbaker@test64", "platform": "planetlab"}
72        keys.append(key_dict)
73        return keys
74
75    all_slice_keys = xmlrpclib.ServerProxy('http://localhost:812/').GetSSHKeys()
76
77    keys = []
78
79    for slice_name in slice_names:  # the slice probably has only one name
80        if slice_name in all_slice_keys:
81            this_slice_keys = all_slice_keys[slice_name]
82            for key in this_slice_keys.split("\n"):
83
84                # remove any keys that are blank
85                key = key.strip()
86                if len(key) == 0:
87                    continue
88
89                key_dict = {"kind": "ssh", "value": key, "platform": "planetlab"}
90                keys.append(key_dict)
91
92    return keys
93