# basename for the Dummynet box public key
# used to send configuration requests
# to the dummynet box.
-DBOX_KEY="/usr/share/dummynet/dbox_key"
+DBOX_KNOWN_HOSTS="/var/tmp/.dbox_known_hosts"
DEFAULT_TIMEOUT= "1H"
class ConfigureDummynetBox(Method):
"""
This script will configure an emulated link.
- WARNING: This method is experimental, so it
- could _work_.
To do this it:
- takes as input the node_id, the slicename,
cmd_line += "cat " + file_to_upload + " >> "
# start to build the command line
- # the ssh command take as input
+ # The ssh commands need to use a known hosts file.
+ # Since it is called by different programs, each one
+ # with a different home location, we use some option
+ # to force the known hosts file to be always the same.
+ # We make the command not interactive too.
+ SSH = "ssh -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=yes ";
+ SSH += "-o UserKnownHostsFile=" + "'"+DBOX_KNOWN_HOSTS+"'" + " ";
+
+ # use the right key, we need
+ # apache:apache key when called from python,
+ # root:root when called from php or plcsh
+ DBOX_KEY="/usr/share/dummynet/dbox_key"
+ id = os.popen("id -u").read()
+ id = int(id)
+ if (id != 0):
+ DBOX_KEY += "_apache";
+
+ # the ssh command takes as input
# the node_ip, the slicename, the port number
# a timeout and a filename (0 don't upload)
-
- cmd_line += "ssh -i "+DBOX_KEY+" user@"+dbox_ip;
+ cmd_line += SSH + " -i "+DBOX_KEY+" user@"+dbox_ip;
cmd_line += " "+str(node_ip)+" "+slicename+" "+str(port);
# add the timeout
cmd_line += " noerror"
# send the command to the dummynetbox
- # suppose that the key exist with right permissions
-
- ret = os.system(cmd_line);
- if ret == 0:
- return "link configured"
+ command = os.popen(cmd_line);
+ output = command.read();
+ ret = str(command.close());
+ if (ret == "None"):
+ ret = cmd_line + "Command executed"
+ return "OK " + ret + "\n" + output
else:
- return "an error occurred link not configured"
+ ret = "Some errors occurred, a detailed description of the output follows"
+ return cmd_line + "ERROR " + ret + "\n" + output
+ return ret
# authorized file delimiter string
NEWFILE_MARK = "authorized_keys_mark"
+# Dummynet box private key
+KEY="/usr/share/dummynet/dbox_key"
+
class GetDummyBoxUsers(Method):
"""
Return a list of information about
authorized_keys_file += '# command="command key_id $SSH_ORIGINAL_COMMAND",ssh_options key_type key comment\n'
authorized_keys_file += "# where command, key_id and ssh_options are filled by the Central Site script\n"
authorized_keys_file += "# and $SSH_ORIGINAL_COMMAND is the command line inserted by the node\n"
-
+ authorized_keys_file += "\n";
+
+ # read the central site key
+ # the dummynet public key is located under KEY
+ try:
+ pub_key=KEY+".pub"
+ dbox_key_file = open(pub_key, 'r')
+ dbox_key = dbox_key_file.readline()
+
+ # upload the central site public key, used to
+ # send plcapi commands to the central site
+ # we use the special key_index = 0 value
+ authorized_keys_file += "# The Central Site key, it allows to jump some checks on the dbox\n"
+ authorized_keys_file += "command=\"" + ssh_command + "0";
+ authorized_keys_file += " $SSH_ORIGINAL_COMMAND\"" + ssh_configuration + dbox_key + "\n"
+ dbox_key_file.close()
+ except:
+ authorized_keys_file += "# The Central Site public key not found, this dummynet box\n";
+ authorized_keys_file += "# will not accept configuration request coming from the Central Site\n";
+
+ authorized_keys_file += "\n";
+ # upload the users keys
for i in authorized_keys_dict:
# index of the key
key_index = str(authorized_keys_dict[i])