onedns/onedns/clients/one.py

24 lines
735 B
Python
Raw Permalink Normal View History

2016-07-14 16:56:32 +03:00
import oca
class OneClient(object):
"""
OpenNebula Python client
"""
def __init__(self, secret=None, address=None, proxy=None):
self._oca = oca.Client(secret=secret, address=address, proxy=proxy)
self._vm_pool = oca.VirtualMachinePool(self._oca)
def vms(self):
2016-07-15 06:11:29 +03:00
self._vm_pool.info(filter=-1)
2016-07-14 16:56:32 +03:00
return self._vm_pool
2016-07-19 21:05:28 +03:00
def get_vm_by_id(self, vm_id):
if type(vm_id) != int or vm_id < 0:
raise TypeError('vm_id must be an integer >= 0')
self._vm_pool.info(filter=-1,
range_start=vm_id,
range_end=vm_id,
vm_state=-2)
return self._vm_pool[0] if self._vm_pool else None