Updates docs for SR1 with final revision
[genesis.git] / fuel / deploy / execution_environment.py
1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ###############################################################################
9
10
11 import yaml
12 import io
13 import os
14
15 import common
16 from environments.libvirt_environment import LibvirtEnvironment
17 from environments.virtual_fuel import VirtualFuel
18
19 exec_cmd = common.exec_cmd
20 err = common.err
21 log = common.log
22 check_dir_exists = common.check_dir_exists
23 check_file_exists = common.check_file_exists
24 check_if_root = common.check_if_root
25 ArgParser = common.ArgParser
26
27
28 class ExecutionEnvironment(object):
29
30     def __new__(cls, storage_dir, pxe_bridge, dha_path, dea):
31
32         with io.open(dha_path) as yaml_file:
33             dha_struct = yaml.load(yaml_file)
34
35         type = dha_struct['adapter']
36
37         root_dir = os.path.dirname(os.path.realpath(__file__))
38
39         if cls is ExecutionEnvironment:
40             if type == 'libvirt':
41                 return LibvirtEnvironment(storage_dir, dha_path, dea, root_dir)
42
43             if type == 'ipmi' or type == 'hp':
44                 return VirtualFuel(storage_dir, pxe_bridge, dha_path, root_dir)
45
46         return super(ExecutionEnvironment, cls).__new__(cls)