Merge "Corrected links associated with release docs. To be updated along with the...
[genesis.git] / fuel / deploy / setup_execution_environment.py
1 import yaml
2 import io
3 import sys
4 import os
5
6 import common
7 from environments.libvirt_environment import LibvirtEnvironment
8 from environments.virtual_fuel import VirtualFuel
9 from dea import DeploymentEnvironmentAdapter
10
11 exec_cmd = common.exec_cmd
12 err = common.err
13 log = common.log
14 check_dir_exists = common.check_dir_exists
15 check_file_exists = common.check_file_exists
16 check_if_root = common.check_if_root
17 ArgParser = common.ArgParser
18
19 class ExecutionEnvironment(object):
20     def __new__(cls, storage_dir, pxe_bridge, dha_path, dea):
21
22         with io.open(dha_path) as yaml_file:
23             dha_struct = yaml.load(yaml_file)
24
25         type = dha_struct['adapter']
26
27         root_dir = os.path.dirname(os.path.realpath(__file__))
28
29         if cls is ExecutionEnvironment:
30             if type == 'libvirt':
31                 return LibvirtEnvironment(storage_dir, dha_path, dea, root_dir)
32
33             if type == 'ipmi' or type == 'hp':
34                 return VirtualFuel(storage_dir, pxe_bridge, dha_path, root_dir)
35
36         return super(ExecutionEnvironment, cls).__new__(cls)