-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
31 lines (21 loc) · 1.29 KB
/
config.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
import configparser
import os
def validate(option, section, key):
if option == '--INVALID--':
raise configparser.Error('Found default invalid option in \'{}\' key in \'{}\' section!'.format(key, section))
return option
APP_DIR = os.path.dirname(os.path.realpath(__file__))
config_file = os.path.join(APP_DIR, 'automation.conf')
config = configparser.ConfigParser()
if os.path.isfile(config_file) is False:
raise OSError('Missing file: \'{0}\'! Please copy \'{1}\' to \'{0}\' and edit necessary values.'.format(config_file, os.path.join(APP_DIR, 'defaults.conf')))
config.read(config_file)
SECRET_KEY = validate(config.get('Flask Setup', 'Secret Key'), 'Flask Setup', 'Secret Key')
ESXI = {}
ESXI['host'] = validate(config.get('ESXI Credentials', 'Host'), 'ESXI Credentials', 'Host')
ESXI['user'] = validate(config.get('ESXI Credentials', 'User'), 'ESXI Credentials', 'User')
ESXI['password'] = validate(config.get('ESXI Credentials', 'Password'), 'ESXI Credentials', 'Password')
GUEST = {}
GUEST['user'] = validate(config.get('Guest Credentials', 'User'), 'Guest Credentials', 'User')
GUEST['password'] = validate(config.get('Guest Credentials', 'Password'), 'Guest Credentials', 'Password')
VM_NAMING_SCHEME = validate(config.get('VMs', 'VM Naming Scheme'), 'VMs', 'VM Naming Scheme')