def _copy_persistent_over_running_config(): pconfig = PersistentConfig() rconfig = RunningConfig() rconfig.delete() rconfig.networks = pconfig.networks rconfig.bonds = pconfig.bonds rconfig.save()
def _restore_sriov_config(): persistent_config = PersistentConfig() current_sriov_pci_devs = sriov.list_sriov_pci_devices() desired_sriov_pci_devs = { sriov.devname2pciaddr(devname) for devname, devattrs in six.viewitems(persistent_config.devices) if 'sriov' in devattrs } non_persisted_devs = current_sriov_pci_devs - desired_sriov_pci_devs if non_persisted_devs: logging.info( 'Non persisted SRIOV devices found: %s', non_persisted_devs ) missing_current_devs = desired_sriov_pci_devs - current_sriov_pci_devs if missing_current_devs: logging.error( 'Persisted SRIOV devices could not be found: %s', missing_current_devs, ) for sriov_devpci in current_sriov_pci_devs & desired_sriov_pci_devs: devname = sriov.pciaddr2devname(sriov_devpci) numvfs = persistent_config.devices[devname]['sriov']['numvfs'] try: change_numvfs(sriov_devpci, numvfs, devname) except Exception: logging.exception( 'Restoring VF configuration for device %s failed. ' 'Persisted nets built on this device will fail to restore.', devname, )
def unified_restoration(): """ Builds a setupNetworks command from the persistent configuration to set it as running configuration. """ networkmanager.init() persistent_config = PersistentConfig() available_config = _filter_available(persistent_config) _verify_all_devices_are_up(list(_owned_ifcfg_files())) _wait_for_for_all_devices_up(available_config.networks.keys() + available_config.bonds.keys()) if ipv6_supported(): _restore_disable_ipv6() classified_conf = _classify_nets_bonds_config(available_config) setup_nets, setup_bonds, remove_nets, remove_bonds = classified_conf logging.info('Remove networks (%s) and bonds (%s).', remove_nets, remove_bonds) _greedy_setup_bonds(remove_bonds) _greedy_setup_nets(remove_nets) _restore_non_vdsm_net_devices() _convert_to_blocking_dhcp(setup_nets) logging.info('Setup networks (%s) and bonds (%s).', setup_nets, setup_bonds) _greedy_setup_bonds(setup_bonds) _greedy_setup_nets(setup_nets)
def upgrade(): rconfig = RunningConfig() pconfig = PersistentConfig() libvirt_networks = libvirtnetwork.networks() _upgrade_volatile_running_config(rconfig) if rconfig.config_exists() or pconfig.config_exists(): _upgrade_unified_configuration(rconfig) _upgrade_unified_configuration(pconfig) else: # In case unified config has not existed before, it is assumed that # the networks existance have been persisted in libvirt db. vdsmnets = libvirt_vdsm_nets(libvirt_networks) _create_unified_configuration(rconfig, NetInfo(netinfo(vdsmnets))) _cleanup_libvirt_networks(libvirt_networks)
def upgrade(): rconfig = RunningConfig() pconfig = PersistentConfig() libvirt_networks = libvirtnetwork.networks() _upgrade_volatile_running_config(rconfig) if rconfig.config_exists() or pconfig.config_exists(): _upgrade_unified_configuration(rconfig) _upgrade_unified_configuration(pconfig) else: # In case unified config has not existed before, it is assumed that # the networks existance have been persisted in libvirt db. vdsmnets = libvirt_vdsm_nets(libvirt_networks) _create_unified_configuration(rconfig, NetInfo(netinfo(vdsmnets))) _cleanup_libvirt_networks(libvirt_networks)
def _get_unified_persistence_ifcfg(): """generate the set of ifcfg files that result of the current unified persistent networks""" persistent_config = PersistentConfig() if not persistent_config: return set() IFCFG_PATH = NET_CONF_PREF + '%s' RULE_PATH = os.path.join(NET_CONF_DIR, 'rule-%s') ROUTE_PATH = os.path.join(NET_CONF_DIR, 'route-%s') ifcfgs = set() for bonding, bonding_attr in persistent_config.bonds.iteritems(): bond_nics = set(bonding_attr.get('nics', [])) ifcfgs.add(IFCFG_PATH % bonding) for nic in bond_nics: ifcfgs.add(IFCFG_PATH % nic) for network, network_attr in persistent_config.networks.iteritems(): top_level_device = None nic = network_attr.get('nic') if nic: ifcfgs.add(IFCFG_PATH % nic) top_level_device = nic network_bonding = network_attr.get('bonding', None) if network_bonding: top_level_device = network_bonding vlan_id = network_attr.get('vlan') if vlan_id is not None: underlying_device = network_bonding or network_attr.get('nic', '') vlan_device = '.'.join([underlying_device, str(vlan_id)]) top_level_device = vlan_device ifcfgs.add(IFCFG_PATH % vlan_device) if utils.tobool(network_attr.get('bridged', True)): ifcfgs.add(IFCFG_PATH % network) top_level_device = network ifcfgs.add(RULE_PATH % top_level_device) ifcfgs.add(ROUTE_PATH % top_level_device) return ifcfgs
def unified_restoration(): """ Builds a setupNetworks command from the persistent configuration to set it as running configuration. """ persistent_config = PersistentConfig() available_config = _filter_available(persistent_config) classified_conf = _classify_nets_bonds_config(available_config) setup_nets, setup_bonds, remove_nets, remove_bonds = classified_conf logging.info('Remove networks (%s) and bonds (%s).', remove_nets, remove_bonds) _greedy_setup_bonds(remove_bonds) _greedy_setup_nets(remove_nets) _convert_to_blocking_dhcp(setup_nets) logging.info('Setup networks (%s) and bonds (%s).', setup_nets, setup_bonds) _greedy_setup_bonds(setup_bonds) _greedy_setup_nets(setup_nets)