''' 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_pools(self): ''' Returns a dict of storage pools bound to the host ''' pass def get_volume_names(self, pool=None): ''' Returns volume names stored in this 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: the pool in which to create the volume :type pool: :class:`virStoragePool` :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, wipe=False): ''' Deletes a volume in the specified pool :param pool: the pool in which delete the volume :type pool: :class:`virStoragePool` :param name: the name of the volume :type name: :class:`str` ''' pass def find_space(self, new_space): ''' Tries to find a suitable chunk of space for volume allocation. :param new_space: a space size in gigabytes :type new_space: :class:`str` :return: a :class:`tuple` of best location or :class:`False` if no pool is suitable ''' def get_pool_name(self, pool): ''' Returns the name of this pool :param pool: the storage pool name :type pool: libvirt.`virStoragePool` :return: :class:`str` name of the pool ''' def get_pool_state(self, pool): ''' Returns the running state of the pool :param pool: the storage pool name :type pool: libvirt.`virStoragePool` ''' def get_pool_space_total(self, pool): ''' Returns the storage capacity of this pool in bytes :param pool: the pool to get information from :type pool: :class:`virStoragePool` :return: :class:`int` of capacity in bytes ''' def get_pool_space_available(self, pool): ''' Returns available space of this storage pool in bytes :param pool: the pool to get information from :type pool: :class:`virStoragePool` :return: :class:`int` of available free space in bytes ''' def get_pool_space_used(self, pool): ''' Returns current storage pool usage in bytes :param pool: the pool to get information from :type pool: :class:`virStoragePool` :return: :class:`int` of used space in bytes ''' def get_volume_path(self, pool, vol_name): ''' Returns the file path to the volume :param pool: the storage pool containing this volume :type pool: libvirt.`virStoragePool` :param volume_name: name of the pool volume :type volume_name: :class:`str` :return: :class:`str` path to the volume file ''' def get_volume_allocation(self, pool, vol_name): ''' Returns the pool space used by this volume in bytes :param pool: the pool containing this volume from :type pool: :class:`virStoragePool` :param vol_name: name of the volume to query :type vol_name: :class:`str` :return: :class:`int` of allocation in bytes ''' def get_volume_capacity(self, pool, vol_name): ''' Returns the capacity (usable space) of this volume in bytes :param pool: the pool containing this volume from :type pool: :class:`virStoragePool` :param vol_name: name of the volume to query :type vol_name: :class:`str` :return: :class:`int` of capacity in bytes '''