1 from docker_driver
import DockerDriver
2 from libvirt_driver
import Libvirt
14 __hyp_instance_type =
None
34 def __init__(self, hypervisor_type="DockerDriver"):
35 if not HypervisorFactory.__hyp_instance:
36 if hypervisor_type ==
"DockerDriver":
37 HypervisorFactory.__hyp_instance_type = hypervisor_type
38 HypervisorFactory.__hyp_instance = DockerDriver()
39 elif hypervisor_type ==
"Libvirt":
40 HypervisorFactory.__hyp_instance_type = hypervisor_type
41 HypervisorFactory.__hyp_instance = Libvirt()
44 "Invalid hypervisor type. Valid types are: Docker, Libvirt")
45 elif HypervisorFactory.__hyp_instance_type != hypervisor_type:
47 "An instantiation of type " +
48 HypervisorFactory.__hyp_instance_type +
58 if HypervisorFactory.__hyp_instance
is not None:
59 return HypervisorFactory.__hyp_instance
61 raise RuntimeError(
"Hypervisor not initialized.")
def __init__
Instantiates a HypervisorFactory object.
def get_hypervisor_instance
Returns the hypervisor driver nstance.
A singletone class for creating hypervisor driver objects.