Exemplo n.º 1
0
def open_log(logfile):
    dir = os.path.dirname(logfile)
    cmd = 'mkdir -p ' + dir
    shell.call_prog_as_is(cmd)
    log = open(logfile, 'a')
    date = time.strftime("%H:%M:%S")
    dash = ""
    for i in range(0, 79):
        dash += "-"
    write_log(log, dash)
    write_log(log, "Logfile " + logfile + " opened at " + date)
    write_log(log, dash)
    return log
Exemplo n.º 2
0
def is_alive(host):
    cmd = "ping -c 1 " + host
    outstr = shell.call_prog_as_is(cmd)
    if (outstr.find("64 bytes from") == -1):
        return False
    else:
        return True
Exemplo n.º 3
0
def main(argc, argv):
    ovs_path, hostname, os_release, logfile, br, vlan_id = ovs_helper.set_defaults(
        home, progname)
    try:
        opts, args = getopt.getopt(argv, "Chs:i:t:T:l:r:n:")
    except getopt.GetoptError as err:
        print progname + ": invalid argument, " + str(err)
        usage()

    vm_ip_local = ""
    port_type = ""
    mgmt_iface = ""
    tnl_type = ""
    rtep_ip = ""
    n_tunnels = 0
    for opt, arg in opts:
        if opt == "-s":
            ovs_sb = arg
            OVS_DIR = home + "/Linux/src/sandbox/" + ovs_sb + "/VCA"
            ovs_path = OVS_DIR + "/utilities"
        elif opt == "-C":
            cmd = "ovs-vsctl show | grep Port | grep -v alubr0 | grep -v svc | awk '{print $2}' | sed 's/\"//g'"
            port_list = shell.call_prog_as_is(cmd)
            for port in port_list.splitlines():
                cmd = "ovs-vsctl del-port " + port
                print "Running " + cmd
                shell.call_prog_as_is(cmd)
            sys.exit(1)
        elif opt == "-i":
            mgmt_iface = arg
        elif opt == "-t":
            port_type = arg
        elif opt == "-l":
            vm_ip_local = arg
        elif opt == "-T":
            Topt_tok = arg.split(":")
            tnl_type = Topt_tok[0]
            rtep_ip = Topt_tok[1]
            tnl_key = ovs_helper.set_tnl_key(tnl_type)
        elif opt == "-r":
            vm_ip_remote = arg
        elif opt == "-n":
            n_tunnels = int(arg)
        elif opt == "-h":
            usage()

    logfd = logger.open_log(logfile)
    bridge = ovs_bridge.Bridge(ovs_path, br, logfd)
    mgmt_ip = net.get_iface_ip(mgmt_iface)
    vm_iface = ovs_helper.set_vm_iface(mgmt_iface, port_type)

    if (len(vm_ip_local) == 0):
        print(progname + ": Need value of local VM IP address")
        usage()
    if (len(rtep_ip) == 0):
        print(progname + ": Need value of RTEP IP address")
        usage()
    if (len(port_type) == 0):
        print(progname + ": Need value of port type")
        usage()
    if (len(tnl_type) == 0):
        print(progname + ": Need value of tunnel type")
        usage()
    if (len(tnl_key) == 0):
        print(progname + ": Tunnel key not set, specify tunnel type")
        usage()
    if (len(mgmt_iface) == 0):
        print(progname + ": Need value of management interface")
        usage()
    if (port_type != "internal" and port_type != "vlan"):
        print(progname + ": Need a supported type of port")
        exit(1)

    ovs_helper.print_defaults(ovs_path, os_release, hostname, logfile)
    time.sleep(2)

    for x in range(0, n_tunnels):
        key = tnl_key + str(x)
        print "ITERATION: " + str(x) + ", key: " + key
        rtep = ovs_vport_tnl.Tunnel(ovs_path, br, tnl_type, key, rtep_ip,
                                    "rtep", logfd, True)
        rtep_port = rtep.get_tnl_name()
        ltep = ovs_vport_tnl.Tunnel(ovs_path, br, tnl_type, key, mgmt_ip,
                                    "ltep", logfd, True)
        ltep_port = ltep.get_tnl_name()
        print "Created rtep_port " + rtep_port + " ltep_port " + ltep_port + " with tnl_key " + key
        if (x % 2) == 0:
            print "Deleting rtep_port " + rtep_port
            rtep.destroy()
            print "Deleting ltep_port " + ltep_port
            ltep.destroy()
        if (process.proc_exists("ovs-vswitchd") == False
                or process.n_procs_by_name("ovs-vswitchd") < 2):
            print "ovs-vswitchd not found, exitting"
            sys.exit(1)
        print
        time.sleep(2)
Exemplo n.º 4
0
 def __show_dhcp_evpn_ovsdb_table(self, table):
     print "Content of table: " + table
     cmd = '/usr/bin/ovsdb-client transact \'["Open_vSwitch", {"op" : "select", "table" : "' + table + '", "where" : [] } ]\''
     output = shell.call_prog_as_is(cmd)
     parsed = json.loads(output)
     print json.dumps(parsed, indent=4, sort_keys=True)
Exemplo n.º 5
0
def getent(host):
    outstr = shell.call_prog_as_is('getent hosts ' + host).replace("\n", "")
    return outstr.split(" ")[0]