Exemple #1
0
def app_1():
    unl = UnlServer('172.16.207.20')
    unl.login('admin', 'unl')
    print ("*** CONNECTED TO UNL")
    lab = unl.create_lab(LAB_NAME)
    print ("*** CREATED LAB")
    node_1 = lab.create_node(Router('R1'))
    print ("*** CREATED NODE")
def app_1():
    unl = UnlServer('192.168.247.20')
    unl.login('admin', 'unl')
    print("*** CONNECTED TO UNL")
    lab = unl.create_lab(LAB_NAME)
    print("*** CREATED LAB")
    node_1 = lab.create_node(Router('R1'))
    print("*** CREATED NODE")
Exemple #3
0
 def __init__(self, ip='', user='', pwd='', lab_name=''):
     self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
     if os.environ.get('UNL_IP'):
         self.ip = os.environ.get('UNL_IP')
     self.unl = UnlServer(self.ip)
     self.unl.login(self.user, self.pwd)
     self.lab = None
     self.nodes = dict()
Exemple #4
0
 def __init__(self, ip="", user="", pwd="", lab_name=""):
     self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
     if os.environ.get("UNL_IP"):
         self.ip = os.environ.get("UNL_IP")
     self.unl = UnlServer(self.ip)
     self.unl.login(self.user, self.pwd)
     self.lab = None
     self.nodes = dict()
Exemple #5
0
 def __init__(self, ip='', user='', pwd='', lab_name=''):
     self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
     if os.environ.get('UNL_IP'):
         self.ip = os.environ.get('UNL_IP')
     self.unl = UnlServer(self.ip)
     self.unl.login(self.user, self.pwd)
     self.lab = None
     self.nodes = dict()
Exemple #6
0
def app():
    try:
        unl = UnlServer('10.14.10.153')
        unl.login('admin', 'eve')
        print("*** CONNECTED TO UNL")
        lab = unl.create_lab(LAB_NAME)
        lab.cleanup()
        print("*** CREATED LAB")
        # Creating topology in UnetLab
        nodes = dict()
        for (a_name, a_intf), (b_name, b_intf) in TOPOLOGY.items():
            # Create a mapping between a Node's name and an object
            if not a_name in nodes:

                nodes[a_name] = lab.create_node(Router(a_name))

                print("*** NODE {} CREATED".format(a_name))

            if not b_name in nodes:
                nodes[b_name] = lab.create_node(Router(b_name))
                print("*** NODE {} CREATED".format(b_name))

            # Extract Node objects using their names and connect them
            node_a = nodes[a_name]
            node_b = nodes[b_name]

            node_a.connect_node(a_intf, node_b, b_intf)
            print("*** NODES {0} and {1} ARE CONNECTED".format(a_name, b_name))
        print("*** TOPOLOGY IS BUILT")
        lab.start_all_nodes()
        print("*** NODES STARTED")
        # Reading and pushing configuration
        for node_name in nodes:
            conf = read_file('..\\config\\{}.txt'.format(node_name))
            nodes[node_name].configure(conf)
            print("*** NODE {} CONFIGURED".format(node_name))
            input('PRESS ANY KEY TO STOP THE LAB')
    except Exception as e:
        print("*** APP FAILED : {}".format(e))
    finally:
        print("*** CLEANING UP THE LAB")
Exemple #7
0
class UNetLab(object):

    def __init__(self, ip='', user='', pwd='', lab_name=''):
        self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
        self.unl = UnlServer(self.ip)
        self.unl.login(self.user, self.pwd)
        self.lab = None
        self.nodes = dict()

    def create_lab(self):
        self.lab = self.unl.create_lab(self.lab_name)
        self.lab.cleanup()

    def get_lab(self):
        return self.unl.get_lab(self.lab_name)

    def build_topo(self, topology):
        real_topo = topology.real
        for (a_name, a_intf), (b_name, b_intf) in real_topo.iteritems():
            a_device = Switch(a_name, L2_IMAGE) if 'sw' in a_name.lower() else Router(a_name, L3_IMAGE)
            b_device = Switch(b_name, L2_IMAGE) if 'sw' in b_name.lower() else Router(b_name, L3_IMAGE)
            if a_name not in self.nodes:
                self.nodes[a_name] = self.lab.create_node(a_device)
                # print("*** NODE {} CREATED".format(a_name))
            if b_name not in self.nodes:
                self.nodes[b_name] = self.lab.create_node(b_device)
                # print("*** NODE {} CREATED".format(b_name))
            node_a = self.nodes[a_name]
            node_b = self.nodes[b_name]
            node_a.connect_node(a_intf, node_b, b_intf)
            # print("*** NODES {0} and {1} ARE CONNECTED".format(a_name, b_name))
        return None

    @decorators.timer
    @decorators.progress
    def configure_nodes(self, path):
        import threading
        processes = []
        for node_name in self.nodes:
            conf = 'enable\r configure terminal\r no ip domain-lookup\r'
            conf += file_io.read_txt('{0}/{1}.txt'.format(path, node_name))
            conf += '\rend\r write\r'
            process = threading.Thread(target=self.nodes[node_name].configure, args=(conf,))
            # self.nodes[node_name].configure(conf)
            process.start()
            processes.append(process)
            # print("*** NODE {} CONFIGURED".format(node_name))
        [p.join() for p in processes]
        return None

    def start(self):
        return self.lab.start_all_nodes()

    @decorators.timer
    @decorators.progress
    def destroy(self):
        self.lab = self.get_lab()
        self.lab.cleanup()
        self.unl.delete_lab(self.lab_name)
