Пример #1
0
def _delNonVdsmNetwork(network, vlan, bonding, nics, _netinfo, configurator):
    if network in netinfo.bridges():
        netEnt = objectivizeNetwork(bridge=network, vlan=vlan, bonding=bonding,
                                    nics=nics, _netinfo=_netinfo,
                                    configurator=configurator,
                                    implicitBonding=False)
        netEnt.remove()
    else:
        raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, "Cannot delete network"
                                 " %r: It doesn't exist in the system" %
                                 network)
Пример #2
0
def _delNonVdsmNetwork(network, vlan, bonding, nics, _netinfo, configurator):
    if network in netinfo.bridges():
        netEnt = objectivizeNetwork(bridge=network, vlan=vlan, bonding=bonding,
                                    nics=nics, _netinfo=_netinfo,
                                    configurator=configurator,
                                    implicitBonding=False)
        netEnt.remove()
    else:
        raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, "Cannot delete network"
                                 " %r: It doesn't exist in the system" %
                                 network)
Пример #3
0
def upgrade_networks(*args):
    """
    Since ovirt-3.0, Vdsm uses libvirt networks (with names vdsm-*) to store
    its own networks. Older Vdsms did not have those defined, and used only
    linux bridges. This command is kept as an upgrade tool for the (very few)
    people who still have such old setups running.
    """
    networks = netinfo.networks()
    bridges = netinfo.bridges()

    if isNeeded(networks, bridges):
        run(networks, bridges)
Пример #4
0
def upgrade_networks(*args):
    """
    upgrade-3.0.0-networks [upgrade-options]
    Since ovirt-3.0, Vdsm uses libvirt networks (with names vdsm-*) to store
    its own networks. Older Vdsms did not have those defined, and used only
    linux bridges. This command is kept as an upgrade tool for the (very few)
    people who still have such old setups running.
    """
    networks = netinfo.networks()
    bridges = netinfo.bridges()

    if isNeeded(networks, bridges):
        run(networks, bridges)
Пример #5
0
 def _syncLibvirtNetworks(self):
     """
         function is mostly for upgrade from versions that did not
         have a libvirt network per vdsm network
     """
     # add libvirt networks
     nets = netinfo.networks()
     bridges = netinfo.bridges()
     for bridge in bridges:
         if not bridge in nets:
             configNetwork.createLibvirtNetwork(network=bridge, bridged=True)
     # remove bridged networks that their bridge not exists
     #TODO:
     # this should probably go into vdsm-restore-net script
     for network in nets:
         if nets[network]['bridged'] and network not in bridges:
             configNetwork.removeLibvirtNetwork(network)
Пример #6
0
 def _syncLibvirtNetworks(self):
     """
         function is mostly for upgrade from versions that did not
         have a libvirt network per vdsm network
     """
     # add libvirt networks
     nets = netinfo.networks()
     bridges = netinfo.bridges()
     configWriter = ifcfg.ConfigWriter()
     for bridge in bridges:
         if not bridge in nets:
             configWriter.createLibvirtNetwork(network=bridge,
                                               bridged=True,
                                               skipBackup=True)
     # remove bridged networks that their bridge not exists
     #TODO:
     # this should probably go into vdsm-restore-net script
     for network in nets:
         if nets[network]['bridged'] and network not in bridges:
             configWriter.removeLibvirtNetwork(network, skipBackup=True)
Пример #7
0
def delNetwork(network, vlan=None, bonding=None, nics=None, force=False,
               configWriter=None, implicitBonding=True, _netinfo=None,
               **options):
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()

    if configWriter is None:
        configWriter = ConfigWriter()

    if network not in _netinfo.networks:
        logging.info("Network %r: doesn't exist in libvirt database", network)
        if network in netinfo.bridges():
            configWriter.removeBridge(network)
        else:
            raise ConfigNetworkError(ne.ERR_BAD_BRIDGE, "Cannot delete network"
                                     " %r: It doesn't exist in the system" %
                                     network)

        if vlan:
            configWriter.removeVlan(vlan, bonding or nics[0])

        return

    nics, vlan, bonding = _netinfo.getNicsVlanAndBondingForNetwork(network)
    bridged = _netinfo.networks[network]['bridged']

    logging.info("Removing network %s with vlan=%s, bonding=%s, nics=%s,"
                 "options=%s" % (network, vlan, bonding, nics, options))

    if not utils.tobool(force):
        if bonding:
            Bond.validateName(bonding)
            if set(nics) != set(_netinfo.bondings[bonding]["slaves"]):
                raise ConfigNetworkError(ne.ERR_BAD_NIC, 'delNetwork: %s are '
                                         'not all nics enslaved to %s' %
                                         (nics, bonding))
        if vlan:
            Vlan.validateTag(vlan)
        if bridged:
            assertBridgeClean(network, vlan, bonding, nics)

    configWriter.setNewMtu(network=network, bridged=bridged, _netinfo=_netinfo)
    configWriter.removeLibvirtNetwork(network)

    # We need to gather NetInfo again to refresh networks info from libvirt.
    # The deleted bridge should never be up at this stage.
    _netinfo = netinfo.NetInfo()
    if network in _netinfo.networks:
        raise ConfigNetworkError(ne.ERR_USED_BRIDGE, 'delNetwork: bridge %s '
                                 'still exists' % network)

    if network and bridged:
        configWriter.removeBridge(network)

    nic = nics[0] if nics else None
    iface = bonding if bonding else nic
    if iface:
        ifdown(iface)
        if vlan:
            configWriter.removeVlan(vlan, iface)
        else:
            cf = netinfo.NET_CONF_PREF + iface
            if not bridged:
                # When removing bridgeless non-VLANed network
                # we need to remove IP/NETMASK from the cfg file
                for key in ('IPADDR', 'NETMASK', 'GATEWAY', 'BOOTPROTO'):
                    configWriter._updateConfigValue(cf, key, '', True)
            else:
                # When removing bridged non-VLANed network
                # we need to remove BRIDGE from the cfg file
                configWriter._updateConfigValue(cf, 'BRIDGE', '', True)

        # Now we can restart changed interface
        ifup(iface)

    # The (relatively) new setupNetwork verb allows to remove a network
    # defined on top of an bonding device without break the bond itself.
    _netinfo = netinfo.NetInfo()
    if implicitBonding:
        if bonding and not _netinfo.ifaceUsers(bonding):
            ifdown(bonding)
            configWriter.removeBonding(bonding)

        _removeUnusedNics(network, vlan, bonding, nics, configWriter)
    elif not bonding:
        _removeUnusedNics(network, vlan, bonding, nics, configWriter)
    elif not _netinfo.ifaceUsers(bonding):
        ifdown(bonding)
        configWriter.setBondingMtu(bonding, DEFAULT_MTU)
        ifup(bonding)