示例#1
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
示例#2
0
def _set_device_mtu(dev, mtu):
    """Set the device MTU."""
    if mtu:
        ip_lib.set(dev, mtu=mtu, check_exit_code=[0, 2, 254])
    else:
        LOG.debug("MTU not set on %(interface_name)s interface",
                  {'interface_name': dev})
示例#3
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)
示例#4
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)
示例#5
0
def _ip_cmd_set(*args, **kwargs):
    ip_lib.set(*args, **kwargs)
示例#6
0
def set_interface_state(interface_name, port_state):
    ip_lib.set(interface_name, state=port_state, check_exit_code=[0, 2, 254])
示例#7
0
def set_device_mtu(dev, mtu):
    """Set the device MTU."""
    if ip_lib.exists(dev):
        ip_lib.set(dev, mtu=mtu, check_exit_code=[0, 2, 254])
示例#8
0
def add_bridge_port(bridge, dev):
    ip_lib.set(dev, master=bridge)