def app():
    try:
        unl = UnlServer('192.168.247.20')
        unl.login('admin', 'unl')
        print("*** CONNECTED TO UNL")
        lab = unl.create_lab(LAB_NAME)
        lab.cleanup()
        print("*** CREATED LAB")
        # Creating topology in UnetLab
        nodes = dict()
        for (a_name, a_intf), (b_name, b_intf) in TOPOLOGY.iteritems():
            # Create a mapping between a Node's name and an object
            if not a_name in nodes:
                nodes[a_name] = lab.create_node(Router(a_name))
                print("*** NODE {} CREATED".format(a_name))
            if not b_name in nodes:
                nodes[b_name] = lab.create_node(Router(b_name))
                print("*** NODE {} CREATED".format(b_name))
            # Extract Node objects using their names and connect them
            node_a = nodes[a_name]
            node_b = nodes[b_name]
            node_a.connect_node(a_intf, node_b, b_intf)
            print("*** NODES {0} and {1} ARE CONNECTED".format(a_name, b_name))
        print("*** TOPOLOGY IS BUILT")
        lab.start_all_nodes()
        print("*** NODES STARTED")
        # Reading and pushing configuration
        for node_name in nodes:
            conf = read_file('..\\config\\{}.txt'.format(node_name))
            nodes[node_name].configure(conf)
            print("*** NODE {} CONFIGURED".format(node_name))
        raw_input('PRESS ANY KEY TO STOP THE LAB')
    except Exception as e:
        print("*** APP FAILED : {}".format(e))
    finally:
        print("*** CLEANING UP THE LAB")
        lab.cleanup()
        unl.delete_lab(LAB_NAME)
def app():
    unl = UnlServer('192.168.247.20')
    unl.login('admin', 'unl')
    print("*** CONNECTED TO UNL")
    lab = unl.create_lab(LAB_NAME)
    try:
        lab.cleanup()
        print("*** CREATED LAB")
        nodes = dict()
        built_topo(lab, nodes, TOPOLOGY)
        print("*** TOPOLOGY IS BUILT")
        ext_connect(lab, nodes, EXT_NET)
        print("*** CONNECTED TO HOST NETWORK")
        lab.start_all_nodes()
        print("*** NODES STARTED")
        configure_nodes(nodes, CONF_PATH)
        print("*** NODES CONFIGURED")
        raw_input('PRESS ANY KEY TO STOP THE LAB')
    except Exception as e:
        print("*** APP FAILED : {}".format(e))
    finally:
        print("*** CLEANING UP THE LAB")
        lab.cleanup()
        unl.delete_lab(LAB_NAME)
Exemple #10
0
 def __init__(self, ip='', user='', pwd='', lab_name=''):
     self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
     self.unl = UnlServer(self.ip)
     self.unl.login(self.user, self.pwd)
     self.lab = None
     self.nodes = dict()
