Exemplo n.º 1
0
def setupHosts(host):
        print "working on host %s\n" %host
        fixed_ip= fxdict[host]
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(fixed_ip, username=u_dict.get(host, vm_user_name), key_filename=private_key_file)
        time.sleep(3)
        # running the ovs commands
        count = 0
        connectip = ''
        vlni = 0
        vnlilist = []
        for keys in topology.keys():
            # this 'hosts' is every node consisting of triplette or switch name for that switch
            for hosts in topology[keys]:
                # if true, this is a triplette belonging to this desired host
                if (hosts[0] == host):
                    # third element is the bridge name
                    try:
                        if hosts[2]:
                            bridge_name = hosts[2]
                    except:
                        bridge_name = 'br%s' % count
                    stdin, stdout, stderr = ssh.exec_command("sudo ovs-vsctl get interface p%s mac_in_use" % (count));
                    mac=(''.join(stdout.readlines())).strip("\n")
                    print "mac of %s is %s" %(hosts[1], mac)
                    ports.setdefault(hosts[1], {})
                    ports[hosts[1]]['mac']=mac
                    connectip = fxdict[keys]
                    #vlni = int(keys[2]) + int(host[1]) + (2*numSwitches) + 10
                    #vlni += vnlilist.count(vlni)
                    #vnlilist.append(vlni)
                    vlni = _get_vni(keys, host)
                    count += 1
        ssh.close()
Exemplo n.º 2
0
def setupHosts(host):
        print "working on host: %s\n" %host
        fixed_ip= fxdict[host]
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(fixed_ip, username=u_dict.get(host, vm_user_name), key_filename=private_key_file)
        time.sleep(3)
        # running the ovs commands
        count = 0
        connectip = ''
        vlni = 0
        vnlilist = []
        for keys in topology.keys():
            # this 'hosts' is every node consisting of triplette or switch name for that switch
            for hosts in topology[keys]:
                # if true, this is a triplette belonging to this desired host
                if (hosts[0] == host):
                    # third element is the bridge name
                    try:
                        if hosts[2]:
                            bridge_name = hosts[2]
                    except:
                        bridge_name = 'br%s' % count
                    #ssh.exec_command("sudo ovs-vsctl del-br %s" % bridge_name)
                    #time.sleep(1)
                    ssh.exec_command("sudo ovs-vsctl -- --may-exist add-br %s" % bridge_name)
                    time.sleep(1)
                    ssh.exec_command("sudo ovs-vsctl -- --may-exist add-port %s p%s -- set interface p%s type=internal" % (bridge_name,count, count))
                    time.sleep(1)
                    ssh.exec_command("mac=`sudo ovs-vsctl get interface p%s mac_in_use`;sudo ovs-vsctl set interface p%s mac=\"$mac\"" % (count, count));
                    if (hosts[1] != "None" or hosts[1] != "none"):
                        ssh.exec_command("sudo ifconfig p%s %s/24 up" %(count, hosts[1]))
                        time.sleep(1)
                    connectip = fxdict[keys]
                    #vlni = int(keys[2]) + int(host[1]) + (2*numSwitches) + 10
                    #vlni += vnlilist.count(vlni)
                    #vnlilist.append(vlni)
                    vlni = _get_vni(keys, host)
                    ssh.exec_command("sudo ovs-vsctl -- --may-exist add-port %s vxlan%s -- set interface vxlan%s type=vxlan options:remote_ip=%s options:key=%s" % (bridge_name,vlni,vlni,connectip,vlni))
                    time.sleep(1)
                    count += 1
        ssh.close()
Exemplo n.º 3
0
def setupHosts(host):
    print "working on host %s\n" % host
    fixed_ip = fxdict[host]
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(fixed_ip,
                username=u_dict.get(host, vm_user_name),
                key_filename=private_key_file)
    time.sleep(3)
    # running the ovs commands
    count = 0
    connectip = ''
    vlni = 0
    vnlilist = []
    for keys in topology.keys():
        # this 'hosts' is every node consisting of triplette or switch name for that switch
        for hosts in topology[keys]:
            # if true, this is a triplette belonging to this desired host
            if (hosts[0] == host):
                # third element is the bridge name
                try:
                    if hosts[2]:
                        bridge_name = hosts[2]
                except:
                    bridge_name = 'br%s' % count
                stdin, stdout, stderr = ssh.exec_command(
                    "sudo ovs-vsctl get interface p%s mac_in_use" % (count))
                mac = (''.join(stdout.readlines())).strip("\n")
                print "mac of %s is %s" % (hosts[1], mac)
                ports.setdefault(hosts[1], {})
                ports[hosts[1]]['mac'] = mac
                connectip = fxdict[keys]
                #vlni = int(keys[2]) + int(host[1]) + (2*numSwitches) + 10
                #vlni += vnlilist.count(vlni)
                #vnlilist.append(vlni)
                vlni = _get_vni(keys, host)
                count += 1
    ssh.close()
