This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
image_build_configuration.py
73 lines (62 loc) · 2.43 KB
/
image_build_configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Utilities to deal with image build configuration files.
"""
import os
import yaml
from cloudless.util.log import logger
from cloudless.util.exceptions import BadConfigurationException
class ImageBuildConfiguration:
"""
Image build configuration object.
This is where to enforce things like types, required arguments, and just general configuration
constraints. This turns it into a kind of "schema" that someday we can probably auto generate
using a YAML schema library.
"""
def __init__(self, config):
with open(config, 'r') as stream:
try:
self.config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
logger.error("Error parsing config: %s", exc)
raise exc
self.config_path = os.path.dirname(config)
if not self.config_path:
self.config_path = "./"
self.config_filename = config
image_name = self.config.get("save", {}).get("name")
if not image_name:
raise BadConfigurationException(
"Missing required configuration option \"save.name\" in config file: %s" % (
self.config_filename))
def get_config_dir(self):
"""
Get directory of the file behind this configuration.
"""
return os.path.abspath(self.config_path)
def get_state_dir(self):
"""
Get temporary state directory for this configuration.
"""
return os.path.join(self.get_config_dir(), ".cloudless")
def get_blueprint_path(self):
"""
Get path to the blueprint being tested.
"""
relative_blueprint_path = self.config.get("deploy", {}).get("blueprint", "blueprint.yml")
return os.path.join(self.config_path, relative_blueprint_path)
def get_configure_script_path(self):
"""
Get the path for the configure script.
"""
return os.path.join(self.config_path, self.config.get("configure", {}).get("path",
"configure"))
def get_check_script_path(self):
"""
Get the path for the check script.
"""
return os.path.join(self.config_path, self.config.get("check", {}).get("path", "check"))
def get_image_name(self):
"""
Get the image name to save as.
"""
return self.config.get("save", {}).get("name")