Exemple #11
0
class UNetLab(object):
    def __init__(self, ip='', user='', pwd='', lab_name=''):
        self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
        if os.environ.get('UNL_IP'):
            self.ip = os.environ.get('UNL_IP')
        self.unl = UnlServer(self.ip)
        self.unl.login(self.user, self.pwd)
        self.lab = None
        self.nodes = dict()

    def create_lab(self):
        self.lab = self.unl.create_lab(self.lab_name)
        self.lab.cleanup()

    def get_lab(self):
        return self.unl.get_lab(self.lab_name)

    def build_topo(self, topology):
        real_topo = topology.real
        intf_conv = file_io.read_yaml(INTF_CONV_FILE)
        for ((a_name, a_intf), (b_name, b_intf)) in real_topo:
            a_device = Switch(a_name,
                              L2_IMAGE) if 'sw' in a_name.lower() else Router(
                                  a_name, L3_IMAGE)
            b_device = Switch(b_name,
                              L2_IMAGE) if 'sw' in b_name.lower() else Router(
                                  b_name, L3_IMAGE)
            if a_name not in self.nodes:
                self.nodes[a_name] = self.lab.create_node(a_device)
                # print("*** NODE {} CREATED".format(a_name))
            if b_name not in self.nodes:
                self.nodes[b_name] = self.lab.create_node(b_device)
                # print("*** NODE {} CREATED".format(b_name))
            node_a = self.nodes[a_name]
            node_b = self.nodes[b_name]
            if intf_conv.get(a_name, {}).get(a_intf, None):
                a_intf_lab = intf_conv[a_name][a_intf]
            else:
                a_intf_lab = node_a.get_next_intf()
            if intf_conv.get(b_name, {}).get(b_intf, None):
                b_intf_lab = intf_conv[b_name][b_intf]
            else:
                b_intf_lab = node_b.get_next_intf()
            intf_conv.setdefault(a_name, {})[a_intf] = a_intf_lab
            intf_conv.setdefault(b_name, {})[b_intf] = b_intf_lab
            node_a.connect_node(a_intf_lab, node_b, b_intf_lab)
            # print("*** NODES {} and {} ARE CONNECTED".format(a_name, b_name))
        file_io.write_yaml(INTF_CONV_FILE, intf_conv)
        return None

    def ext_connect(self, topo):
        ext_topo = topo.ext_net
        intf_conv = file_io.read_yaml(INTF_CONV_FILE)
        for (node_name, node_intf), pnet in ext_topo.iteritems():
            ext_net = self.lab.create_net('cloud', net_type=pnet)
            the_node = self.nodes[node_name]
            node_intf_lab = the_node.get_next_intf()
            the_node.connect_interface(node_intf_lab, ext_net)
            intf_conv.setdefault(node_name, {})[node_intf] = node_intf_lab
        file_io.write_yaml(INTF_CONV_FILE, intf_conv)
        return None

    @decorators.timer
    @decorators.progress
    def configure_nodes(self, path):
        import threading
        processes = []
        for node_name in self.nodes:
            conf = 'no\renable\r configure terminal\r no ip domain-lookup\r'
            conf += file_io.read_txt('{0}/{1}.txt'.format(path, node_name))
            conf += '\rend\r write\r'
            process = threading.Thread(target=self.nodes[node_name].configure,
                                       args=(conf, ))
            # self.nodes[node_name].configure(conf)
            process.start()
            processes.append(process)
            # print("*** NODE {} CONFIGURED".format(node_name))
        [p.join() for p in processes]
        return None

    def start(self):
        return self.lab.start_all_nodes()

    @decorators.timer
    @decorators.progress
    def destroy(self):
        self.lab = self.get_lab()
        self.lab.cleanup()
        self.unl.delete_lab(self.lab_name)
