Exemple #1
0
    def connectnode(self, ifname, othernode, otherifname):
        """
        Connect a node.

        :param str ifname: name of interface to connect
        :param core.netns.nodes.LxcNode othernode: node to connect to
        :param str otherifname: interface name to connect to
        :return: nothing
        """
        tmplen = 8
        tmp1 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for x in xrange(tmplen)])
        tmp2 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for x in xrange(tmplen)])
        subprocess.check_call([
            constants.IP_BIN, "link", "add", "name", tmp1, "type", "veth",
            "peer", "name", tmp2
        ])

        subprocess.call(
            [constants.IP_BIN, "link", "set", tmp1, "netns",
             str(self.pid)])
        self.cmd([constants.IP_BIN, "link", "set", tmp1, "name", ifname])
        self.addnetif(PyCoreNetIf(self, ifname), self.newifindex())

        subprocess.check_call([
            constants.IP_BIN, "link", "set", tmp2, "netns",
            str(othernode.pid)
        ])
        othernode.cmd(
            [constants.IP_BIN, "link", "set", tmp2, "name", otherifname])
        othernode.addnetif(PyCoreNetIf(othernode, otherifname),
                           othernode.newifindex())
Exemple #2
0
    def connectnode(self, ifname, othernode, otherifname):
        tmplen = 8
        tmp1 = "tmp." + "".join([random.choice(string.ascii_lowercase)
                                 for x in xrange(tmplen)])
        tmp2 = "tmp." + "".join([random.choice(string.ascii_lowercase)
                                 for x in xrange(tmplen)])
        check_call([IP_BIN, "link", "add", "name", tmp1,
                    "type", "veth", "peer", "name", tmp2])

        check_call([IP_BIN, "link", "set", tmp1, "netns", str(self.pid)])
        self.cmd([IP_BIN, "link", "set", tmp1, "name", ifname])
        self.addnetif(PyCoreNetIf(self, ifname), self.newifindex())

        check_call([IP_BIN, "link", "set", tmp2, "netns", str(othernode.pid)])
        othernode.cmd([IP_BIN, "link", "set", tmp2, "name", otherifname])
        othernode.addnetif(PyCoreNetIf(othernode, otherifname),
                           othernode.newifindex())