This class will be extended by all other hypervisor types and defines common functionality and APIs for them. --- src/virtlib/hypervisors/__init__.py | 1 + src/virtlib/hypervisors/base.py | 292 +++++++++++++++++++++++++++++++++++ 2 files changed, 293 insertions(+), 0 deletions(-) create mode 100644 src/virtlib/hypervisors/base.py
diff --git a/src/virtlib/hypervisors/__init__.py b/src/virtlib/hypervisors/__init__.py index 470db00..4487baa 100644 --- a/src/virtlib/hypervisors/__init__.py +++ b/src/virtlib/hypervisors/__init__.py @@ -16,3 +16,4 @@ # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html. +__all__ = ['base'] diff --git a/src/virtlib/hypervisors/base.py b/src/virtlib/hypervisors/base.py new file mode 100644 index 0000000..6d53c7f --- /dev/null +++ b/src/virtlib/hypervisors/base.py @@ -0,0 +1,292 @@ +# base.py - Copyright (C) 2011 Red Hat, Inc. +# Written by Darryl L. Pierce <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +from abc import ABCMeta, abstractmethod + +class Hypervisor: + ''' + Defines the abstract base class for all hypervisors. + ''' + + __metaclass__ = ABCMeta + + def connect(self): + ''' + Connects to the underlying virtualization layer. + ''' + self.do_connect() + + def disconnect(self): + ''' + Disconnects from the underlying virtualization layer. + ''' + self.do_disconnect() + + @abstractmethod + def do_connect(self): pass + + @abstractmethod + def do_disconnect(self): pass + + def get_domains(self, defined = True, created = True): + ''' + Returns the list of all domains. + + Keyword arguments: + defined -- If True, returns domains that are defined but not created. + created -- If True, returns domains that are created. + ''' + + return self.do_get_domains(defined, created) + + @abstractmethod + def do_get_domains(self, defined, created): pass + + def get_domain(self, name): + ''' + Returns the domain with the specified name. + + name -- The domain name. + ''' + + return self.do_get_domain(name) + + @abstractmethod + def do_get_domain(self, name): pass + + def domain_exists(self, domain): + ''' + Returns True if the named domain exists. + + domain -- The domain name. + ''' + + domains = self.get_domains(defined = True, created = True) + return domain in domains + + def define_domain(self, config): + ''' + Defines the domain specified by the provided configuration. + The domain configuration is platform-specific. + + config -- The domain's configuration details. + ''' + + self.do_define_domain(config) + + @abstractmethod + def do_define_domain(self, config): pass + + def undefine_domain(self, domain): + ''' + Undefines the specified domain. + + domain -- The domain name. + ''' + + self.do_undefine_domain(domain) + + @abstractmethod + def do_undefine_domain(self, domain): pass + + def create_domain(self, domain): + ''' + Starts the specified domain if it's not already created. + + domain -- The domain name. + ''' + + self.do_create_domain(domain) + + @abstractmethod + def do_create_domain(self, domain): pass + + def destroy_domain(self, domain): + ''' + Shuts down the specified domain. + + domain -- The domain name. + ''' + + self.do_destroy_domain(domain) + + @abstractmethod + def do_destroy_domain(self, domain): pass + + def get_networks(self, defined = True, created = True): + ''' + Returns the list of all networks. + + defined -- If True, includes uncreated but defined networks. + created -- If True, includes created networks. + ''' + + return self.do_get_networks(defined, created) + + @abstractmethod + def do_get_networks(self, defined, created): pass + + def get_network(self, name): + ''' + Returns the network with the specified name. + ''' + + return self.do_get_network(name) + + @abstractmethod + def do_get_network(self, name): pass + + def network_exists(self, network): + ''' + Returns True if the specified network exists. + + network -- The network name. + ''' + + networks = self.get_networks(defined = True, created = True) + return network in networks + + def define_network(self, config): + ''' + Defines the network specified by the configuration. + ''' + + self.do_define_network(config) + + @abstractmethod + def do_define_network(self, config): pass + + def undefine_network(self, network): + ''' + Undefines the specified network. + + network -- The network name. + ''' + + self.do_undefine_network(network) + + @abstractmethod + def do_undefine_network(self, network): pass + + def create_network(self, network): + ''' + Starts the network with the specified name. + + network -- The network name. + ''' + + self.do_create_network(network) + + @abstractmethod + def do_create_network(self, network): pass + + def destroy_network(self, network): + ''' + Shuts down the specified network + + network -- The network name. + ''' + + self.do_destroy_network(network) + + @abstractmethod + def do_destroy_network(self, network): pass + + def get_storage_pools(self, defined = True, created = True): + ''' + Returns the list of all storage pools. + + defined -- If True, includes storage pools that are defined but not started. + started -- If True, includes storage pools that are started. + ''' + + return self.do_get_storage_pools(defined, started) + + @abstractmethod + def do_get_storage_pools(defined, started): pass + + def storage_pool_exists(self, pool): + ''' + Returns True if the specified storage pool exists. + + pool -- The storage pool name. + ''' + + pools = self.get_storage_pools(defined = True, created = True) + return pool in pools + + def get_storage_pool(self, pool): + ''' + Returns the specified storage pool. + + pool -- The storage pool name. + ''' + + return self.do_get_storage_pool(pool) + + @abstractmethod + def do_get_storage_pool(self, pool): pass + + def define_storage_pool(self, name, config): + ''' + Defines the storage pool defined by the configuration. + + name -- The storage pool name. + config -- The storage pool configuration. + ''' + + self.do_define_storage_pool(name, config) + + @abstractmethod + def do_define_storage_pool(self, name, config): pass + + def undefine_storage_pool(self, pool): + ''' + Undefines the specified storage pool. + + pool -- The storage pool name. + ''' + + self.do_undefine_storage_pool(pool) + + @abstractmethod + def do_undefine_storage_pool(self, pool): pass + + def create_storage_pool(self, pool): + ''' + Starts the specified storage pool + + pool -- The storage pool name. + ''' + + self.do_create_storage_pool(pool) + + def do_create_storage_pool(self, pool): pass + + def destroy_storage_pool(self, pool): + ''' + Destroys the specified storage pool. + + pool -- The storage pool name. + ''' + + self.do_destroy_storage_pool(pool) + + @abstractmethod + def do_destroy_storage_pool(self, pool): pass + -- 1.7.4.2 _______________________________________________ virt-tools-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/virt-tools-list
