Bug 1580268

Summary: Add example how to clearing virtual numa nodes of VM via API
Product: [oVirt] ovirt-engine Reporter: Germano Veit Michel <gveitmic>
Component: RestAPIAssignee: Ondra Machacek <omachace>
Status: CLOSED CURRENTRELEASE QA Contact: Radim Hrazdil <rhrazdil>
Severity: low Docs Contact:
Priority: unspecified    
Version: 4.2.3.5CC: bugs, lsvaty, mperina
Target Milestone: ovirt-4.2.6Flags: rule-engine: ovirt-4.2+
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-09-03 15:09:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Germano Veit Michel 2018-05-21 06:35:27 UTC
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%

Comment 1 Germano Veit Michel 2018-05-21 23:51:50 UTC
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.

Comment 2 Germano Veit Michel 2018-05-22 00:04:45 UTC
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()

Comment 3 Yaniv Kaul 2018-05-22 05:30:32 UTC
I think documentation via example is the best way to solve this.

Comment 4 Radim Hrazdil 2018-08-14 09:36:51 UTC
Verified updated documentation and example of removing numa nodes.