-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.py
77 lines (69 loc) · 3.24 KB
/
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
74
75
76
77
'''
Copyright 2016, 2017 Hop and Fork.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
import yaml
class Configuration:
def __init__(self):
conf = self.parse_configuration_file('config.yaml')
self.get_required_parameter(conf, 'aws_access_key_id')
self.get_required_parameter(conf, 'aws_secret_access_key')
self.get_required_parameter(conf, 'region_name')
self.get_required_parameter(conf, 'key_pair')
self.get_required_parameter(conf, 'security_groups_zk')
self.get_required_parameter(conf, 'security_groups_ui')
self.get_required_parameter(conf, 'security_groups_ni')
self.get_required_parameter(conf, 'security_groups_sv')
self.get_required_parameter(conf, 'default_vpc')
self.get_required_parameter(conf, 'default_vpc_security_group')
self.get_required_parameter(conf, 'default_ami_id')
self.get_required_parameter(conf, 'subnet_id')
self.get_parameter(conf, 'nimbus_ami_id', self.default_ami_id)
self.get_parameter(conf, 'supervisor_ami_id', self.default_ami_id)
self.get_parameter(conf, 'ui_ami_id', self.default_ami_id)
self.get_parameter(conf, 'zookeeper_ami_id', self.default_ami_id)
self.get_parameter(conf, 'zk_instances', 1)
self.get_parameter(conf, 'supervisors', 1)
self.get_parameter(conf, 'slots', 4)
self.get_parameter(conf, 'default_instance_type', 't2.micro')
self.get_parameter(conf, 'nimbus_instance_type', self.default_instance_type)
self.get_parameter(conf, 'ui_instance_type', self.default_instance_type)
self.get_parameter(conf, 'supervisor_instance_type', self.default_instance_type)
self.get_parameter(conf, 'zookeeper_instance_type', self.default_instance_type)
self.get_parameter(conf, 'volume_size', 8)
def parse_configuration_file(self, config_file):
try:
stream = open(config_file)
conf = yaml.load(stream)
if conf == None:
raise yaml.YAMLError
stream.close()
except IOError:
print("Failed to open configuration file '{}'".format(config_file))
exit(1)
except yaml.YAMLError:
print("Error in configuration file '{}'".format(config_file))
stream.close()
exit(2)
else:
return conf
def get_required_parameter(self, conf, key):
if key in conf:
setattr(self, key, conf[key])
else:
print("Missing required parameter '{}' in configuration."
.format(key))
exit(3)
def get_parameter(self, conf, key, default_value):
if key in conf:
setattr(self, key, conf[key])
else:
setattr(self, key, default_value)