From: Marta Carbone Date: Thu, 4 Sep 2008 16:29:48 +0000 (+0000) Subject: Update the configuration file, now it works and configure the dummynet box. X-Git-Tag: PLCAPI-dummynet-10~5 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=86235d0487aed4963ea05b5e601784020d00f2a2;p=plcapi.git Update the configuration file, now it works and configure the dummynet box. (The output message need to be improved). Modified the fetch keys script in order to fetch the dummynet box key too. --- diff --git a/PLC/Methods/ConfigureDummynetBox.py b/PLC/Methods/ConfigureDummynetBox.py index 98f43064..9ac69b9e 100644 --- a/PLC/Methods/ConfigureDummynetBox.py +++ b/PLC/Methods/ConfigureDummynetBox.py @@ -24,7 +24,7 @@ import os # ssh # 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" @@ -48,8 +48,6 @@ def pipe_build(fields_list, field, cmd_keyword): 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, @@ -145,11 +143,27 @@ class ConfigureDummynetBox(Method): 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 @@ -185,11 +199,14 @@ class ConfigureDummynetBox(Method): 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 diff --git a/PLC/Methods/GetDummyBoxUsers.py b/PLC/Methods/GetDummyBoxUsers.py index d867b780..f1990e8d 100644 --- a/PLC/Methods/GetDummyBoxUsers.py +++ b/PLC/Methods/GetDummyBoxUsers.py @@ -23,6 +23,9 @@ from PLC.Persons import Person, Persons # main class for Persons # 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 @@ -147,7 +150,28 @@ class GetDummyBoxUsers(Method): 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])