33d37e909fccdbf4cd566eedb813ae9385b5ae0d
[osm/devops.git] / builds / VyOS-proxy / lib / charms / layer / __init__.py
1 import os
2
3
4 class LayerOptions(dict):
5 def __init__(self, layer_file, section=None):
6 import yaml # defer, might not be available until bootstrap
7 with open(layer_file) as f:
8 layer = yaml.safe_load(f.read())
9 opts = layer.get('options', {})
10 if section and section in opts:
11 super(LayerOptions, self).__init__(opts.get(section))
12 else:
13 super(LayerOptions, self).__init__(opts)
14
15
16 def options(section=None, layer_file=None):
17 if not layer_file:
18 base_dir = os.environ.get('CHARM_DIR', os.getcwd())
19 layer_file = os.path.join(base_dir, 'layer.yaml')
20
21 return LayerOptions(layer_file, section)