The setup networks API expects the target configuration the administrator wishes to apply to the host. Therefore sometimes we wish to perform only minor change that shouldn’t affect existing settings. For that we need to resend as part of the parameters the unmodified network interfaces together with the modified one.
Any interface that will not be send to the engine will be considered as not-configured and any existing configuration will be removed.
The next program will show how to modify few interfaces and maintain the management network intact:
from ovirtsdk.api import API from ovirtsdk.xml import params URL = 'http://localhost:8700/api' USERNAME = 'admin@internal' PASSWORD = 'letmein!' ''' Host venus-vdsb has 3 interfaces: eth0, eth4 and eth5 eth0 - is the management network interface ''' api = API(url=URL, username=USERNAME, password=PASSWORD) MY_HOST_NAME = 'venus-vdsb' def nullifyNic(hostNIC): ''' resets nic configuration to enable its reuse ''' hostNIC.network = params.Network() hostNIC.boot_protocol = 'none' hostNIC.ip = params.IP(address='', netmask='', gateway='') return hostNIC hostNics = api.hosts.get(MY_HOST_NAME).nics # We send eth0 as already defined on the engine nic0 = hostNics.get(name = 'eth0') # We configure eth2 and eth3 for their target configuration - as bond nic2 = nullifyNic(params.HostNIC(name = 'eth4')) nic3 = nullifyNic(params.HostNIC(name = 'eth5')) bond = params.Bonding( slaves = params.Slaves(host_nic = [ nic2, nic3 ]), options = params.Options( option = [ params.Option(name = 'miimon', value = '100'), params.Option(name = 'mode', value = '1'), params.Option(name = 'primary', value = 'eth4')] ) ) bondnic = params.HostNIC(network = params.Network(name = 'bridge11'), name = 'bond0', boot_protocol = 'none', override_configuration = 1, bonding = bond) hostNics.setupnetworks(params.Action(force = 0, check_connectivity = 1, host_nics = params.HostNics(host_nic = [ bondnic, nic0 ])))
In the example above nic0 represents interface “eth0”, the physical interface the management network is assigned to.
nic0 is loaded from the host’s network interfaces list and send as is to the engine
nic1 and nic2 represent eth4 and eth5 respectively which are intended to get bonded. First the nics should be nullify so previous configuration is deleted. It prevents cases in which a nic assigned with network is being used to assign by another network.
Next, the new configuration for nic1 and nic2 is set, and together the new bond0 definition and the nic0 interfaces are being passed as the setup network parameters.
The result as appear on the ‘setup dialog’ after the execution is completed: