Description of problem: Objective: remove all virtual nodes from a VM via Python SDK. The most obvious (to me) would be to use the remove() method for each vm_node_service, as below: vm_nodes_service = vm_service.numa_nodes_service() for node in vm_nodes_service.list(): vm_node_service = vm_nodes_service.node_service(node.id) vm_node_service.remove() But this always fails with: 2018-05-21 16:23:21,078+10 WARN [org.ovirt.engine.core.bll.numa.vm.RemoveVmNumaNodesCommand] (default task-29) [5f98d6e1-d3f8-4fe7-b997-5054d147167d] Validation of action 'RemoveVmNumaNodes' failed for user admin@internal-authz. Reasons: VM_NUMA_NODE_NON_CONTINUOUS_INDEX,$nodeCount 3,$minIndex 0,$maxIndex 2,$missingIndices 0 2018-05-21 16:23:21,080+10 ERROR [org.ovirt.engine.api.restapi.resource.AbstractBackendResource] (default task-29) [] Operation Failed: [Expected a continuous sequence of 0-2 for 3 numa nodes. Missing indices 0. Assign indices with increasing order starting from 0 to your virtual numa nodes.] So we cannot remove the first node while there are other nodes. Starting from the higher node works, but it is VERY unfriendly to have to reverse the list to not fail the validation: vm_nodes_service = vm_service.numa_nodes_service() for node in reversed(vm_nodes_service.list()): vm_node_service = vm_nodes_service.node_service(node.id) vm_node_service.remove() Version-Release number of selected component (if applicable): ovirt-engine-4.2.3.5-1.el7.centos.noarch python-ovirt-engine-sdk4-4.2.4-2.el7.centos.x86_64 How reproducible: 100%
And that list is not always ordered, so reversing it does not always guarantee a removal from top to bottom. So basically one needs to order the by index, reverse it and then remove each node.
This appears to always do the job: vm_nodes_service = vm_service.numa_nodes_service() for node in sorted(vm_nodes_service.list(), key=attrgetter('index'), reverse=True): vm_node_service = vm_nodes_service.node_service(node.id) vm_node_service.remove()
I think documentation via example is the best way to solve this.
Verified updated documentation and example of removing numa nodes.