コード例 #1
0
 def linknet(self, net):
     ''' Link this bridge with another by creating a veth pair and installing
         each device into each bridge.
     '''
     sessionid = self.session.shortsessionid()
     try:
         self_objid = '%x' % self.objid
     except TypeError:
         self_objid = '%s' % self.objid
     try:
         net_objid = '%x' % net.objid
     except TypeError:
         net_objid = '%s' % net.objid
     localname = 'veth%s.%s.%s' % (self_objid, net_objid, sessionid)
     if len(localname) >= 16:
         raise ValueError, "interface local name '%s' too long" % \
             localname
     name = 'veth%s.%s.%s' % (net_objid, self_objid, 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
         check_call([BRCTL_BIN, "addif", net.brname, netif.name])
         check_call([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
コード例 #2
0
ファイル: vnet.py プロジェクト: tohojo/core
 def linknet(self, net):
     ''' Link this bridge with another by creating a veth pair and installing
         each device into each bridge.
     '''
     sessionid = self.session.shortsessionid()
     try:
         self_objid = '%x' % self.objid
     except TypeError:
         self_objid = '%s' % self.objid
     try:
         net_objid = '%x' % net.objid
     except TypeError:
         net_objid = '%s' % net.objid
     localname = 'veth%s.%s.%s' % (self_objid, net_objid, sessionid)
     if len(localname) >= 16:
         raise ValueError, "interface local name '%s' too long" % \
             localname
     name = 'veth%s.%s.%s' % (net_objid, self_objid, 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
         check_call([BRCTL_BIN, "addif", net.brname, netif.name])
         check_call([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
コード例 #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:
            self_objid = "%x" % self.objid
        except TypeError:
            self_objid = "%s" % self.objid

        try:
            net_objid = "%x" % network.objid
        except TypeError:
            net_objid = "%s" % network.objid

        localname = "veth%s.%s.%s" % (self_objid, net_objid, session_id)

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

        name = "veth%s.%s.%s" % (net_objid, self_objid, 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"])

        # TODO: is there a native method for this? see if this  causes issues
        # i = network.newifindex()
        # network._netif[i] = interface
        # with network._linked_lock:
        #     network._linked[interface] = {}
        # this method call is equal to the above, with a interface.netifi = call
        network.attach(interface)

        interface.net = self
        interface.othernet = network
        return interface
コード例 #4
0
ファイル: vnet.py プロジェクト: yrs1/core
    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:
            self_objid = "%x" % self.objid
        except TypeError:
            self_objid = "%s" % self.objid

        try:
            net_objid = "%x" % net.objid
        except TypeError:
            net_objid = "%s" % net.objid

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

        name = "veth%s.%s.%s" % (net_objid, self_objid, 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
コード例 #5
0
ファイル: openvswitch.py プロジェクト: gsomlo/core
    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:
            self_objid = "%x" % self.objid
        except TypeError:
            self_objid = "%s" % self.objid

        try:
            net_objid = "%x" % network.objid
        except TypeError:
            net_objid = "%s" % network.objid

        localname = "veth%s.%s.%s" % (self_objid, net_objid, session_id)

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

        name = "veth%s.%s.%s" % (net_objid, self_objid, 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"])

        # TODO: is there a native method for this? see if this causes issues
        # i = network.newifindex()
        # network._netif[i] = interface
        # with network._linked_lock:
        #     network._linked[interface] = {}
        # this method call is equal to the above, with a interface.netifi = call
        network.attach(interface)

        interface.net = self
        interface.othernet = network
        return interface
コード例 #6
0
ファイル: vnode.py プロジェクト: gas2serra/core
    def newveth(self, ifindex=None, ifname=None, net=None):
        """
        Create a new interface.

        :param int ifindex: index for the new interface
        :param str ifname: name for the new interface
        :param net: network to associate interface with
        :return: nothing
        """
        with self.lock:
            if ifindex is None:
                ifindex = self.newifindex()

            if ifname is None:
                ifname = "eth%d" % ifindex

            sessionid = self.session.short_session_id()

            try:
                suffix = "%x.%s.%s" % (self.objid, ifindex, sessionid)
            except TypeError:
                suffix = "%s.%s.%s" % (self.objid, ifindex, sessionid)

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

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

            veth = VEth(node=self, name=name, localname=localname, net=net, start=self.up)

            if self.up:
                utils.check_cmd([constants.IP_BIN, "link", "set", veth.name, "netns", str(self.pid)])
                self.check_cmd([constants.IP_BIN, "link", "set", veth.name, "name", ifname])

            veth.name = ifname

            if self.up:
                # TODO: potentially find better way to query interface ID
                # retrieve interface information
                output = self.check_cmd(["ip", "link", "show", veth.name])
                logger.debug("interface command output: %s", output)
                output = output.split("\n")
                veth.flow_id = int(output[0].strip().split(":")[0]) + 1
                logger.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
                veth.hwaddr = MacAddress.from_string(output[1].strip().split()[1])
                logger.debug("interface mac: %s - %s", veth.name, veth.hwaddr)

            try:
                self.addnetif(veth, ifindex)
            except ValueError as e:
                veth.shutdown()
                del veth
                raise e

            return ifindex
コード例 #7
0
ファイル: vnet.py プロジェクト: gsomlo/core
    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:
            self_objid = "%x" % self.objid
        except TypeError:
            self_objid = "%s" % self.objid

        try:
            net_objid = "%x" % net.objid
        except TypeError:
            net_objid = "%s" % net.objid

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

        name = "veth%s.%s.%s" % (net_objid, self_objid, 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
コード例 #8
0
ファイル: vnet.py プロジェクト: Benocs/core
 def linknet(self, net):
     ''' Link this bridge with another by creating a veth pair and installing
         each device into each bridge.
     '''
     sessionid = self.session.sessionid
     localname = "n%s.%s.%s" % (self.objid, net.objid, sessionid)
     name = "n%s.%s.%s" % (net.objid, self.objid, sessionid)
     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
         check_call([BRCTL_BIN, "addif", net.brname, netif.name])
         check_call([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
コード例 #9
0
    def newveth(self, ifindex=None, ifname=None, net=None):
        """
        Create a new interface.

        :param int ifindex: index for the new interface
        :param str ifname: name for the new interface
        :param net: network to associate interface with
        :return: nothing
        """
        self.lock.acquire()
        try:
            if ifindex is None:
                ifindex = self.newifindex()

            if ifname is None:
                ifname = "eth%d" % ifindex

            sessionid = self.session.short_session_id()

            try:
                suffix = "%x.%s.%s" % (self.objid, ifindex, sessionid)
            except TypeError:
                suffix = "%s.%s.%s" % (self.objid, ifindex, sessionid)

            localname = "veth" + suffix
            if len(localname) >= 16:
                raise ValueError("interface local name (%s) too long" %
                                 localname)
            name = localname + "p"
            if len(name) >= 16:
                raise ValueError("interface name (%s) too long" % name)
            veth = VEth(node=self,
                        name=name,
                        localname=localname,
                        mtu=1500,
                        net=net,
                        start=self.up)

            if self.up:
                subprocess.check_call([
                    constants.IP_BIN, "link", "set", veth.name, "netns",
                    str(self.pid)
                ])
                self.cmd([
                    constants.IP_BIN, "link", "set", veth.name, "name", ifname
                ])

            veth.name = ifname

            # retrieve interface information
            result, output = self.cmdresult(["ip", "link", "show", veth.name])
            logger.info("interface command output: %s", output)
            output = output.split("\n")
            veth.flow_id = int(output[0].strip().split(":")[0]) + 1
            logger.info("interface flow index: %s - %s", veth.name,
                        veth.flow_id)
            veth.hwaddr = output[1].strip().split()[1]
            logger.info("interface mac: %s - %s", veth.name, veth.hwaddr)

            try:
                self.addnetif(veth, ifindex)
            except:
                veth.shutdown()
                del veth
                raise

            return ifindex
        finally:
            self.lock.release()