Exemplo n.º 4
0
def setupSwitch(switch):
        fixed_ip= fxdict[switch]
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(fixed_ip, username=vm_user_name, key_filename=private_key_file)
        time.sleep(15)
        # running the ovs commands
        if switch not in nodes:
            print "Switch %s was not defined in 'nodes', setting up using default ovs commands" % switch
        bridge_name = 'br1'
        if 'bridge_name' in nodes[switch]:
            bridge_name = nodes[switch]['bridge_name']
        ssh.exec_command("sudo ovs-vsctl add-br %s" % bridge_name)
        time.sleep(2)
        if 'contr_addr' in nodes[switch]:
            ssh.exec_command("sudo ovs-vsctl set-controller %s tcp:%s" % (bridge_name, nodes[switch]['contr_addr']))
            time.sleep(1)
        if 'int_ip' in nodes[switch]:
            int_ip_name = nodes[switch]['int_ip'][0]
            int_ip = nodes[switch]['int_ip'][1]
            ssh.exec_command("sudo ovs-vsctl add-port %s %s -- set interface %s type=internal" % (bridge_name,int_ip_name, int_ip_name))
            time.sleep(1)     
            ssh.exec_command("sudo ifconfig %s %s/24 up" %(int_ip_name, int_ip))
            time.sleep(1) 
        ssh.exec_command("sudo ovs-vsctl set-fail-mode %s secure" % bridge_name)
        time.sleep(1)
        ssh.exec_command("sudo ovs-vsctl set controller %s connection-mode=out-of-band"% bridge_name)
        time.sleep(1) 
        # this will hold the internal ip for use in the vxlan set up
        connectip = ''
        # this is used for the vxlan count and VLNI number (this must be the same on both sides)
        vlni = 0
        # used to implement a different VLNI number. For the cases of multiple connections to the same node
        vnlilist = []
        # this 'host' is every node consisting of triplette or switch name for that switch
        for host in topology[switch]:
            # handle hosts 
            if isinstance(host, tuple):
                vlni = int(host[0][1]) + int(switch[2]) + (2*numSwitches) + 10
                vlni += vnlilist.count(vlni)
                vnlilist.append(vlni)
                connectip = fxdict[host[0]]
            # handle switches
            else: 
                vlni = int(host[2]) + int(switch[2]) + 10
                vlni += vnlilist.count(vlni)
                vnlilist.append(vlni)
                connectip = fxdict[host]
            ssh.exec_command("sudo ovs-vsctl add-port %s vxlan%s -- set interface vxlan%s type=vxlan options:remote_ip=%s options:key=%s" % (bridge_name,vlni,vlni,connectip,vlni))
            time.sleep(1)
        # establishes all the other connections to this switch 
        for keys in topology.keys():
            for host in topology[keys]:
                if (host == switch):
                    connectip = fxdict[keys]
                    vlni = int(keys[2]) + int(switch[2]) + 10 
                    vlni += vnlilist.count(vlni)
                    vnlilist.append(vlni)
                    ssh.exec_command("sudo ovs-vsctl add-port %s vxlan%s -- set interface vxlan%s type=vxlan options:remote_ip=%s options:key=%s" % (bridge_name, vlni, vlni,connectip, vlni))
                    time.sleep(1)
        ssh.close()
Exemplo n.º 5
0
"""
Here we parse the 'topology' dictionary found inside topology.py and extract 
a list 'nodeList' which stores the names of every Node
"""
# parse the user topology
valuelist = []
for values in topology.values():
    for tuples in values:
        # we only want the hosts 
        if isinstance(tuples, tuple):
            if ((tuples[0][0] == 'h' or tuples[0][0] == 'H') and tuples[0] not in valuelist):
                valuelist.append(tuples[0])

numHosts = len(valuelist)
numSwitches = len(topology.keys())
numNodes = numHosts + numSwitches

# this list contains the switch names and host names
nodeList = []
# start off by appending the switche names
for key in topology.keys():
    if (key not in nodeList):
        nodeList.append(key)

# this list only holds the host names (used to append into the nodeList)
hostList = []
for values in topology.values():
    for tuples in values:
        if isinstance(tuples, tuple):
            if ((tuples[0][0] == 'h' or tuples[0][0] == 'H') and tuples[0] not in hostList):
