-
Benziane Chakib authored
- list_vm now does tag filtering and vm name filtering - start and stop vm have name filtering - stop_vm have now an optional parameter to force poweroff
Benziane Chakib authored- list_vm now does tag filtering and vm name filtering - start and stop vm have name filtering - stop_vm have now an optional parameter to force poweroff
interface.py 5.48 KiB
'''
This is the base interface to all the Cloud Control Hypervisor libraries.
It defines abstract classes that represent any kind of entity
we could handle with this library.
We call our most basic entity a Host, basicly a couple (Machine, Operating
System)
For instance a Host is whether a Hypervisor or a Virtual Machine, however other
type of hosts could easly be implemented
'''
#TODO: Implements KvmHV methods and KvmVM methods
class Host(object):
'''
Base host class:
A host is an abstraction of any type of machine
'''
def get_name(self):
'''
Returns the host's name
'''
pass
def get_memory_stats(self):
'''
Returns a tuple representing memory usage
(free, used, total)
'''
pass
def get_status(self):
'''
Returns host's status
'''
pass
def get_cpu_stats(self):
'''
Returns cpu stats as a tuple representing:
(nb_cpu, nb_core_per_cpu, cpu_usage)
'''
pass
def get_network_conf(self):
'''
Returns network configuration
'''
pass
def get_storage_conf(self):
'''
Returns storage configuration
'''
pass
def get_storage_stats(self):
'''
Returns storage statistics
'''
pass
def get_info(self):
'''
get info about the host
get_cpu_stats
get_memory_stats
get_network_conf
get_storage_conf
'''
pass
class Hypervisor(Host):
'''
Base interface class for all hypervisor types and libraries
that interacts with them
'''
_id = 0
def __init__(self):
super(Hypervisor, self).__init__()
self.__class__._id += 1
self.hv_type = 'None'
def list_vms(self):
'''
Lists current defined virtual machines in the hypervisor
Returns a dict of vms
'''
pass
def get_id(self):
'''
Get id of the current hypervisor
Should always be 0
'''
return self._id
def stop_vm(self, vm_name):
'''
Stops the given virtual machinoe
:param vm_name: name of the VM
:Returns: the name of the VM
'''
pass
class VM(Host):
'''
Base Virtual Machine class
'''
_id_count = 0
def __init__(self):
'''
Initiate a Virtual Machine
Each VM instace has a unique ID
'''
self.__class__._id_count += 1
self._id = self.__class__._id_count
def get_id(self):
'''
Gets the id of the virtual machine
:Returns: :class:`int` id of the VM
'''
return self._id
def get_status(self):
'''
returns VM's status:
- running
- blocked in ressource
- paused by user
- being shutdown
- is shut off
- is crached
'''
pass
def shutdown(self):
'''
Shut down given vm
'''
pass
def suspend(self):
'''
Suspend vm
'''
pass
def resume(self):
'''
Resume vm
'''
pass
class HVStorage(object):
'''
Base class representing storage interface of a hypervisor
:param hypervisor: in instance of :class:`Hypervisor`
'''
def get_backend_type(self):
'''
Returns the type of backend used for storage
'''
pass
def get_storage_pools(self):
'''
Returns a list of storage pools bound to the host
'''
pass
def get_space_statistics(self):
'''
Returns informations about space available in the storage object
'''
pass
def get_storage_volumes(self, pool=None):
'''
Returns volumes stored in pool or all pools
'''
pass
def add_pool(self, name, pool_type):
'''
Add new storage pool
:param name: the name of the storage pool to add
:type name: :class:`str`
:param pool_type: The type of the pool : LVM Group, Phisical Disk,
NFS Server ...
'''
pass
def del_pool(self, name):
'''
Delete a storage pool
'''
pass
def add_volume(self, pool, name, space):
'''
Adds a volume to the specified pool
:param pool: name of the pool
:type pool: :class:`str`
:param name: name of the new volume
:type name: :class:`str`
:param space: size of the new volume in gigabytes
:type space: :class:`int`
'''
pass
def del_volume(self, pool, name):
'''
Deletes a volume in the specified pool
:param pool: the pool in which delete the volume
:type pool: :class:`str`
:param name: the name of the volume
:type name: :class:`str`
'''
pass
def find_space(new_space):
'''
Tries to find a suitable chunk of space to store new_space.
:param new_space: a space size in gigabytes
:type new_space: :class:`str`
:return: a :class:`tuple` of possible locations or :class:`False` if no
space is suitable
'''
def get_pool_info(self, pool):
'''
Returns informations about the pool
'''
pass
def get_vol_info(self, vol):
'''
Returns informations about the volume
'''