def delete_bridge(bridge, dev): if ip_lib.exists(bridge): # Note(sean-k-mooney): this will detach all ports on # the bridge before deleting the bridge. ip_lib.delete(bridge, check_exit_code=[0, 2, 254]) # howver it will not set the detached interface down # so we set the dev down if dev is not None and exists. if dev and ip_lib.exists(dev): set_interface_state(dev, "down")
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')
def _plug_vif_windows(self, vif, instance_info): """Create a per-VIF OVS port.""" if not ip_lib.exists(vif.id): self.ovsdb.ensure_ovs_bridge(vif.network.bridge, self._get_vif_datapath_type(vif)) self._create_vif_port(vif, vif.id, instance_info)
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
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)
def delete_net_dev(dev): """Delete a network device only if it exists.""" if ip_lib.exists(dev): try: ip_lib.delete(dev, check_exit_code=[0, 2, 254]) LOG.debug("Net device removed: '%s'", dev) except processutils.ProcessExecutionError: with excutils.save_and_reraise_exception(): LOG.error("Failed removing net device: '%s'", dev)
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')
def _plug_bridge(self, vif, instance_info): """Plug using hybrid strategy Create a per-VIF linux bridge, then link that bridge to the OVS integration bridge via a veth device, setting up the other end of the veth device just like a normal OVS port. Then boot the VIF on the linux bridge using standard libvirt mechanisms. """ v1_name, v2_name = self.get_veth_pair_names(vif) linux_net.ensure_bridge(vif.bridge_name) mtu = self._get_mtu(vif) if not ip_lib.exists(v2_name): linux_net.create_veth_pair(v1_name, v2_name, mtu) linux_net.add_bridge_port(vif.bridge_name, v1_name) self.ovsdb.ensure_ovs_bridge(vif.network.bridge, self._get_vif_datapath_type(vif)) self._create_vif_port(vif, v2_name, instance_info) else: linux_net.update_veth_pair(v1_name, v2_name, mtu) self._update_vif_port(vif, v2_name)
def _ip_cmd_exists(*args, **kwargs): return ip_lib.exists(*args, **kwargs)
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])