Exemplo n.º 1
0
def ensure_bridge(bridge):
    if not ip_lib.exists(bridge):
        ip_lib.add(bridge, 'bridge')
    _disable_ipv6(bridge)
    _arp_filtering(bridge)
    # we bring up the bridge to allow it to switch packets
    set_interface_state(bridge, 'up')
Exemplo n.º 2
0
def _ensure_vlan_privileged(vlan_num, bridge_interface, mac_address, mtu):
    """Create a vlan unless it already exists.

    This assumes the caller is already annotated to run
    with elevated privileges.
    """
    interface = 'vlan%s' % vlan_num
    if not ip_lib.exists(interface):
        LOG.debug('Starting VLAN interface %s', interface)
        ip_lib.add(interface,
                   'vlan',
                   link=bridge_interface,
                   vlan_id=vlan_num,
                   check_exit_code=[0, 2, 254])
        # (danwent) the bridge will inherit this address, so we want to
        # make sure it is the value set from the NetworkManager
        if mac_address:
            ip_lib.set(interface,
                       address=mac_address,
                       check_exit_code=[0, 2, 254])
        ip_lib.set(interface, state='up', check_exit_code=[0, 2, 254])
        # NOTE(vish): set mtu every time to ensure that changes to mtu get
        #             propogated
        _set_device_mtu(interface, mtu)

    return interface
Exemplo n.º 3
0
def ensure_bridge(bridge):
    if not ip_lib.exists(bridge):
        # NOTE(sean-k-mooney): we set mac ageing to 0 to disable mac ageing
        # on the hybrid plug bridge to avoid packet loss during live
        # migration. This avoids bug #1715317 and related bug #1414559
        ip_lib.add(bridge, 'bridge', ageing=0)
    _disable_ipv6(bridge)
    _arp_filtering(bridge)
    # we bring up the bridge to allow it to switch packets
    set_interface_state(bridge, 'up')
Exemplo n.º 4
0
def create_veth_pair(dev1_name, dev2_name, mtu):
    """Create a pair of veth devices with the specified names,
    deleting any previous devices with those names.
    """
    for dev in [dev1_name, dev2_name]:
        delete_net_dev(dev)

    ip_lib.add(dev1_name, 'veth', peer=dev2_name)
    for dev in [dev1_name, dev2_name]:
        ip_lib.set(dev, state='up')
        ip_lib.set(dev, promisc='on')
        _update_device_mtu(dev, mtu)
Exemplo n.º 5
0
def _ensure_bridge_privileged(bridge,
                              interface,
                              net_attrs,
                              gateway,
                              filtering=True,
                              mtu=None):
    """Create a bridge unless it already exists.

    :param interface: the interface to create the bridge on.
    :param net_attrs: dictionary with  attributes used to create bridge.
    :param gateway: whether or not the bridge is a gateway.
    :param filtering: whether or not to create filters on the bridge.
    :param mtu: MTU of bridge.

    If net_attrs is set, it will add the net_attrs['gateway'] to the bridge
    using net_attrs['broadcast'] and net_attrs['cidr'].  It will also add
    the ip_v6 address specified in net_attrs['cidr_v6'] if use_ipv6 is set.

    The code will attempt to move any ips that already exist on the
    interface onto the bridge and reset the default gateway if necessary.

    """
    if not ip_lib.exists(bridge):
        LOG.debug('Starting Bridge %s', bridge)
        ip_lib.add(bridge, 'bridge')
        _disable_ipv6(bridge)
        _arp_filtering(bridge)
        ip_lib.set(bridge, state='up')

    if interface and ip_lib.exists(interface):
        LOG.debug('Adding interface %(interface)s to bridge %(bridge)s', {
            'interface': interface,
            'bridge': bridge
        })
        ip_lib.set(interface,
                   master=bridge,
                   state='up',
                   check_exit_code=[0, 2, 254])

        _set_device_mtu(interface, mtu)
        _update_bridge_routes(interface, bridge)
        # NOTE(sean-k-mooney):
        # The bridge mtu cannont be set until after an
        # interface is added due to bug:
        # https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1399064
        _set_device_mtu(bridge, mtu)
Exemplo n.º 6
0
def _ip_cmd_add(*args, **kwargs):
    ip_lib.add(*args, **kwargs)