Created by Antoni Segura Puimedon / @celebdor
#!/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))
#!/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
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)