[libvirt-users] changeBegin() on python API

Laine Stump laine at laine.org
Mon Nov 2 14:48:51 UTC 2015

On 10/30/2015 07:02 AM, Michal Privoznik wrote:
> On 29.10.2015 15:22, Ramon Medeiros wrote:
>> Hi,
>> is changeBegin() working on python? I was trying to use the following
>> method:
>> if = conn.interfaceLookupByName("name")
>> if.undefine()
>> I saw that changeBegin() does not commit changes, but i can't use it.
> This python API boils down to virInterfaceChangeBegin() but as such it's
> implemented just for netcf backend. So if you're on a distro where udev
> is used instead, the API will return an error.
> Otherwise, this should work:
> if = conn.interfaceLookupByName("name")
> if.changeBegin()
> if.undefine()
> /* test if the connectivity to the host was not lost */
> if.changeCommit()

I haven't ever used the python bindings for the interface APIs, but if 
changeBegin is implemented as a method of an interface, that is wrong - 
virInterfaceChangeBegin() saves all the config for *all* interfaces on 
the host, so it should instead be a method of the connection.

(To be more descriptive, virInterfaceChangeBegin() makes a copy of all 
network interface config for all interfaces on the host. You can then 
modify the network config as you wish (add/remove/modify interface 
configs), then when you're sure the new config works, call 
virInterfaceChangeCommit() to throw away the snapshotted copy of config. 
If the host is rebooted without calling virInterfaceChangeCommit(), an 
initscript (or whatever they call the equivalent in systemd) called 
during boot will replace the new network config with whatever it was at 
the time virInterfaceChangeBegin() was called. You can also force this 
rollback prior to boot by calling virinterfaceChangeRollback() (note 
that rollback only affects the config files, *not* the current working 
state of the network)).

More information about the libvirt-users mailing list