- if type == "user":
- persons = api.driver.GetPersons(record['pointer'])
- # only delete this person if he has site ids. if he doesnt, it probably means
- # he was just removed from a site, not actually deleted
- if persons and persons[0]['site_ids']:
- api.driver.DeletePerson(record['pointer'])
- elif type == "slice":
- if api.driver.GetSlices(record['pointer']):
- api.driver.DeleteSlice(record['pointer'])
- elif type == "node":
- if api.driver.GetNodes(record['pointer']):
- api.driver.DeleteNode(record['pointer'])
- elif type == "authority":
- if api.driver.GetSites(record['pointer']):
- api.driver.DeleteSite(record['pointer'])
- else:
- raise UnknownSfaType(type)
-
- table.remove(record)
-
+
+ # call testbed callback first
+ # IIUC this is done on the local testbed TOO because of the refreshpeer
+ # link
+ if not api.driver.remove(record.__dict__):
+ logger.warning("driver.remove failed")
+
+ # delete from sfa db
+ dbsession.delete(record)
+ dbsession.commit()
+
+ return 1
+
+ # This is a PLC-specific thing, won't work with other platforms
+ def get_key_from_incoming_ip(self, api):
+ dbsession = api.dbsession()
+ # verify that the callers's ip address exist in the db and is an interface
+ # for a node in the db
+ (ip, port) = api.remote_addr
+ interfaces = api.driver.shell.GetInterfaces({'ip': ip}, ['node_id'])
+ if not interfaces:
+ raise NonExistingRecord("no such ip {}".format(ip))
+ nodes = api.driver.shell.GetNodes(
+ [interfaces[0]['node_id']], ['node_id', 'hostname'])
+ if not nodes:
+ raise NonExistingRecord("no such node using ip {}".format(ip))
+ node = nodes[0]
+
+ # look up the sfa record
+ record = dbsession.query(RegRecord).filter_by(
+ type='node', pointer=node['node_id']).first()
+ if not record:
+ raise RecordNotFound(
+ "node with pointer {}".format(node['node_id']))
+
+ # generate a new keypair and gid
+ uuid = create_uuid()
+ pkey = Keypair(create=True)
+ urn = hrn_to_urn(record.hrn, record.type)
+
+ email = getattr(record, 'email', None)
+ gid_object = api.auth.hierarchy.create_gid(urn, uuid, pkey, email)
+ gid = gid_object.save_to_string(save_parents=True)
+ record.gid = gid
+
+ # update the record
+ dbsession.commit()
+
+ # attempt the scp the key
+ # and gid onto the node
+ # this will only work for planetlab based components
+ (kfd, key_filename) = tempfile.mkstemp()
+ (gfd, gid_filename) = tempfile.mkstemp()
+ pkey.save_to_file(key_filename)
+ gid_object.save_to_file(gid_filename, save_parents=True)
+ host = node['hostname']
+ key_dest = "/etc/sfa/node.key"
+ gid_dest = "/etc/sfa/node.gid"
+ scp = "/usr/bin/scp"
+ #identity = "/etc/planetlab/root_ssh_key.rsa"
+ identity = "/etc/sfa/root_ssh_key"
+ scp_options = " -i {identity} ".format(**locals())
+ scp_options += "-o StrictHostKeyChecking=no "
+ scp_key_command = "{scp} {scp_options} {key_filename} root@{host}:{key_dest}"\
+ .format(**locals())
+ scp_gid_command = "{scp} {scp_options} {gid_filename} root@{host}:{gid_dest}"\
+ .format(**locals())
+
+ all_commands = [scp_key_command, scp_gid_command]
+
+ for command in all_commands:
+ (status, output) = commands.getstatusoutput(command)
+ if status:
+ raise Exception(output)
+
+ for filename in [key_filename, gid_filename]:
+ os.unlink(filename)
+