def main(): setup_nets_config = hooking.read_json() log('Hook started, handling: %s' % setup_nets_config) running_config = RunningConfig() networks = setup_nets_config['request']['networks'] bondings = setup_nets_config['request']['bondings'] in_ovs_rollback = setup_nets_config['request']['options'].get( '_inOVSRollback') if in_ovs_rollback: log('OVS rollback is to be done.') _rollback(running_config) _set_nets_bonds(setup_nets_config['request'], {}, {}) log('OVS rollback finished, returning empty networks and bondings ' 'configuration back to VDSM.') else: ovs_nets, non_ovs_nets, ovs_bonds, non_ovs_bonds = \ _separate_ovs_nets_bonds(networks, bondings, running_config) _configure(ovs_nets, ovs_bonds, running_config) _set_nets_bonds(setup_nets_config['request'], non_ovs_nets, non_ovs_bonds) log('Hook finished, returning non-OVS networks and bondings back to ' 'VDSM: %s' % setup_nets_config) hooking.write_json(setup_nets_config)
def main(): setup_nets_config = hooking.read_json() log('Hook started, handling: %s' % setup_nets_config) running_config = RunningConfig() networks = setup_nets_config['request']['networks'] bondings = setup_nets_config['request']['bondings'] in_ovs_rollback = setup_nets_config['request']['options'].get( '_inOVSRollback') if in_ovs_rollback: log('OVS rollback is to be done.') _rollback(running_config) _set_nets_bonds(setup_nets_config['request'], {}, {}) log('OVS rollback finished, returning empty networks and bondings ' 'configuration back to VDSM.') else: ovs_nets, non_ovs_nets, ovs_bonds, non_ovs_bonds = \ _separate_ovs_nets_bonds(networks, bondings, running_config) if ovs_nets or ovs_bonds: _configure(ovs_nets, ovs_bonds, running_config) _set_nets_bonds(setup_nets_config['request'], non_ovs_nets, non_ovs_bonds) log('Hook finished, returning non-OVS networks and bondings back to ' 'VDSM: %s' % setup_nets_config) hooking.write_json(setup_nets_config)
def main(): running_config = RunningConfig() caps = hooking.read_json() caps["networks"].update(networks_caps(running_config)) caps["bridges"].update(bridges_caps(running_config)) caps["vlans"].update(vlans_caps(running_config)) caps["bondings"].update(bondings_caps(running_config)) hooking.write_json(caps)
def main(): running_config = RunningConfig() caps = hooking.read_json() caps['networks'].update(networks_caps(running_config)) caps['bridges'].update(bridges_caps(running_config)) caps['vlans'].update(vlans_caps(running_config)) caps['bondings'].update(bondings_caps(running_config)) hooking.write_json(caps)
def main(): """Read ethtool_options from the network 'custom' properties and apply them to the network's devices.""" setup_nets_config = hooking.read_json() for network, attrs in setup_nets_config['request']['networks'].items(): if 'remove' in attrs: continue elif 'custom' in attrs: _process_network(network, attrs)
def main(): """Forward IPv6 configuration from the network 'custom' properties to VDSM API.""" setup_nets_config = hooking.read_json() for network, attrs in setup_nets_config['request']['networks'].items(): if 'remove' in attrs: continue elif 'custom' in attrs: _process_network(attrs) hooking.write_json(setup_nets_config)
def main(): setup_nets_config = hooking.read_json() in_ovs_rollback = setup_nets_config['request']['options'].get( '_inOVSRollback') if in_ovs_rollback: log('Rollback is done. Removing OVS init_config backup.') else: log('Network setup was successful. Removing OVS init_config backup.') _remove_init_config()
def main(): setup_nets_config = hooking.read_json() in_rollback = setup_nets_config['request']['options'].get('_inRollback') if in_rollback: log('Configuration failed with _inRollback=True.') else: log('Configuration failed. At this point, non-OVS rollback should be ' 'done. Executing OVS rollback.') supervdsm.getProxy().setupNetworks( {}, {}, {'connectivityCheck': False, '_inRollback': True, '_inOVSRollback': True})
def main(): """ Create lists of running networks and networks to be (un)configured as FCoE or removed. """ existing_fcoe_networks = _all_configured_fcoe_networks() changed_fcoe = {} changed_non_fcoe = {} removed_networks = {} custom_parameters = {} setup_nets_config = hooking.read_json() changed_all = setup_nets_config['request']['networks'] for net, net_attr in six.iteritems(changed_all): custom_parameters_string = net_attr.get('custom', {}).get('fcoe', '') custom_parameters[net] = _parse_custom(custom_parameters_string) if _has_fcoe(net_attr): changed_fcoe[net] = net_attr.get('nic') elif hooking.tobool(net_attr.get('remove')): removed_networks[net] = net_attr.get('nic') else: changed_non_fcoe[net] = net_attr.get('nic') removed_service_restart_required = _unconfigure_removed( existing_fcoe_networks, removed_networks ) non_fcoe_service_restart_required = _unconfigure_non_fcoe( existing_fcoe_networks, changed_non_fcoe ) reconfigure_service_restart_required = _reconfigure_fcoe( existing_fcoe_networks, changed_fcoe, custom_parameters ) if ( removed_service_restart_required or non_fcoe_service_restart_required or reconfigure_service_restart_required ): # TODO If services are failed to start restore previous configuration # and notify user ret, _, err = hooking.execCmd(['/bin/systemctl', 'restart', 'lldpad']) if ret: hooking.log('Failed to restart lldpad service. err = %s' % (err)) ret, _, err = hooking.execCmd(['/bin/systemctl', 'restart', 'fcoe']) if ret: hooking.log('Failed to restart fcoe service. err = %s' % (err))
def main(): setup_nets_config = hooking.read_json() hooking.log('Hook started, handling: %s' % setup_nets_config) running_config = RunningConfig() networks = setup_nets_config['request']['networks'] bondings = setup_nets_config['request']['bondings'] inRollback = setup_nets_config['request']['options'].get('_inRollback', False) ovs_nets, non_ovs_nets, ovs_bonds, non_ovs_bonds = \ _separate_ovs_nets_bonds(networks, bondings, running_config) configure(ovs_nets, ovs_bonds, running_config, inRollback) setup_nets_config['request']['bondings'] = non_ovs_bonds setup_nets_config['request']['networks'] = non_ovs_nets hooking.log('Hook finished, returning non-OVS networks and bondings back ' 'to VDSM: %s' % setup_nets_config) hooking.write_json(setup_nets_config)
def main(): """ Create lists of running networks and networks to be (un)configured as FCoE or removed. """ existing_fcoe_networks = _all_configured_fcoe_networks() changed_fcoe = {} changed_non_fcoe = {} removed_networks = {} custom_parameters = {} setup_nets_config = hooking.read_json() changed_all = setup_nets_config['request']['networks'] for net, net_attr in six.iteritems(changed_all): custom_parameters_string = net_attr.get('custom', {}).get('fcoe', '') custom_parameters[net] = _parse_custom(custom_parameters_string) if _has_fcoe(net_attr): changed_fcoe[net] = net_attr.get('nic') elif hooking.tobool(net_attr.get('remove')): removed_networks[net] = net_attr.get('nic') else: changed_non_fcoe[net] = net_attr.get('nic') _unconfigure_removed(existing_fcoe_networks, removed_networks) _unconfigure_non_fcoe(existing_fcoe_networks, changed_non_fcoe) _reconfigure_fcoe(existing_fcoe_networks, changed_fcoe, custom_parameters) # TODO If services are failed to start restore previous configuration # and notify user ret, _, err = hooking.execCmd(['/bin/systemctl', 'restart', 'lldpad']) if ret: hooking.log('Failed to restart lldpad service. err = %s' % (err)) ret, _, err = hooking.execCmd(['/bin/systemctl', 'restart', 'fcoe']) if ret: hooking.log('Failed to restart fcoe service. err = %s' % (err))
def main(): stats = hooking.read_json() stats['network'].update(ovs_networks_stats(stats['network'])) hooking.write_json(stats)
def main(): """Main entry point.""" cache = load_cache() stats = hooking.read_json() # Get a list of the ports we need to map. ports = [] for st in stats: for disp in st.get('displayInfo', []): port = int(disp.get('port', '0')) if port > 0: ports.append(port) port = int(disp.get('tlsPort', '0')) if port > 0: ports.append(port) debug('ports to be mapped: {}', ', '.join(map(str, ports))) # Assess the status of the cache with respect to our ports. fresh = complete = True now = time.time() for port in ports: if port not in cache: fresh = complete = False break entry = cache[port] if now - entry['timestamp'] > _cache_ttl: fresh = False debug('cache state: fresh = {}, complete = {}', fresh, complete) # If we are not fresh but we are complete then we can try just to scan the # ports of the previously discovered endpoints as an optimization. These # should not normally change. if not fresh and complete: debug('cache is complete so try previous endpoints') candidates = [cache[port]['port'] for port in ports] debug('port candidates are: {}', ', '.join(map(str, candidates))) endpoints = find_external_endpoints(ports, candidates) update_cache(cache, endpoints) if len(endpoints) == len(ports): complete = True # If we are not complete at this point, then we do a scan over the full port # mapping range. if not complete: debug('cache is not complete so scan full port mapping range') candidates = get_port_candidates(ports) debug('port candidates are: {}', ', '.join(map(str, candidates))) endpoints = find_external_endpoints(ports, candidates) update_cache(cache, endpoints) if len(endpoints) == len(ports): complete = True debug('new cache state: complete = {}', complete) # We are either complete or we aren't. Map as much as we can. for st in stats: for disp in st.get('displayInfo', []): debug('displayInfo: {!r}', disp) port = int(disp.get('port', '0')) if port in cache: entry = cache[port] disp['port'] = str(entry['port']) disp['ipAddress'] = entry['ip'] debug('port {} mapped to {}:{}', port, entry['ip'], entry['port']) elif port > 0: debug('port {} could not be mapped', port) port = int(disp.get('tlsPort', '0')) if port in cache: entry = cache[port] disp['tlsPort'] = str(entry['port']) disp['ipAddress'] = entry['ip'] debug('tlsPort {} mapped to {}:{}', port, entry['ip'], entry['port']) elif port > 0: debug('tlsPort {} could not be mapped', port) save_cache(cache) hooking.write_json(stats)
openstack_binding_host_id = _get_openstack_binding_host_id() if openstack_binding_host_id is not None: openstack_binding_host_ids = caps.get(CAPS_BINDING_KEY, {}) openstack_binding_host_ids[openstacknet_utils.PT_OVS] = \ openstack_binding_host_id openstack_binding_host_ids[openstacknet_utils.PT_OPENSTACK_OVN] = \ openstack_binding_host_id caps[CAPS_BINDING_KEY] = openstack_binding_host_ids return caps if __name__ == '__main__': try: opts, args = getopt.getopt(sys.argv[1:], 'ht', ['help', 'test']) except getopt.GetoptError as err: print(str(err)) _usage() sys.exit(1) for option, _ in opts: if option in ('-h', '--help'): _usage() sys.exit() elif option in ('-t', '--test'): _test() sys.exit() caps = hooking.read_json() caps = _update_openstack_binding_host_ids(caps) hooking.write_json(caps)
#!/usr/bin/python import hooking import os import sys sys.path.append("/usr/libexec/vdsm/hooks/vifdriver") import vif_driver_hooking reply = vif_driver_hooking.before_get_caps(os.environ, hooking.read_json()) if reply: hooking.write_json(reply) hooking.exit_hook("", return_code=0)
#!/usr/bin/python import hooking import os import sys sys.path.append("/usr/libexec/vdsm/hooks/vifdriver") import vif_driver_hooking reply = vif_driver_hooking.before_network_setup(os.environ, hooking.read_json()) if reply: hooking.write_json(reply) hooking.exit_hook("", return_code=0)
openstack_binding_host_ids[openstacknet_utils.PT_OVS] = \ openstack_binding_host_id openstack_binding_host_ids[openstacknet_utils.PT_OPENSTACK_OVN] = \ openstack_binding_host_id caps[CAPS_BINDING_KEY] = openstack_binding_host_ids return caps if __name__ == '__main__': try: opts, args = getopt.getopt(sys.argv[1:], 'ht', ['help', 'test']) except getopt.GetoptError as err: print(str(err)) _usage() sys.exit(1) for option, _ in opts: if option in ('-h', '--help'): _usage() sys.exit() elif option in ('-t', '--test'): _test() sys.exit() if not _is_ovs_service_running(): hooking.exit_hook('OVS is not running', return_code=0) caps = hooking.read_json() caps = _update_openstack_binding_host_ids(caps) hooking.write_json(caps)
vmDigest.next() * GB)) stats['diskUsage'] = diskUsage # Each vm between 1 to 3 ifaces, not dynamic: netIfaces = [] for i in range(1 + (vmDigest.next() % 3)): netif = {} hw = map(lambda x: vmDigest.next(), range(6)) netif['hw'] = ETH_HW_ADDR_FORMAT % (hw[0], hw[1], hw[2], hw[3], hw[4], hw[5]) inet = map(lambda x: vmDigest.next(), range(4)) netif['inet'] = ['%d.%d.%d.%d' % (inet[0], inet[1], inet[2], inet[3])] # For simplicty purposes, the ipv6 addresses are transition from ipv4 netif['inet6'] = ['0:0:0:0:0:ffff:%x%02x:%x%02x' % (inet[0], inet[1], inet[2], inet[3])] netif['name'] = 'eth%d' % i netIfaces.append(netif) stats['netIfaces'] = netIfaces stats['guestFQDN'] = '%s.fakefqdn.com' % stats['vmId'].replace('-', '') stats['appsList'] = APP_LIST if __name__ == '__main__': statsList = hooking.read_json() for stats in statsList: randomizeRuntimeStats(stats) hooking.write_json(statsList)
'slot': '16'}, 'capability': 'pci', 'iommu_group': '23', 'parent': 'pci_0000_00_03_0', 'physfn': _PCI_ADDR_PF, 'product': '82576 Virtual Function', 'product_id': '0x10ca', 'vendor': 'Intel Corporation', 'vendor_id': '0x8086'}}, # vf0 net device 'net_%s_aa_8c_31_98_8a_9a' % _VF0_DEVICE_NAME: { 'params': { 'capability': 'net', 'interface': _VF0_DEVICE_NAME, 'parent': _PCI_ADDR_VF0}}, # vf1 _PCI_ADDR_VF1: { 'params': { 'address': {'bus': '22', 'domain': '0', 'function': '2', 'slot': '16'}, 'capability': 'pci', 'iommu_group': '24', 'parent': 'pci_0000_00_03_0', 'physfn': _PCI_ADDR_PF, 'product': '82576 Virtual Function', 'product_id': '0x10ca', 'vendor': 'Intel Corporation', 'vendor_id': '0x8086'}}, # vf1 net device 'net_%s_ce_1f_0b_d1_ca_93' % _VF1_DEVICE_NAME: { 'params': { 'capability': 'net', 'interface': _VF1_DEVICE_NAME, 'parent': _PCI_ADDR_VF1}}} if __name__ == '__main__': if config.getboolean('vars', 'fake_sriov_enable'): host_devices = hooking.read_json() host_devices.update(_FAKE_SRIOV) hooking.write_json(host_devices)
'bus': '22', 'domain': '0', 'function': '2', 'slot': '16' }, 'capability': 'pci', 'iommu_group': '24', 'parent': 'pci_0000_00_03_0', 'physfn': _PCI_ADDR_PF, 'product': '82576 Virtual Function', 'product_id': '0x10ca', 'vendor': 'Intel Corporation', 'vendor_id': '0x8086' } }, # vf1 net device 'net_%s_ce_1f_0b_d1_ca_93' % _VF1_DEVICE_NAME: { 'params': { 'capability': 'net', 'interface': _VF1_DEVICE_NAME, 'parent': _PCI_ADDR_VF1 } } } if __name__ == '__main__': if config.getboolean('vars', 'fake_sriov_enable'): host_devices = hooking.read_json() host_devices.update(_FAKE_SRIOV) hooking.write_json(host_devices)
def main(): stats_json = hooking.read_json() networks = persist_net.PersistentConfig().networks update_networks_state(stats_json, networks, constants.P_VDSM_RUN) hooking.write_json(stats_json)
#!/usr/bin/python import hooking import os import sys sys.path.append("/usr/libexec/vdsm/hooks/vifdriver") import vif_driver_hooking reply = vif_driver_hooking.after_get_stats(os.environ, hooking.read_json()) if reply: hooking.write_json(reply) hooking.exit_hook("", return_code=0)
stats['diskUsage'] = diskUsage # Each vm between 1 to 3 ifaces, not dynamic: netIfaces = [] for i in range(1 + (next(vmDigest) % 3)): netif = {} hw = [next(vmDigest) for _ in range(6)] netif['hw'] = ETH_HW_ADDR_FORMAT % (hw[0], hw[1], hw[2], hw[3], hw[4], hw[5]) inet = [next(vmDigest) for _ in range(4)] netif['inet'] = ['%d.%d.%d.%d' % (inet[0], inet[1], inet[2], inet[3])] # For simplicty purposes, the ipv6 addresses are transition from ipv4 netif['inet6'] = ['0:0:0:0:0:ffff:%x%02x:%x%02x' % (inet[0], inet[1], inet[2], inet[3])] netif['name'] = 'eth%d' % i netIfaces.append(netif) stats['netIfaces'] = netIfaces stats['guestFQDN'] = '%s.fakefqdn.com' % stats['vmId'].replace('-', '') stats['appsList'] = APP_LIST if __name__ == '__main__': if config.getboolean('vars', 'fake_vmstats_enable'): statsList = hooking.read_json() for stats in statsList: randomizeRuntimeStats(stats) hooking.write_json(statsList)