All Classes Functions
hypervisor.hypervisor_factory.HypervisorFactory Class Reference

A singletone class for creating hypervisor driver objects. More...

Inheritance diagram for hypervisor.hypervisor_factory.HypervisorFactory:

Public Member Functions

def __init__
 Instantiates a HypervisorFactory object. More...
 

Static Public Member Functions

def get_hypervisor_instance
 Returns the hypervisor driver nstance. More...
 

Detailed Description

A singletone class for creating hypervisor driver objects.

For an instantiation of nf.io there can be exactly one object of only one type of hyperviosr. HyervisorFactory takes care of the creation logic.

Definition at line 11 of file hypervisor_factory.py.

Constructor & Destructor Documentation

def hypervisor.hypervisor_factory.HypervisorFactory.__init__ (   self,
  hypervisor_type = "DockerDriver" 
)

Instantiates a HypervisorFactory object.

Args: hypervisor_type: The type of hypervisor object to instantiate. Valid hypervisor types are 'DockerDriver' and 'Libvirt' for the time being.

Returns: Nothing. Initializaes the factory object.

Note: If this factory class is instantiated multiple times with different types of hypervisor_type argument then it raises a ValueError.

If this factory class is instantiated with a hypervisor type other than Docker or Libvirt it raises a TypeError.

Definition at line 34 of file hypervisor_factory.py.

34 
35  def __init__(self, hypervisor_type="DockerDriver"):
36  if not HypervisorFactory.__hyp_instance:
37  if hypervisor_type == "DockerDriver":
38  HypervisorFactory.__hyp_instance_type = hypervisor_type
39  HypervisorFactory.__hyp_instance = DockerDriver()
40  elif hypervisor_type == "Libvirt":
41  HypervisorFactory.__hyp_instance_type = hypervisor_type
42  HypervisorFactory.__hyp_instance = Libvirt()
43  else:
44  raise TypeError(
45  "Invalid hypervisor type. Valid types are: Docker, Libvirt")
46  elif HypervisorFactory.__hyp_instance_type != hypervisor_type:
47  raise ValueError(
48  "An instantiation of type " +
49  HypervisorFactory.__hyp_instance_type +
50  " already exists.")
def __init__
Instantiates a HypervisorFactory object.

Member Function Documentation

def hypervisor.hypervisor_factory.HypervisorFactory.get_hypervisor_instance ( )
static

Returns the hypervisor driver nstance.

If the instance is not initialized then a RuntimeError is raised.

Definition at line 57 of file hypervisor_factory.py.

57 
59  if HypervisorFactory.__hyp_instance is not None:
60  return HypervisorFactory.__hyp_instance
61  else:
62  raise RuntimeError("Hypervisor not initialized.")
def get_hypervisor_instance
Returns the hypervisor driver nstance.

The documentation for this class was generated from the following file: