Some optimizations to improve throughput
This commit is contained in:
parent
e34abc449d
commit
55a6868006
1 changed files with 29 additions and 18 deletions
|
@ -2,6 +2,7 @@ import pyone
|
||||||
|
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from config import config, etcd_client
|
from config import config, etcd_client
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
# How to get client secrets?
|
# How to get client secrets?
|
||||||
# 1. Login to OpenNebula
|
# 1. Login to OpenNebula
|
||||||
|
@ -14,8 +15,6 @@ one_client = pyone.OneServer(
|
||||||
session=config['oca']['client_secrets']
|
session=config['oca']['client_secrets']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_hostname_of_vm(vm_id):
|
|
||||||
host_pool = {
|
host_pool = {
|
||||||
host.NAME: {
|
host.NAME: {
|
||||||
'name': host.NAME,
|
'name': host.NAME,
|
||||||
|
@ -28,10 +27,12 @@ def get_hostname_of_vm(vm_id):
|
||||||
}
|
}
|
||||||
for host in one_client.hostpool.info().HOST
|
for host in one_client.hostpool.info().HOST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_hostname_of_vm(vm_id):
|
||||||
for hostname, host in host_pool.items():
|
for hostname, host in host_pool.items():
|
||||||
if vm_id in host['vms']:
|
if vm_id in host['vms']:
|
||||||
return host
|
return host
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,11 +116,21 @@ def main():
|
||||||
START_ID = -1 # First id whatever it is
|
START_ID = -1 # First id whatever it is
|
||||||
END_ID = -1 # Last id whatever it is
|
END_ID = -1 # Last id whatever it is
|
||||||
|
|
||||||
for VM_STATE in VM_STATES:
|
# Get VMs in all kind of states
|
||||||
vm_pool = one_client.vmpool.infoextended(VmFilterFlag.AllResources.value, START_ID, END_ID, VM_STATE)
|
|
||||||
for i, vm in enumerate(vm_pool.VM):
|
# vms is a list of lists
|
||||||
vm = VM(vm)
|
vms = [
|
||||||
|
one_client.vmpool.infoextended(VmFilterFlag.AllResources.value, START_ID, END_ID, vm_state).VM
|
||||||
|
for vm_state in VM_STATES
|
||||||
|
]
|
||||||
|
# Take out elements from nested lists and put them into the original list
|
||||||
|
# forming a nice flat list
|
||||||
|
vms = list(reduce(lambda n, n_1: n + n_1, vms))
|
||||||
|
print('Total VMs:', len(vms))
|
||||||
|
for i, _vm in enumerate(vms):
|
||||||
|
vm = VM(_vm)
|
||||||
etcd_client.put('/opennebula/vm/{}'.format(vm.id), vm.get_data())
|
etcd_client.put('/opennebula/vm/{}'.format(vm.id), vm.get_data())
|
||||||
|
print(i, end=' ')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue