Beispiel #1
0
 def delif(self, iface):
     ''' Remove the interface with the given name from this bridge.
         Equivalent to brctl delif [bridge] [interface]'''
     if type(iface) == ifconfig.Interface:
         devindex = iface.index
     else:
         devindex = ifconfig.Interface(iface).index
     ifreq = struct.pack('16si', self.name, devindex)
     fcntl.ioctl(ifconfig.sockfd, SIOCBRDELIF, ifreq)
     return self
Beispiel #2
0
 def addif(self, iface):
     ''' Add the interface with the given name to this bridge. Equivalent to
         brctl addif [bridge] [interface]. '''
     if type(iface) == ifconfig.Interface:
         devindex = iface.index
     else:
         devindex = ifconfig.Interface(iface).index
     ifreq = struct.pack('16si', self.name, devindex)
     fcntl.ioctl(ifconfig.sockfd, SIOCBRADDIF, ifreq)
     return self
Beispiel #3
0
def create_bridge_with_vid(name, vid):
    devlist = [dev for dev in ifconfig.iterifs(physical=False) if dev.name == "eth1.10"]
    if len(devlist) != 0:
       raise Exists("eth1.10")
    
    br0 = brctl.findbridge(name)
    if br0:
       raise Exists("br0")

    br0 = brctl.addbr(name)
    
    vconfig.add_vlan("eth1", vid)
    
    iface1 = ifconfig.Interface("eth1.%s" % vid) 
    br0.addif(iface1)
    br_iface  = ifconfig.Interface(name)
    iface1.up()
    br_iface.up()
    return
Beispiel #4
0
def interface(request, name):
    i = ifconfig.Interface(name)
    ip = i.ip
    mac = i.mac
    netmask = i.netmask
    i.up()

    def cleanup():
        i.ip = ip
        i.mac = mac
        i.netmask = netmask
        i.up()

    request.addfinalizer(cleanup)

    return i
Beispiel #5
0
def delete_network_interfaces():
    """Delete network interfaces

    This function performs a clean up for the following network interfaces
    virbr[1-4]
    """

    # elevate module re-launches the current process with root/admin privileges
    # using one of the following mechanisms : sudo (Linux, macOS)

    # becoming in root
    elevate(graphical=False)

    ifdata = Ifcfg(subprocess.check_output(['ifconfig', '-a']))

    for interface in range(1, 5):
        current_interface = 'virbr{}'.format(interface)

        if current_interface in ifdata.interfaces:
            # the network interface exists
            net_object = ifdata.get_interface(current_interface)
            net_up = net_object.get_values().get('UP')
            net_running = net_object.get_values().get('RUNNING')

            if net_up or net_running:
                # the network interface is up or running
                try:
                    # down and delete the network interface
                    ifconfig.Interface(current_interface).down()
                    brctl.Bridge(current_interface).delete()
                except IOError:
                    LOG.warn('[Errno 19] No such device: {}'.format(
                        current_interface))

        # adding the network interface
        try:
            brctl.addbr(current_interface)
        except IOError:
            LOG.warn('[Errno 17] File exists {}'.format(current_interface))
Beispiel #6
0
def delete_network_interfaces():
    """Delete network interfaces

    This function performs a clean up for the following network interfaces
    stxbr[1-4]
    """

    # elevate module re-launches the current process with root/admin privileges
    # using one of the following mechanisms : sudo (Linux, macOS)

    # becoming in root
    elevate(graphical=False)

    ifdata = NetIfs()

    # Destroy NAT network if exist
    try:
        bash('sudo virsh net-destroy {}'.format('stx-nat'))
        bash('sudo virsh net-undefine {}'.format('stx-nat'))
    except IOError:
        LOG.warning('NAT network not found')

    for interface in range(1, 5):
        net_if = 'stxbr{}'.format(interface)

        if net_if in ifdata.interfaces:

            if ifdata.is_up(net_if) or \
               ifdata.is_running(net_if):
                # the network interface is up or running
                try:
                    # down and delete the network interface
                    ifconfig.Interface(net_if).down()
                    brctl.Bridge(net_if).delete()
                except IOError:
                    LOG.warning('[Errno 19] No such device: ' '%s', net_if)