Bug 1580268 - Add example how to clearing virtual numa nodes of VM via API
Summary: Add example how to clearing virtual numa nodes of VM via API
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine
Classification: oVirt
Component: RestAPI
Version: 4.2.3.5
Hardware: x86_64
OS: Linux
unspecified
low
Target Milestone: ovirt-4.2.6
: ---
Assignee: Ondra Machacek
QA Contact: Radim Hrazdil
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-05-21 06:35 UTC by Germano Veit Michel
Modified: 2018-09-03 15:09 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2018-09-03 15:09:36 UTC
oVirt Team: Infra
Embargoed:
rule-engine: ovirt-4.2+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 93003 0 master MERGED Add example how to remove numa nodes 2020-05-26 05:28:16 UTC
oVirt gerrit 93004 0 master MERGED Add doc note to numa node removal 2020-05-26 05:28:16 UTC
oVirt gerrit 93040 0 sdk_4.2 MERGED Add example how to remove numa nodes 2020-05-26 05:28:16 UTC
oVirt gerrit 93060 0 model_4.2 MERGED Add doc note to numa node removal 2020-05-26 05:28:17 UTC

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.


Note You need to log in before you can comment on or make changes to this bug.