4 import sfa.client.sfaprotocol as sfaprotocol
5 from sfa.plc.nodemanager import NodeManager
7 from sfa.trust.credential import Credential
8 from sfa.trust.certificate import Certificate, Keypair
9 from sfa.trust.gid import GID
12 class PlComponentDriver:
14 This class is the type for the toplevel 'api' object
15 when running the component manager inside a planetlab node.
16 As such it runs an SFA-compliant interface and thus inherits SfaApi
17 However the fact that we run inside a planetlab nodes requires
18 some tweaks as compared with a service running in the infrastructure.
21 def __init__ (self, config):
22 self.nodemanager = NodeManager(config)
24 def sliver_exists(self):
25 sliver_dict = self.nodemanager.GetXIDs()
26 ### xxx slicename is undefined
27 if slicename in sliver_dict.keys():
32 def get_registry(self):
33 addr, port = self.config.SFA_REGISTRY_HOST, self.config.SFA_REGISTRY_PORT
34 url = "http://%(addr)s:%(port)s" % locals()
35 ### xxx this would require access to the api...
36 server = sfaprotocol.server_proxy(url, self.key_file, self.cert_file)
39 def get_node_key(self):
40 # this call requires no authentication,
41 # so we can generate a random keypair here
43 (kfd, keyfile) = tempfile.mkstemp()
44 (cfd, certfile) = tempfile.mkstemp()
45 key = Keypair(create=True)
46 key.save_to_file(keyfile)
47 cert = Certificate(subject=subject)
48 cert.set_issuer(key=key, subject=subject)
51 cert.save_to_file(certfile)
52 registry = self.get_registry()
53 # the registry will scp the key onto the node
54 registry.get_key_from_incoming_ip()
56 # override the method in SfaApi
57 def getCredential(self):
59 Get our credential from a remote registry
61 path = self.config.SFA_DATA_DIR
62 config_dir = self.config.config_path
63 cred_filename = path + os.sep + 'node.cred'
65 credential = Credential(filename = cred_filename)
66 return credential.save_to_string(save_parents=True)
68 node_pkey_file = config_dir + os.sep + "node.key"
69 node_gid_file = config_dir + os.sep + "node.gid"
70 cert_filename = path + os.sep + 'server.cert'
71 if not os.path.exists(node_pkey_file) or \
72 not os.path.exists(node_gid_file):
76 gid = GID(filename=node_gid_file)
78 # get credential from registry
79 cert_str = Certificate(filename=cert_filename).save_to_string(save_parents=True)
80 registry = self.get_registry()
81 cred = registry.GetSelfCredential(cert_str, hrn, 'node')
82 # xxx credfile is undefined
83 Credential(string=cred).save_to_file(credfile, save_parents=True)
87 def clean_key_cred(self):
89 remove the existing keypair and cred and generate new ones
91 files = ["server.key", "server.cert", "node.cred"]
93 # xxx KEYDIR is undefined, could be meant to be "/var/lib/sfa/" from sfa_component_setup.py
94 filepath = KEYDIR + os.sep + f
95 if os.path.isfile(filepath):
98 # install the new key pair
99 # GetCredential will take care of generating the new keypair