import os, subprocess, popen2, string tekko = "xxx.xxx.xxx.xxx" #dev_tekko = "eth3" bs = "xxx.xxx.xxx.xxx" #dev_bs = "eth2" def set_route(req, prov): s = """ Ok """ if not (prov): return "A required parameter is missing, \ please go back and correct the error" if prov == '1': subprocess.call("sudo ip ro ch default via %s metric 1" % (bs), shell=True) subprocess.call("sudo ip ro ch default via %s metric 2" % (tekko), shell=True) # s = """ %s """ % prov elif prov == '2': subprocess.call("sudo ip ro ch default via %s metric 1" % (tekko), shell=True) subprocess.call("sudo ip ro ch default via %s metric 2" % (bs), shell=True) # s = """ %s """ % prov else: s = """ Error """ return s def get_route(req): z, z2 = os.popen2("sudo ip ro") rd = z2.readlines() z.close(); z2.close() for line in rd: k = string.split(line) if k[0] == 'default': if k[2] == bs: pr = '1' elif k[2] == tekko: pr = '2' else: pr = '0' break return pr