8e15ea79496eca4fa0858a65593b93605aae51f1
[sfa.git] / sfa / plc / api.py
1 #
2 # SFA XML-RPC and SOAP interfaces
3 #
4
5 import sys
6 import os
7 import traceback
8 import string
9 import datetime
10 import xmlrpclib
11
12 from sfa.util.faults import *
13 from sfa.util.api import *
14 from sfa.util.config import *
15 from sfa.util.sfalogging import sfa_logger
16 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
17 from sfa.trust.auth import Auth
18 from sfa.trust.rights import Right, Rights, determine_rights
19 from sfa.trust.credential import Credential,Keypair
20 from sfa.trust.certificate import Certificate
21 from sfa.util.xrn import get_authority, hrn_to_urn
22 from sfa.util.plxrn import hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_slicename, slicename_to_hrn
23 from sfa.util.nodemanager import NodeManager
24 try:
25     from collections import defaultdict
26 except:
27     class defaultdict(dict):
28         def __init__(self, default_factory=None, *a, **kw):
29             if (default_factory is not None and
30                 not hasattr(default_factory, '__call__')):
31                 raise TypeError('first argument must be callable')
32             dict.__init__(self, *a, **kw)
33             self.default_factory = default_factory
34         def __getitem__(self, key):
35             try:
36                 return dict.__getitem__(self, key)
37             except KeyError:
38                 return self.__missing__(key)
39         def __missing__(self, key):
40             if self.default_factory is None:
41                 raise KeyError(key)
42             self[key] = value = self.default_factory()
43             return value
44         def __reduce__(self):
45             if self.default_factory is None:
46                 args = tuple()
47             else:
48                 args = self.default_factory,
49             return type(self), args, None, None, self.items()
50         def copy(self):
51             return self.__copy__()
52         def __copy__(self):
53             return type(self)(self.default_factory, self)
54         def __deepcopy__(self, memo):
55             import copy
56             return type(self)(self.default_factory,
57                               copy.deepcopy(self.items()))
58         def __repr__(self):
59             return 'defaultdict(%s, %s)' % (self.default_factory,
60                                             dict.__repr__(self))
61 ## end of http://code.activestate.com/recipes/523034/ }}}
62
63 def list_to_dict(recs, key):
64     """
65     convert a list of dictionaries into a dictionary keyed on the 
66     specified dictionary key 
67     """
68     keys = [rec[key] for rec in recs]
69     return dict(zip(keys, recs))
70
71 class SfaAPI(BaseAPI):
72
73     # flat list of method names
74     import sfa.methods
75     methods = sfa.methods.all
76     
77     def __init__(self, config = "/etc/sfa/sfa_config.py", encoding = "utf-8", 
78                  methods='sfa.methods', peer_cert = None, interface = None, 
79                 key_file = None, cert_file = None, cache = None):
80         BaseAPI.__init__(self, config=config, encoding=encoding, methods=methods, \
81                          peer_cert=peer_cert, interface=interface, key_file=key_file, \
82                          cert_file=cert_file, cache=cache)
83  
84         self.encoding = encoding
85         from sfa.util.table import SfaTable
86         self.SfaTable = SfaTable
87         # Better just be documenting the API
88         if config is None:
89             return
90
91         # Load configuration
92         self.config = Config(config)
93         self.auth = Auth(peer_cert)
94         self.interface = interface
95         self.key_file = key_file
96         self.key = Keypair(filename=self.key_file)
97         self.cert_file = cert_file
98         self.cert = Certificate(filename=self.cert_file)
99         self.credential = None
100         # Initialize the PLC shell only if SFA wraps a myPLC
101         rspec_type = self.config.get_aggregate_type()
102         if (rspec_type == 'pl' or rspec_type == 'vini' or \
103             rspec_type == 'eucalyptus' or rspec_type == 'max'):
104             self.plshell = self.getPLCShell()
105             self.plshell_version = "4.3"
106
107         self.hrn = self.config.SFA_INTERFACE_HRN
108         self.time_format = "%Y-%m-%d %H:%M:%S"
109         self.logger=sfa_logger()
110
111     def getPLCShell(self):
112         self.plauth = {'Username': self.config.SFA_PLC_USER,
113                        'AuthMethod': 'password',
114                        'AuthString': self.config.SFA_PLC_PASSWORD}
115         try:
116             sys.path.append(os.path.dirname(os.path.realpath("/usr/bin/plcsh")))
117             self.plshell_type = 'direct'
118             import PLC.Shell
119             shell = PLC.Shell.Shell(globals = globals())
120         except:
121             self.plshell_type = 'xmlrpc' 
122             url = self.config.SFA_PLC_URL
123             shell = xmlrpclib.Server(url, verbose = 0, allow_none = True)
124         
125         return shell
126
127     def getCredential(self):
128         """
129         Return a valid credential for this interface. 
130         """
131         type = 'authority'
132         path = self.config.SFA_DATA_DIR
133         filename = ".".join([self.interface, self.hrn, type, "cred"])
134         cred_filename = path + os.sep + filename
135         cred = None
136         if os.path.isfile(cred_filename):
137             cred = Credential(filename = cred_filename)
138             # make sure cred isnt expired
139             if not cred.get_expiration or \
140                datetime.datetime.today() < cred.get_expiration():    
141                 return cred.save_to_string(save_parents=True)
142
143         # get a new credential
144         if self.interface in ['registry']:
145             cred =  self.__getCredentialRaw()
146         else:
147             cred =  self.__getCredential()
148         cred.save_to_file(cred_filename, save_parents=True)
149
150         return cred.save_to_string(save_parents=True)
151
152
153     def getDelegatedCredential(self, creds):
154         """
155         Attempt to find a credential delegated to us in
156         the specified list of creds.
157         """
158         if creds and not isinstance(creds, list): 
159             creds = [creds]
160         delegated_creds = filter_creds_by_caller(creds,self.hrn)
161         if not delegated_creds:
162             return None
163         return delegated_creds[0]
164  
165     def __getCredential(self):
166         """ 
167         Get our credential from a remote registry 
168         """
169         from sfa.server.registry import Registries
170         registries = Registries(self)
171         registry = registries[self.hrn]
172         cert_string=self.cert.save_to_string(save_parents=True)
173         # get self credential
174         self_cred = registry.GetSelfCredential(cert_string, self.hrn, 'authority')
175         # get credential
176         cred = registry.GetCredential(self_cred, self.hrn, 'authority')
177         return Credential(string=cred)
178
179     def __getCredentialRaw(self):
180         """
181         Get our current credential directly from the local registry.
182         """
183
184         hrn = self.hrn
185         auth_hrn = self.auth.get_authority(hrn)
186     
187         # is this a root or sub authority
188         if not auth_hrn or hrn == self.config.SFA_INTERFACE_HRN:
189             auth_hrn = hrn
190         auth_info = self.auth.get_auth_info(auth_hrn)
191         table = self.SfaTable()
192         records = table.findObjects(hrn)
193         if not records:
194             raise RecordNotFound
195         record = records[0]
196         type = record['type']
197         object_gid = record.get_gid_object()
198         new_cred = Credential(subject = object_gid.get_subject())
199         new_cred.set_gid_caller(object_gid)
200         new_cred.set_gid_object(object_gid)
201         new_cred.set_issuer_keys(auth_info.get_privkey_filename(), auth_info.get_gid_filename())
202         
203         r1 = determine_rights(type, hrn)
204         new_cred.set_privileges(r1)
205         new_cred.encode()
206         new_cred.sign()
207
208         return new_cred
209    
210
211     def loadCredential (self):
212         """
213         Attempt to load credential from file if it exists. If it doesnt get
214         credential from registry.
215         """
216
217         # see if this file exists
218         # XX This is really the aggregate's credential. Using this is easier than getting
219         # the registry's credential from iteslf (ssl errors).   
220         ma_cred_filename = self.config.SFA_DATA_DIR + os.sep + self.interface + self.hrn + ".ma.cred"
221         try:
222             self.credential = Credential(filename = ma_cred_filename)
223         except IOError:
224             self.credential = self.getCredentialFromRegistry()
225
226     ##
227     # Convert SFA fields to PLC fields for use when registering up updating
228     # registry record in the PLC database
229     #
230     # @param type type of record (user, slice, ...)
231     # @param hrn human readable name
232     # @param sfa_fields dictionary of SFA fields
233     # @param pl_fields dictionary of PLC fields (output)
234
235     def sfa_fields_to_pl_fields(self, type, hrn, record):
236
237         def convert_ints(tmpdict, int_fields):
238             for field in int_fields:
239                 if field in tmpdict:
240                     tmpdict[field] = int(tmpdict[field])
241
242         pl_record = {}
243         #for field in record:
244         #    pl_record[field] = record[field]
245  
246         if type == "slice":
247             if not "instantiation" in pl_record:
248                 pl_record["instantiation"] = "plc-instantiated"
249             pl_record["name"] = hrn_to_pl_slicename(hrn)
250             if "url" in record:
251                pl_record["url"] = record["url"]
252             if "description" in record:
253                 pl_record["description"] = record["description"]
254             if "expires" in record:
255                 pl_record["expires"] = int(record["expires"])
256
257         elif type == "node":
258             if not "hostname" in pl_record:
259                 if not "hostname" in record:
260                     raise MissingSfaInfo("hostname")
261                 pl_record["hostname"] = record["hostname"]
262             if not "model" in pl_record:
263                 pl_record["model"] = "geni"
264
265         elif type == "authority":
266             pl_record["login_base"] = hrn_to_pl_login_base(hrn)
267
268             if not "name" in pl_record:
269                 pl_record["name"] = hrn
270
271             if not "abbreviated_name" in pl_record:
272                 pl_record["abbreviated_name"] = hrn
273
274             if not "enabled" in pl_record:
275                 pl_record["enabled"] = True
276
277             if not "is_public" in pl_record:
278                 pl_record["is_public"] = True
279
280         return pl_record
281
282     def fill_record_pl_info(self, records):
283         """
284         Fill in the planetlab specific fields of a SFA record. This
285         involves calling the appropriate PLC method to retrieve the 
286         database record for the object.
287         
288         PLC data is filled into the pl_info field of the record.
289     
290         @param record: record to fill in field (in/out param)     
291         """
292         # get ids by type
293         node_ids, site_ids, slice_ids = [], [], [] 
294         person_ids, key_ids = [], []
295         type_map = {'node': node_ids, 'authority': site_ids,
296                     'slice': slice_ids, 'user': person_ids}
297                   
298         for record in records:
299             for type in type_map:
300                 if type == record['type']:
301                     type_map[type].append(record['pointer'])
302
303         # get pl records
304         nodes, sites, slices, persons, keys = {}, {}, {}, {}, {}
305         if node_ids:
306             node_list = self.plshell.GetNodes(self.plauth, node_ids)
307             nodes = list_to_dict(node_list, 'node_id')
308         if site_ids:
309             site_list = self.plshell.GetSites(self.plauth, site_ids)
310             sites = list_to_dict(site_list, 'site_id')
311         if slice_ids:
312             slice_list = self.plshell.GetSlices(self.plauth, slice_ids)
313             slices = list_to_dict(slice_list, 'slice_id')
314         if person_ids:
315             person_list = self.plshell.GetPersons(self.plauth, person_ids)
316             persons = list_to_dict(person_list, 'person_id')
317             for person in persons:
318                 key_ids.extend(persons[person]['key_ids'])
319
320         pl_records = {'node': nodes, 'authority': sites,
321                       'slice': slices, 'user': persons}
322
323         if key_ids:
324             key_list = self.plshell.GetKeys(self.plauth, key_ids)
325             keys = list_to_dict(key_list, 'key_id')
326
327         # fill record info
328         for record in records:
329             # records with pointer==-1 do not have plc info.
330             # for example, the top level authority records which are
331             # authorities, but not PL "sites"
332             if record['pointer'] == -1:
333                 continue
334            
335             for type in pl_records:
336                 if record['type'] == type:
337                     if record['pointer'] in pl_records[type]:
338                         record.update(pl_records[type][record['pointer']])
339                         break
340             # fill in key info
341             if record['type'] == 'user':
342                 if 'key_ids' not in record:
343                     self.logger.info("user record has no 'key_ids' - need to import from myplc ?")
344                 else:
345                     pubkeys = [keys[key_id]['key'] for key_id in record['key_ids'] if key_id in keys] 
346                     record['keys'] = pubkeys
347
348         # fill in record hrns
349         records = self.fill_record_hrns(records)   
350  
351         return records
352
353     def fill_record_hrns(self, records):
354         """
355         convert pl ids to hrns
356         """
357
358         # get ids
359         slice_ids, person_ids, site_ids, node_ids = [], [], [], []
360         for record in records:
361             if 'site_id' in record:
362                 site_ids.append(record['site_id'])
363             if 'site_ids' in records:
364                 site_ids.extend(record['site_ids'])
365             if 'person_ids' in record:
366                 person_ids.extend(record['person_ids'])
367             if 'slice_ids' in record:
368                 slice_ids.extend(record['slice_ids'])
369             if 'node_ids' in record:
370                 node_ids.extend(record['node_ids'])
371
372         # get pl records
373         slices, persons, sites, nodes = {}, {}, {}, {}
374         if site_ids:
375             site_list = self.plshell.GetSites(self.plauth, site_ids, ['site_id', 'login_base'])
376             sites = list_to_dict(site_list, 'site_id')
377         if person_ids:
378             person_list = self.plshell.GetPersons(self.plauth, person_ids, ['person_id', 'email'])
379             persons = list_to_dict(person_list, 'person_id')
380         if slice_ids:
381             slice_list = self.plshell.GetSlices(self.plauth, slice_ids, ['slice_id', 'name'])
382             slices = list_to_dict(slice_list, 'slice_id')       
383         if node_ids:
384             node_list = self.plshell.GetNodes(self.plauth, node_ids, ['node_id', 'hostname'])
385             nodes = list_to_dict(node_list, 'node_id')
386        
387         # convert ids to hrns
388         for record in records:
389             # get all relevant data
390             type = record['type']
391             pointer = record['pointer']
392             auth_hrn = self.hrn
393             login_base = ''
394             if pointer == -1:
395                 continue
396
397             if 'site_id' in record:
398                 site = sites[record['site_id']]
399                 login_base = site['login_base']
400                 record['site'] = ".".join([auth_hrn, login_base])
401             if 'person_ids' in record:
402                 emails = [persons[person_id]['email'] for person_id in record['person_ids'] \
403                           if person_id in  persons]
404                 usernames = [email.split('@')[0] for email in emails]
405                 person_hrns = [".".join([auth_hrn, login_base, username]) for username in usernames]
406                 record['persons'] = person_hrns 
407             if 'slice_ids' in record:
408                 slicenames = [slices[slice_id]['name'] for slice_id in record['slice_ids'] \
409                               if slice_id in slices]
410                 slice_hrns = [slicename_to_hrn(auth_hrn, slicename) for slicename in slicenames]
411                 record['slices'] = slice_hrns
412             if 'node_ids' in record:
413                 hostnames = [nodes[node_id]['hostname'] for node_id in record['node_ids'] \
414                              if node_id in nodes]
415                 node_hrns = [hostname_to_hrn(auth_hrn, login_base, hostname) for hostname in hostnames]
416                 record['nodes'] = node_hrns
417             if 'site_ids' in record:
418                 login_bases = [sites[site_id]['login_base'] for site_id in record['site_ids'] \
419                                if site_id in sites]
420                 site_hrns = [".".join([auth_hrn, lbase]) for lbase in login_bases]
421                 record['sites'] = site_hrns
422             
423         return records   
424
425     def fill_record_sfa_info(self, records):
426
427         def startswith(prefix, values):
428             return [value for value in values if value.startswith(prefix)]
429
430         # get person ids
431         person_ids = []
432         site_ids = []
433         for record in records:
434             person_ids.extend(record.get("person_ids", []))
435             site_ids.extend(record.get("site_ids", [])) 
436             if 'site_id' in record:
437                 site_ids.append(record['site_id']) 
438         
439         # get all pis from the sites we've encountered
440         # and store them in a dictionary keyed on site_id 
441         site_pis = {}
442         if site_ids:
443             pi_filter = {'|roles': ['pi'], '|site_ids': site_ids} 
444             pi_list = self.plshell.GetPersons(self.plauth, pi_filter, ['person_id', 'site_ids'])
445             for pi in pi_list:
446                 # we will need the pi's hrns also
447                 person_ids.append(pi['person_id'])
448                 
449                 # we also need to keep track of the sites these pis
450                 # belong to
451                 for site_id in pi['site_ids']:
452                     if site_id in site_pis:
453                         site_pis[site_id].append(pi)
454                     else:
455                         site_pis[site_id] = [pi]
456                  
457         # get sfa records for all records associated with these records.   
458         # we'll replace pl ids (person_ids) with hrns from the sfa records
459         # we obtain
460         
461         # get the sfa records
462         table = self.SfaTable()
463         person_list, persons = [], {}
464         person_list = table.find({'type': 'user', 'pointer': person_ids})
465         # create a hrns keyed on the sfa record's pointer.
466         # Its possible for  multiple records to have the same pointer so
467         # the dict's value will be a list of hrns.
468         persons = defaultdict(list)
469         for person in person_list:
470             persons[person['pointer']].append(person)
471
472         # get the pl records
473         pl_person_list, pl_persons = [], {}
474         pl_person_list = self.plshell.GetPersons(self.plauth, person_ids, ['person_id', 'roles'])
475         pl_persons = list_to_dict(pl_person_list, 'person_id')
476
477         # fill sfa info
478         for record in records:
479             # skip records with no pl info (top level authorities)
480             #if record['pointer'] == -1:
481             #    continue 
482             sfa_info = {}
483             type = record['type']
484             if (type == "slice"):
485                 # all slice users are researchers
486                 record['geni_urn'] = hrn_to_urn(record['hrn'], 'slice')
487                 record['PI'] = []
488                 record['researcher'] = []
489                 for person_id in record.get('person_ids', []):
490                     hrns = [person['hrn'] for person in persons[person_id]]
491                     record['researcher'].extend(hrns)                
492
493                 # pis at the slice's site
494                 if 'site_id' in record and record['site_id'] in site_pis:
495                     pl_pis = site_pis[record['site_id']]
496                     pi_ids = [pi['person_id'] for pi in pl_pis]
497                     for person_id in pi_ids:
498                         hrns = [person['hrn'] for person in persons[person_id]]
499                         record['PI'].extend(hrns)
500                         record['geni_creator'] = record['PI'] 
501                 
502             elif (type.startswith("authority")):
503                 record['url'] = None
504                 if record['hrn'] in self.aggregates:
505                     record['url'] = self.aggregates[record['hrn']].url
506
507                 if record['pointer'] != -1:
508                     record['PI'] = []
509                     record['operator'] = []
510                     record['owner'] = []
511                     for pointer in record.get('person_ids', []):
512                         if pointer not in persons or pointer not in pl_persons:
513                             # this means there is not sfa or pl record for this user
514                             continue   
515                         hrns = [person['hrn'] for person in persons[pointer]] 
516                         roles = pl_persons[pointer]['roles']   
517                         if 'pi' in roles:
518                             record['PI'].extend(hrns)
519                         if 'tech' in roles:
520                             record['operator'].extend(hrns)
521                         if 'admin' in roles:
522                             record['owner'].extend(hrns)
523                         # xxx TODO: OrganizationName
524             elif (type == "node"):
525                 sfa_info['dns'] = record.get("hostname", "")
526                 # xxx TODO: URI, LatLong, IP, DNS
527     
528             elif (type == "user"):
529                 sfa_info['email'] = record.get("email", "")
530                 sfa_info['geni_urn'] = hrn_to_urn(record['hrn'], 'user')
531                 sfa_info['geni_certificate'] = record['gid'] 
532                 # xxx TODO: PostalAddress, Phone
533             record.update(sfa_info)
534
535     def fill_record_info(self, records):
536         """
537         Given a SFA record, fill in the PLC specific and SFA specific
538         fields in the record. 
539         """
540         if not isinstance(records, list):
541             records = [records]
542
543         self.fill_record_pl_info(records)
544         self.fill_record_sfa_info(records)
545
546     def update_membership_list(self, oldRecord, record, listName, addFunc, delFunc):
547         # get a list of the HRNs tht are members of the old and new records
548         if oldRecord:
549             oldList = oldRecord.get(listName, [])
550         else:
551             oldList = []     
552         newList = record.get(listName, [])
553
554         # if the lists are the same, then we don't have to update anything
555         if (oldList == newList):
556             return
557
558         # build a list of the new person ids, by looking up each person to get
559         # their pointer
560         newIdList = []
561         table = self.SfaTable()
562         records = table.find({'type': 'user', 'hrn': newList})
563         for rec in records:
564             newIdList.append(rec['pointer'])
565
566         # build a list of the old person ids from the person_ids field 
567         if oldRecord:
568             oldIdList = oldRecord.get("person_ids", [])
569             containerId = oldRecord.get_pointer()
570         else:
571             # if oldRecord==None, then we are doing a Register, instead of an
572             # update.
573             oldIdList = []
574             containerId = record.get_pointer()
575
576     # add people who are in the new list, but not the oldList
577         for personId in newIdList:
578             if not (personId in oldIdList):
579                 addFunc(self.plauth, personId, containerId)
580
581         # remove people who are in the old list, but not the new list
582         for personId in oldIdList:
583             if not (personId in newIdList):
584                 delFunc(self.plauth, personId, containerId)
585
586     def update_membership(self, oldRecord, record):
587         if record.type == "slice":
588             self.update_membership_list(oldRecord, record, 'researcher',
589                                         self.plshell.AddPersonToSlice,
590                                         self.plshell.DeletePersonFromSlice)
591         elif record.type == "authority":
592             # xxx TODO
593             pass
594
595
596
597 class ComponentAPI(BaseAPI):
598
599     def __init__(self, config = "/etc/sfa/sfa_config.py", encoding = "utf-8", methods='sfa.methods',
600                  peer_cert = None, interface = None, key_file = None, cert_file = None):
601
602         BaseAPI.__init__(self, config=config, encoding=encoding, methods=methods, peer_cert=peer_cert,
603                          interface=interface, key_file=key_file, cert_file=cert_file)
604         self.encoding = encoding
605
606         # Better just be documenting the API
607         if config is None:
608             return
609
610         self.nodemanager = NodeManager(self.config)
611
612     def sliver_exists(self):
613         sliver_dict = self.nodemanager.GetXIDs()
614         if slicename in sliver_dict.keys():
615             return True
616         else:
617             return False
618
619     def get_registry(self):
620         addr, port = self.config.SFA_REGISTRY_HOST, self.config.SFA_REGISTRY_PORT
621         url = "http://%(addr)s:%(port)s" % locals()
622         server = xmlrpcprotocol.get_server(url, self.key_file, self.cert_file)
623         return server
624
625     def get_node_key(self):
626         # this call requires no authentication,
627         # so we can generate a random keypair here
628         subject="component"
629         (kfd, keyfile) = tempfile.mkstemp()
630         (cfd, certfile) = tempfile.mkstemp()
631         key = Keypair(create=True)
632         key.save_to_file(keyfile)
633         cert = Certificate(subject=subject)
634         cert.set_issuer(key=key, subject=subject)
635         cert.set_pubkey(key)
636         cert.sign()
637         cert.save_to_file(certfile)
638         registry = self.get_registry()
639         # the registry will scp the key onto the node
640         registry.get_key()        
641
642     def getCredential(self):
643         """
644         Get our credential from a remote registry
645         """
646         path = self.config.SFA_DATA_DIR
647         config_dir = self.config.config_path
648         cred_filename = path + os.sep + 'node.cred'
649         try:
650             credential = Credential(filename = cred_filename)
651             return credential.save_to_string(save_parents=True)
652         except IOError:
653             node_pkey_file = config_dir + os.sep + "node.key"
654             node_gid_file = config_dir + os.sep + "node.gid"
655             cert_filename = path + os.sep + 'server.cert'
656             if not os.path.exists(node_pkey_file) or \
657                not os.path.exists(node_gid_file):
658                 self.get_node_key()
659
660             # get node's hrn
661             gid = GID(filename=node_gid_file)
662             hrn = gid.get_hrn()
663             # get credential from registry
664             cert_str = Certificate(filename=cert_filename).save_to_string(save_parents=True)
665             registry = self.get_registry()
666             cred = registry.GetSelfCredential(cert_str, hrn, 'node')
667             Credential(string=cred).save_to_file(credfile, save_parents=True)            
668
669             return cred
670
671     def clean_key_cred(self):
672         """
673         remove the existing keypair and cred  and generate new ones
674         """
675         files = ["server.key", "server.cert", "node.cred"]
676         for f in files:
677             filepath = KEYDIR + os.sep + f
678             if os.path.isfile(filepath):
679                 os.unlink(f)
680
681         # install the new key pair
682         # GetCredential will take care of generating the new keypair
683         # and credential
684         self.get_node_key()
685         self.getCredential()
686
687