The program creates a network configuration using the python sdk.
The target configuration requires preconfigured definition on the ovirt-engine system:
1. ovirtmgmt – the management network is defined as non-vm network.
2. nettest – a cluster assinged with the required networks.
from ovirtsdk.api import API from ovirtsdk.xml import params URL = 'http://localhost:8700/api' USERNAME = 'admin@internal' PASSWORD = 'letmein!' ''' The target configuration of the following program is: eth0 ---| | |------ ovirtmgmt |--- bond0 |------ bond0.100 ----- NON_VM_VLAN_100 | |------ bond0.200 ----- VM_VLAN_200 eth4 ---| ''' api = API(url = URL, username = USERNAME, password = PASSWORD) # the eth0 configuration which used for the managment network should be nullify in order to allow reusing eth0 as a slave nic0 = params.HostNIC(name = 'eth0', network = params.Network(), boot_protocol='none', ip=params.IP(address='', netmask='', gateway='')) nic1 = params.HostNIC(name = 'eth4', network = params.Network(), boot_protocol='none', ip=params.IP(address='', netmask='', gateway='')) # bond0 definition on top of eth0 and eth4 bond = params.Bonding( slaves = params.Slaves(host_nic = [ nic0, nic1 ]), options = params.Options( option = [ params.Option(name = 'miimon', value = '100'), params.Option(name = 'mode', value = '1'), params.Option(name = 'primary', value = 'eth0')] ) ) # Configure the management network on top of the bond managementNetwork = params.HostNIC(network = params.Network(name = 'ovirtmgmt'), name = 'bond0', boot_protocol = 'static', ip = params.IP( address = '10.1.1.1', netmask = '255.255.254.0', gateway = '10.1.1.254'), override_configuration = 1, bonding = bond) # create vlan device for network with vlan tag 100 networkName = 'NON_VM_VLAN_100' clusterNetwork = api.clusters.get('nettest').networks.get(name = networkName) vlanNetwork = params.HostNIC(network = params.Network(name = networkName), name = "bond0.%s" % clusterNetwork.vlan.id) # create vlan device for network with vlan tag 200 networkName = 'VM_VLAN_200' clusterNetwork = api.clusters.get('nettest').networks.get(name = networkName) vlanNetwork2 = params.HostNIC(network = params.Network(name = networkName), name = "bond0.%s" % clusterNetwork.vlan.id) # Now apply the configuration host = api.hosts.get('my-host-name') host.nics.setupnetworks(params.Action(force = 0, check_connectivity = 1, host_nics = params.HostNics(host_nic = [ managementNetwork, vlanNetwork, vlanNetwork2 ])))