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():
    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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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()
    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)
Beispiel #8
0
    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)
Beispiel #9
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)
Beispiel #10
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)
#!/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)
                        '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)
Beispiel #13
0
                                         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)
Beispiel #14
0
                '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)
Beispiel #15
0
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)
Beispiel #16
0
def main():
    stats = hooking.read_json()
    stats['network'].update(ovs_networks_stats(stats['network']))
    hooking.write_json(stats)
Beispiel #17
0
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)
Beispiel #19
0
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)
Beispiel #20
0
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)