Ejemplo n.º 1
0
    def linknet(self, net: CoreNetworkBase) -> CoreInterface:
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.

        :param net: network to link with
        :return: created interface
        """
        sessionid = self.session.short_session_id()
        try:
            _id = f"{self.id:x}"
        except TypeError:
            _id = str(self.id)
        try:
            net_id = f"{net.id:x}"
        except TypeError:
            net_id = str(net.id)
        localname = f"veth{_id}.{net_id}.{sessionid}"
        name = f"veth{net_id}.{_id}.{sessionid}"
        iface = Veth(self.session, name, localname)
        if self.up:
            iface.startup()
        self.attach(iface)
        if net.up and net.brname:
            iface.net_client.set_iface_master(net.brname, iface.name)
        i = net.next_iface_id()
        net.ifaces[i] = iface
        with net.linked_lock:
            net.linked[iface] = {}
        iface.net = self
        iface.othernet = net
        return iface
Ejemplo n.º 2
0
    def linknet(self, net):
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.

        :param core.netns.vnet.LxBrNet net: network to link with
        :return: created interface
        :rtype: Veth
        """
        sessionid = self.session.short_session_id()
        try:
            _id = "%x" % self.id
        except TypeError:
            _id = "%s" % self.id

        try:
            net_id = "%x" % net.id
        except TypeError:
            net_id = "%s" % net.id

        localname = "veth%s.%s.%s" % (_id, net_id, sessionid)
        if len(localname) >= 16:
            raise ValueError("interface local name %s too long" % localname)

        name = "veth%s.%s.%s" % (net_id, _id, sessionid)
        if len(name) >= 16:
            raise ValueError("interface name %s too long" % name)

        netif = Veth(node=None,
                     name=name,
                     localname=localname,
                     mtu=1500,
                     net=self,
                     start=self.up)
        self.attach(netif)
        if net.up:
            # this is similar to net.attach() but uses netif.name instead
            # of localname
            utils.check_cmd(
                [constants.BRCTL_BIN, "addif", net.brname, netif.name])
            utils.check_cmd(
                [constants.IP_BIN, "link", "set", netif.name, "up"])
        i = net.newifindex()
        net._netif[i] = netif
        with net._linked_lock:
            net._linked[netif] = {}
        netif.net = self
        netif.othernet = net
        return netif
Ejemplo n.º 3
0
    def linknet(self, network):
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.
        """
        session_id = self.session.short_session_id()

        try:
            _id = "%x" % self.id
        except TypeError:
            _id = "%s" % self.id

        try:
            network_id = "%x" % network.id
        except TypeError:
            network_id = "%s" % network.id

        localname = "veth%s.%s.%s" % (_id, network_id, session_id)

        if len(localname) >= 16:
            raise ValueError("interface local name %s too long" % localname)

        name = "veth%s.%s.%s" % (network_id, _id, session_id)
        if len(name) >= 16:
            raise ValueError("interface name %s too long" % name)

        interface = Veth(node=None,
                         name=name,
                         localname=localname,
                         mtu=1500,
                         net=self,
                         start=self.up)
        self.attach(interface)
        if network.up:
            # this is similar to net.attach() but uses netif.name instead of localname
            utils.check_cmd([
                constants.OVS_BIN, "add-port", network.bridge_name,
                interface.name
            ])
            utils.check_cmd(
                [constants.IP_BIN, "link", "set", interface.name, "up"])

        network.attach(interface)
        interface.net = self
        interface.othernet = network
        return interface
Ejemplo n.º 4
0
    def linknet(self, net):
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.

        :param core.netns.vnet.LxBrNet net: network to link with
        :return: created interface
        :rtype: Veth
        """
        sessionid = self.session.short_session_id()
        try:
            _id = f"{self.id:x}"
        except TypeError:
            _id = str(self.id)

        try:
            net_id = f"{net.id:x}"
        except TypeError:
            net_id = str(net.id)

        localname = f"veth{_id}.{net_id}.{sessionid}"
        if len(localname) >= 16:
            raise ValueError(f"interface local name {localname} too long")

        name = f"veth{net_id}.{_id}.{sessionid}"
        if len(name) >= 16:
            raise ValueError(f"interface name {name} too long")

        netif = Veth(self.session, None, name, localname, start=self.up)
        self.attach(netif)
        if net.up:
            # this is similar to net.attach() but uses netif.name instead of localname
            netif.net_client.create_interface(net.brname, netif.name)
        i = net.newifindex()
        net._netif[i] = netif
        with net._linked_lock:
            net._linked[netif] = {}
        netif.net = self
        netif.othernet = net
        return netif
Ejemplo n.º 5
0
    def linknet(self, net: CoreNetworkBase) -> CoreInterface:
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.

        :param net: network to link with
        :return: created interface
        """
        sessionid = self.session.short_session_id()
        try:
            _id = f"{self.id:x}"
        except TypeError:
            _id = str(self.id)

        try:
            net_id = f"{net.id:x}"
        except TypeError:
            net_id = str(net.id)

        localname = f"veth{_id}.{net_id}.{sessionid}"
        if len(localname) >= 16:
            raise ValueError(f"interface local name {localname} too long")

        name = f"veth{net_id}.{_id}.{sessionid}"
        if len(name) >= 16:
            raise ValueError(f"interface name {name} too long")

        netif = Veth(self.session, None, name, localname, start=self.up)
        self.attach(netif)
        if net.up and net.brname:
            netif.net_client.set_interface_master(net.brname, netif.name)
        i = net.newifindex()
        net._netif[i] = netif
        with net._linked_lock:
            net._linked[netif] = {}
        netif.net = self
        netif.othernet = net
        return netif