On Github celebdor / devconf14
Created by Antoni Segura Puimedon / @celebdor
VDSM gathers network information and applies network definitions.
oVirt-engine aggregates node information and issues calls to VDSM.
The engine sends XML RPC requests to its hypervisor nodes' VDSM.
VDSM processes the requests executes the actions and returns status message and code.
Multiple bridged or bridgeless vlanned networks with a single bridge-less non vlanned network.
Single non-vlanned bridged network
Define setupNetworks path.
Define getCaps path.
Introduce configurators.
explain library usage.
#!/usr/bin/env python from systemd import journal from vdsm import netinfo import json, os, sys with open(os.environ['_hook_json']) as data_file: setup_nets_config = json.load(data_file) networks = netinfo.networks() # Current nets for network, data in setup_nets_config['request']['networks'].items(): if 'remove' in data: journal.send('VDSM to remove network %s' % network) else: journal.send('VDSM to configure network %s' % network, NEWNET=network in networks, DEF=str(data))
before_nic_hotunplug after_nic_hotunplug after_nic_hotunplug_fail
before_device_create after_device_create
before_device_destroy after_device_destroy
before_update_device after_update_device after_update_device_fail
#!/usr/bin/env python import hooking, os, sys, xml.dom libvirt_net = os.environ.get('extnet') if libvirt_net is not None: doc_xml = hooking.read_domxml() vnic_xml, = doc_xml.getElementsByTagName('interface') # Replace net from vnic xml source, = vnic_xml.getElementsByTagName('source') source.removeAttribute('bridge') source.setAttribute('network', libvirt_net) vnic_xml.setAttribute('type', 'network') hooking.write_domxml(doc) # Write back the xml for vdsm/libvirt
This could be used in:
configureBridge configureBond configureVlan configureNic configureSourceRoute
editBonding
removeBridge removeBond removeVlan removeNic removeSourceRoute
flush
rollback
def configureVlan(self, vlan, **opts): vlan.device.configure(**opts) ipwrapper.linkAdd(name=vlan.name, linkType='vlan', link=vlan.device.name args=['id', str(vlan.tag)]) if vlan.ip: ipwrapper.addrFlush(vlan.name) ipwrapper.addrAdd(vlan.name, vlan.ipConfig.ipaddr, ipConfig.netmask) if vlan.ipConfig.gateway and vlan.ipConfig.defaultRoute: ipwrapper.routeAdd(['default', 'via', vlan.ipConfig.gateway]) if vlan.mtu: ipwrapper.linkSet(vlan.name, ['mtu', str(mtu)]) ipwrapper.linkSet(vlan.name, ['up']) if vlan.ipConfig.bootproto == 'dhcp': DhcpClient(vlan.name).start(vlan.ipConfig.async)