Exemplo n.º 6
0
def setupSwitch(switch):
        print "working on switch %s\n" %switch
        fixed_ip= fxdict[switch]
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(fixed_ip, username=u_dict.get(switch, vm_user_name), key_filename=private_key_file)
        time.sleep(2)
        # running the ovs commands
        if switch not in nodes:
            print "Switch %s was not defined in 'nodes', setting up using default ovs commands" % switch
        bridge_name = 'br1'
        if 'bridge_name' in nodes[switch]:
            bridge_name = nodes[switch]['bridge_name']
        stdin, stdout, stderr = ssh.exec_command("sudo ovs-vsctl get bridge %s datapath_id" % bridge_name)
        stdin.close()
        dpid=(''.join(stdout.readlines())).strip("\n");
        print "datapath_id of %s is %s\n" %(bridge_name, dpid)
        time.sleep(1)
        if 'int_ip' in nodes[switch]:
            int_ip_name = nodes[switch]['int_ip'][0]
            int_ip = nodes[switch]['int_ip'][1]
            #ssh.exec_command("sudo ovs-vsctl add-port %s %s -- set interface %s type=internal " % (bridge_name,int_ip_name, int_ip_name))
            #time.sleep(1)     
            stdin, stdout, stderr = ssh.exec_command("sudo ovs-vsctl get interface %s mac_in_use" % (int_ip_name));
            stdin.close()
            stdin2, stdout2, stderr2 = ssh.exec_command("sudo ovs-vsctl get interface %s ofport" % (int_ip_name));
            stdin.close()
            mac=(''.join(stdout.readlines())).strip("\n")
            of_port=(''.join(stdout2.readlines())).strip("\n")
            print "mac of %s is %s, of port is %s\n" %(int_ip, mac, of_port)
            ports.setdefault(int_ip, {})
            ports[int_ip]['dpid']=dpid
            ports[int_ip]['mac']=mac
            ports[int_ip]['of_port']=of_port
            time.sleep(1) 
        # this will hold the internal ip for use in the vxlan set up
        connectip = ''
        # this is used for the vxlan count and VLNI number (this must be the same on both sides)
        vlni = 0
        # used to implement a different VLNI number. For the cases of multiple connections to the same node
        vnlilist = []
        # this 'host' is every node consisting of triplette or switch name for that switch
        for host in topology[switch]:
            # handle hosts 
            if isinstance(host, tuple):
                #vlni = int(host[0][1]) + int(switch[2]) + (2*numSwitches) + 10
                #vlni += vnlilist.count(vlni)
                #vnlilist.append(vlni)
                vlni = _get_vni(host[0], switch)
                connectip = fxdict[host[0]]
                ip_of_port = host[1] 
                stdin, stdout, stderr = ssh.exec_command("sudo ovs-vsctl get interface vxlan%s ofport" % (vlni))
                stdin.close()
                of_port=(''.join(stdout.readlines())).strip("\n")
                print "of port to %s is %s\n" %(ip_of_port, of_port)
                ports.setdefault(ip_of_port, {})
                ports[ip_of_port]['dpid']=dpid
                ports[ip_of_port]['of_port']=of_port
            # handle switches
            else: 
                #vlni = int(host[2]) + int(switch[2]) + 10
                #vlni += vnlilist.count(vlni)
                #vnlilist.append(vlni)
                vlni = _get_vni(host, switch)
                connectip = fxdict[host]
            time.sleep(1)
        # establishes all the other connections to this switch 
        for keys in topology.keys():
            for host in topology[keys]:
                if (host == switch):
                    connectip = fxdict[keys]
                    #vlni = int(keys[2]) + int(switch[2]) + 10 
                    #vlni += vnlilist.count(vlni)
                    #vnlilist.append(vlni)
                    vlni = _get_vni(keys, switch)
                    #ssh.exec_command("sudo ovs-vsctl add-port %s vxlan%s -- set interface vxlan%s type=vxlan options:remote_ip=%s options:key=%s" % (bridge_name, vlni, vlni,connectip, vlni))
                    stdin, stdout, stderr = ssh.exec_command("sudo ovs-vsctl get interface vxlan%s ofport" % (vlni))
                    stdin.close()
                    print "of port to %s is %s\n" %(connectip, (''.join(stdout.readlines())))
                    time.sleep(1)
        ssh.close()
Exemplo n.º 7
0
from config import region_name
from config import user, password, auth_url, instance_name, tenant_name

if len(sys.argv) > 1:
    instance_name = sys.argv[1] 

valuelist = []
for values in topology.values():
    for tuples in values:
        # we only want the hosts
        if isinstance(tuples, tuple):
            if ((tuples[0][0] == 'h' or tuples[0][0] == 'H') and tuples[0] not in valuelist):
                valuelist.append(tuples[0])

numHosts = len(valuelist)
numSwitches = len(topology.keys())
numNodes = numHosts + numSwitches