Exemple #12
0
class UNetLab(object):
    def __init__(self, ip="", user="", pwd="", lab_name=""):
        self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
        if os.environ.get("UNL_IP"):
            self.ip = os.environ.get("UNL_IP")
        self.unl = UnlServer(self.ip)
        self.unl.login(self.user, self.pwd)
        self.lab = None
        self.nodes = dict()

    def create_lab(self):
        self.lab = self.unl.create_lab(self.lab_name)
        self.lab.cleanup()

    def get_lab(self):
        return self.unl.get_lab(self.lab_name)

    def build_topo(self, topology):
        real_topo = topology.real
        intf_conv = file_io.read_yaml(INTF_CONV_FILE)
        for ((a_name, a_intf), (b_name, b_intf)) in real_topo:
            a_device = Switch(a_name, L2_IMAGE) if "sw" in a_name.lower() else Router(a_name, L3_IMAGE)
            b_device = Switch(b_name, L2_IMAGE) if "sw" in b_name.lower() else Router(b_name, L3_IMAGE)
            if a_name not in self.nodes:
                self.nodes[a_name] = self.lab.create_node(a_device)
                # print("*** NODE {} CREATED".format(a_name))
            if b_name not in self.nodes:
                self.nodes[b_name] = self.lab.create_node(b_device)
                # print("*** NODE {} CREATED".format(b_name))
            node_a = self.nodes[a_name]
            node_b = self.nodes[b_name]
            if intf_conv.get(a_name, {}).get(a_intf, None):
                a_intf_lab = intf_conv[a_name][a_intf]
            else:
                a_intf_lab = node_a.get_next_intf()
            if intf_conv.get(b_name, {}).get(b_intf, None):
                b_intf_lab = intf_conv[b_name][b_intf]
            else:
                b_intf_lab = node_b.get_next_intf()
            intf_conv.setdefault(a_name, {})[a_intf] = a_intf_lab
            intf_conv.setdefault(b_name, {})[b_intf] = b_intf_lab
            node_a.connect_node(a_intf_lab, node_b, b_intf_lab)
            # print("*** NODES {} and {} ARE CONNECTED".format(a_name, b_name))
        file_io.write_yaml(INTF_CONV_FILE, intf_conv)
        return None

    def ext_connect(self, topo):
        ext_topo = topo.ext_net
        intf_conv = file_io.read_yaml(INTF_CONV_FILE)
        for (node_name, node_intf), pnet in ext_topo.iteritems():
            ext_net = self.lab.create_net("cloud", net_type=pnet)
            the_node = self.nodes[node_name]
            node_intf_lab = the_node.get_next_intf()
            the_node.connect_interface(node_intf_lab, ext_net)
            intf_conv.setdefault(node_name, {})[node_intf] = node_intf_lab
        file_io.write_yaml(INTF_CONV_FILE, intf_conv)
        return None

    @decorators.timer
    @decorators.progress
    def configure_nodes(self, path):
        import threading

        processes = []
        for node_name in self.nodes:
            conf = "no\renable\r configure terminal\r no ip domain-lookup\r"
            conf += file_io.read_txt("{0}/{1}.txt".format(path, node_name))
            conf += "\rend\r write\r"
            process = threading.Thread(target=self.nodes[node_name].configure, args=(conf,))
            # self.nodes[node_name].configure(conf)
            process.start()
            processes.append(process)
            # print("*** NODE {} CONFIGURED".format(node_name))
        [p.join() for p in processes]
        return None

    def start(self):
        return self.lab.start_all_nodes()

    @decorators.timer
    @decorators.progress
    def destroy(self):
        self.lab = self.get_lab()
        self.lab.cleanup()
        self.unl.delete_lab(self.lab_name)
Exemple #13
0
class UNetLab(object):
    def __init__(self, ip='', user='', pwd='', lab_name=''):
        self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
        self.unl = UnlServer(self.ip)
        self.unl.login(self.user, self.pwd)
        self.lab = None
        self.nodes = dict()

    def create_lab(self):
        self.lab = self.unl.create_lab(self.lab_name)
        self.lab.cleanup()

    def get_lab(self):
        return self.unl.get_lab(self.lab_name)

    def build_topo(self, topology):
        real_topo = topology.real
        for (a_name, a_intf), (b_name, b_intf) in real_topo.iteritems():
            a_device = Switch(a_name,
                              L2_IMAGE) if 'sw' in a_name.lower() else Router(
                                  a_name, L3_IMAGE)
            b_device = Switch(b_name,
                              L2_IMAGE) if 'sw' in b_name.lower() else Router(
                                  b_name, L3_IMAGE)
            if a_name not in self.nodes:
                self.nodes[a_name] = self.lab.create_node(a_device)
                # print("*** NODE {} CREATED".format(a_name))
            if b_name not in self.nodes:
                self.nodes[b_name] = self.lab.create_node(b_device)
                # print("*** NODE {} CREATED".format(b_name))
            node_a = self.nodes[a_name]
            node_b = self.nodes[b_name]
            node_a.connect_node(a_intf, node_b, b_intf)
            # print("*** NODES {0} and {1} ARE CONNECTED".format(a_name, b_name))
        return None

    @decorators.timer
    @decorators.progress
    def configure_nodes(self, path):
        import threading
        processes = []
        for node_name in self.nodes:
            conf = 'enable\r configure terminal\r no ip domain-lookup\r'
            conf += file_io.read_txt('{0}/{1}.txt'.format(path, node_name))
            conf += '\rend\r write\r'
            process = threading.Thread(target=self.nodes[node_name].configure,
                                       args=(conf, ))
            # self.nodes[node_name].configure(conf)
            process.start()
            processes.append(process)
            # print("*** NODE {} CONFIGURED".format(node_name))
        [p.join() for p in processes]
        return None

    def start(self):
        return self.lab.start_all_nodes()

    @decorators.timer
    @decorators.progress
    def destroy(self):
        self.lab = self.get_lab()
        self.lab.cleanup()
        self.unl.delete_lab(self.lab_name)
Exemple #14
0
 def __init__(self, ip='', user='', pwd='', lab_name=''):
     self.ip, self.user, self.pwd, self.lab_name = ip, user, pwd, lab_name
     self.unl = UnlServer(self.ip)
     self.unl.login(self.user, self.pwd)
     self.lab = None
     self.nodes = dict()