def startwork(config=None, logger=None): """Main start """ fullURL = getFullUrl(config) agents = getDataFromSiteFE({}, fullURL, "/sitefe/json/frontend/ips") if agents[2] != 'OK': print 'Received a failure getting information from Site Frontend %s' % str( agents) return workDir = config.get('frontend', 'privatedir') + "/forwardingService/" createDirs(workDir) copy2("/etc/httpd/conf.d/sitefe-httpd.conf", str(workDir + "httpd-copy.conf")) httpdCopy = readFile(str(workDir + "httpd-copy.conf")) try: newDict = evaldict(agents[0]) except FailedToParseError as ex: print 'Server returned not a json loadable object. Raising error. Output %s. Errors: %s' % ( str(agents), ex) return if not newDict: print 'Seems server returned empty dictionary. Exiting.' return newOut, changed = prepareNewHTTPDConfig(newDict, httpdCopy) if changed: writeNewConfig(newOut, workDir) copy2(str(workDir + "httpd-new.conf"), "/etc/httpd/conf.d/sitefe-httpd.conf") stdout = externalCommand("service httpd restart") print stdout # Restart apache... return
def executeCmd(command, logger): """ Execute interfaces commands. """ logger.info('Asked to execute %s command' % command) cmdOut = externalCommand(command, False) out, err = cmdOut.communicate() msg = 'Command: %s, Out: %s, Err: %s, ReturnCode: %s' % (command, out.rstrip(), err.rstrip(), cmdOut.returncode) logger.info(msg) return out.rstrip(), err.rstrip(), cmdOut.returncode
def rapidping(inputDict): """Return arptable for specific vlan""" # TODO Checks: # Interface is available; command = "ping -i 0.001 -w %s %s -s 1024 -I %s" % ( inputDict['time'], inputDict['ip'], inputDict['interface']) cmdOut = externalCommand(command, False) out, err = cmdOut.communicate() return out.decode("utf-8"), err.decode("utf-8"), cmdOut.returncode
def iperfserver(inputDict): """Run IPerf Server """ # TODO Checks: # Port is not used # Use python library (iperf3 pip) command = "timeout %s iperf3 --server -p %s --bind %s %s" % ( inputDict['time'], inputDict['port'], inputDict['ip'], '-1' if inputDict['onetime'] == 'True' else '') cmdOut = externalCommand(command, False) out, err = cmdOut.communicate() return out.decode("utf-8"), err.decode("utf-8"), cmdOut.returncode
def arptable(inputDict): """Return arptable for specific vlan""" command = "ip neigh" cmdOut = externalCommand(command, False) out, err = cmdOut.communicate() retOut = [] for line in out.decode("utf-8").split('\n'): splLine = line.split(' ') if len(splLine) > 4 and splLine[2] == inputDict['interface']: retOut.append(line) return retOut, err.decode("utf-8"), cmdOut.returncode
def iperf(inputDict): """Run TCP IPerf """ # TODO Checks: # IP Is valid; # Ping works; # Telnet to default port works (5201) command = "iperf3 -c %s -B %s -t %s" % ( inputDict['ip'], inputDict['interface'], inputDict['time']) cmdOut = externalCommand(command, False) out, err = cmdOut.communicate() return out.decode("utf-8"), err.decode("utf-8"), cmdOut.returncode