# this list contains the switch names and host names
nodeList = []
# start off by appending the switche names
for key in topology.keys():
    if (key not in nodeList):
        nodeList.append(key)

# this list only holds the host names (used to append into the nodeList)
hostList = []
for values in topology.values():
    for tuples in values:
        if isinstance(tuples, tuple):
            if ((tuples[0][0] == 'h' or tuples[0][0] == 'H') and tuples[0] not in hostList):
Exemplo n.º 8
0
def setupSwitch(switch):
    print "working on switch %s\n" % switch
    fixed_ip = fxdict[switch]
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(fixed_ip,
                username=u_dict.get(switch, vm_user_name),
                key_filename=private_key_file)
    time.sleep(2)
    # running the ovs commands
    if switch not in nodes:
        print "Switch %s was not defined in 'nodes', setting up using default ovs commands" % switch
    bridge_name = 'br1'
    if 'bridge_name' in nodes[switch]:
        bridge_name = nodes[switch]['bridge_name']
    stdin, stdout, stderr = ssh.exec_command(
        "sudo ovs-vsctl get bridge %s datapath_id" % bridge_name)
    stdin.close()
    dpid = (''.join(stdout.readlines())).strip("\n")
    print "datapath_id of %s is %s\n" % (bridge_name, dpid)
    time.sleep(1)
    if 'int_ip' in nodes[switch]:
        int_ip_name = nodes[switch]['int_ip'][0]
        int_ip = nodes[switch]['int_ip'][1]
        #ssh.exec_command("sudo ovs-vsctl add-port %s %s -- set interface %s type=internal " % (bridge_name,int_ip_name, int_ip_name))
        #time.sleep(1)
        stdin, stdout, stderr = ssh.exec_command(
            "sudo ovs-vsctl get interface %s mac_in_use" % (int_ip_name))
        stdin.close()
        stdin2, stdout2, stderr2 = ssh.exec_command(
            "sudo ovs-vsctl get interface %s ofport" % (int_ip_name))
        stdin.close()
        mac = (''.join(stdout.readlines())).strip("\n")
        of_port = (''.join(stdout2.readlines())).strip("\n")
        print "mac of %s is %s, of port is %s\n" % (int_ip, mac, of_port)
        ports.setdefault(int_ip, {})
        ports[int_ip]['dpid'] = dpid
        ports[int_ip]['mac'] = mac
        ports[int_ip]['of_port'] = of_port
        time.sleep(1)
    # this will hold the internal ip for use in the vxlan set up
    connectip = ''
    # this is used for the vxlan count and VLNI number (this must be the same on both sides)
    vlni = 0
    # used to implement a different VLNI number. For the cases of multiple connections to the same node
    vnlilist = []
    # this 'host' is every node consisting of triplette or switch name for that switch
    for host in topology[switch]:
        # handle hosts
        if isinstance(host, tuple):
            #vlni = int(host[0][1]) + int(switch[2]) + (2*numSwitches) + 10
            #vlni += vnlilist.count(vlni)
            #vnlilist.append(vlni)
            vlni = _get_vni(host[0], switch)
            connectip = fxdict[host[0]]
            ip_of_port = host[1]
            stdin, stdout, stderr = ssh.exec_command(
                "sudo ovs-vsctl get interface vxlan%s ofport" % (vlni))
            stdin.close()
            of_port = (''.join(stdout.readlines())).strip("\n")
            print "of port to %s is %s\n" % (ip_of_port, of_port)
            ports.setdefault(ip_of_port, {})
            ports[ip_of_port]['dpid'] = dpid
            ports[ip_of_port]['of_port'] = of_port
        # handle switches
        else:
            #vlni = int(host[2]) + int(switch[2]) + 10
            #vlni += vnlilist.count(vlni)
            #vnlilist.append(vlni)
            vlni = _get_vni(host, switch)
            connectip = fxdict[host]
        time.sleep(1)
    # establishes all the other connections to this switch
    for keys in topology.keys():
        for host in topology[keys]:
            if (host == switch):
                connectip = fxdict[keys]
                #vlni = int(keys[2]) + int(switch[2]) + 10
                #vlni += vnlilist.count(vlni)
                #vnlilist.append(vlni)
                vlni = _get_vni(keys, switch)
                #ssh.exec_command("sudo ovs-vsctl add-port %s vxlan%s -- set interface vxlan%s type=vxlan options:remote_ip=%s options:key=%s" % (bridge_name, vlni, vlni,connectip, vlni))
                stdin, stdout, stderr = ssh.exec_command(
                    "sudo ovs-vsctl get interface vxlan%s ofport" % (vlni))
                stdin.close()
                print "of port to %s is %s\n" % (connectip,
                                                 (''.join(stdout.readlines())))
                time.sleep(1)
    ssh.close()