From 40093300817a8d17fb20f56511daeeaaa7f2107c Mon Sep 17 00:00:00 2001 From: Marta Carbone Date: Wed, 10 Sep 2008 09:48:15 +0000 Subject: [PATCH] Renamed vars, changed return error messages, better handled extra-delay filename. Should improve return error messages. --- PLC/Methods/ConfigureDummynetBox.py | 60 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/PLC/Methods/ConfigureDummynetBox.py b/PLC/Methods/ConfigureDummynetBox.py index 4c75236b..34344fe7 100644 --- a/PLC/Methods/ConfigureDummynetBox.py +++ b/PLC/Methods/ConfigureDummynetBox.py @@ -27,7 +27,7 @@ import os # ssh DBOX_KNOWN_HOSTS="/var/tmp/.dbox_known_hosts" DBOX_KEY="/usr/share/dummynet/dbox_key" -DEFAULT_TIMEOUT= "1H" +DEFAULT_TIMEOUT= "1d" # return 1 if the value is present in the array def match(list, value): @@ -60,7 +60,7 @@ class ConfigureDummynetBox(Method): """ roles = ['admin', 'pi', 'tech', 'user'] - link_configuration_fields = { + link_config = { 'node_id': Parameter(int, "Node identifier"), 'slicename': Parameter(str, "Name of the slice"), 'port': Parameter(int, "Port number"), @@ -75,38 +75,38 @@ class ConfigureDummynetBox(Method): accepts = [ Auth(), - link_configuration_fields, + link_config, ] returns = Parameter(str, 'Remote command execution output'); - def call(self, auth, link_configuration_fields): + def call(self, auth, link_config): # Only a person istance can send configuration commands if not isinstance(self.caller, Person): - return "Authentication method not allowed to perform this operation"; + return "1 Authentication method not allowed to perform this operation"; # Get identity email = str(self.caller['email']); # Get mandatory arguments - node_id = link_configuration_fields['node_id'] - slicename = link_configuration_fields['slicename'] - port = link_configuration_fields['port'] + node_id = link_config['node_id'] + slicename = link_config['slicename'] + port = link_config['port'] # Check not mandatory, they will be done again on the dummynet box if port <= 1024: - return "Port should be > 1024" + return "1 Port should be > 1024" # Get the dummynet box connected to this node nodes = Nodes(self.api, {'node_id': node_id}, ['dummybox_id','nodenetwork_ids']) if not nodes: - return "Node not present" + return "1 Node not present" dummybox_id = nodes[0]['dummybox_id'] if (dummybox_id == 0): # dummybox_id == 0 means empty - return "This node has no dummynet box connected" + return "1 This node has no dummynet box connected" dummyboxes = DummyBoxes(self.api, {'dummybox_id': dummybox_id}, ['ip']) dbox_ip = str(dummyboxes[0]['ip']) @@ -114,34 +114,34 @@ class ConfigureDummynetBox(Method): # Get the node ip address, we need to cross with the NodeNetworks table nodenetwork_id = NodeNetworks(self.api, {'node_id': node_id, 'is_primary':'t'}, ['ip']); if not nodenetwork_id or not nodenetwork_id[0]['ip']: - return "Network not configured on this node" + return "1 Network not configured on this node" node_ip = nodenetwork_id[0]['ip'] # Search the person_id person_id = Persons(self.api, {'email': email}, ['person_id']) if not person_id: - return "User not found" + return "1 User not found" # Search slice information slices = Slices(self.api, {'name': slicename}, ['node_ids', 'person_ids']) if not slices: - return "No slices found" + return "1 No slices found" # Check for permissions: # - the person_id should own the slice # - the slice should be istantiated on the node if not match(slices[0]['node_ids'], node_id) or \ not match(slices[0]['person_ids'], person_id[0]['person_id']): - return "The slice %s and the user %s should be istantiated on the node %s" % \ + return "1 The slice %s and the user %s should be istantiated on the node %s" % \ (slicename, person_id[0]['person_id'], node_id) # Manage the profile upload # if upload_extra-delay is present, we upload the file and use it as profile cmd_line = "" - file_to_upload = pipe_build(link_configuration_fields, "upload_extra-delay", "") + file_to_upload = pipe_build(link_config, "upload_extra-delay", "") if file_to_upload: - cmd_line += "cat " + file_to_upload + " >> " + cmd_line += "cat " + file_to_upload + " | " # start to build the command line # The ssh commands need to use a known hosts file. @@ -159,7 +159,7 @@ class ConfigureDummynetBox(Method): cmd_line += " "+str(node_ip)+" "+slicename+" "+str(port); # add the timeout - cmd = pipe_build(link_configuration_fields, "timeout", "") + cmd = pipe_build(link_config, "timeout", "") cmd_line += " " if not cmd: cmd_line += DEFAULT_TIMEOUT @@ -169,24 +169,26 @@ class ConfigureDummynetBox(Method): # add the filename to upload, "0" if not defined cmd_line += " " if file_to_upload: - cmd_line += file_to_upload + cmd_line += os.path.basename(file_to_upload) else: cmd_line += "0" - # add the extra-delay parameter + # add the extra-delay parameter, only the basename # note that the upload_extra-delay, if present win if file_to_upload: - cmd_line += pipe_build(link_configuration_fields, "upload_extra-delay", " extra-delay ") + link_config['upload_extra-delay'] = os.path.basename(link_config['upload_extra-delay']); + cmd_line += pipe_build(link_config, "upload_extra-delay", " extra-delay ") else: - cmd_line += pipe_build(link_configuration_fields, "extra-delay", " extra-delay ") + link_config['extra-delay'] = os.path.basename(link_config['extra-delay']); + cmd_line += pipe_build(link_config, "extra-delay", " extra-delay ") # add plr, bw, delay, noerror - cmd_line += pipe_build(link_configuration_fields, "plr", " plr ") - cmd_line += pipe_build(link_configuration_fields, "bw", " bw ") - cmd_line += pipe_build(link_configuration_fields, "delay", " delay ") + cmd_line += pipe_build(link_config, "plr", " plr ") + cmd_line += pipe_build(link_config, "bw", " bw ") + cmd_line += pipe_build(link_config, "delay", " delay ") # noerror should be malipulated in a different way - noerror = pipe_build(link_configuration_fields, "noerror", "") + noerror = pipe_build(link_config, "noerror", "") if noerror == '0': cmd_line += " noerror" @@ -197,10 +199,12 @@ class ConfigureDummynetBox(Method): ret = str(command.close()); if (ret == "None"): - ret = "0" + ret = "0 " else: - ret = "1" + ret = "1 " + ret += "The command line used to configure the link follows:\n" + ret += cmd_line ret += " \n" + output return ret -- 2.47.0