Skip to content

Commit

Permalink
Enh: move core packs to it's own level. If works, then make it read only
Browse files Browse the repository at this point in the history
  • Loading branch information
naparuba committed Jul 23, 2018
1 parent d0011af commit 37ba22c
Show file tree
Hide file tree
Showing 79 changed files with 11 additions and 8 deletions.
Expand Up @@ -115,7 +115,7 @@ def do_packs_show():
# now we read them, set it in our object

from opsbro.packer import packer
packs = {'global': {}, 'zone': {}, 'local': {}}
packs = {'core': {}, 'global': {}, 'zone': {}, 'local': {}}
for level in packer.packs:
for pname in packer.packs[level]:
packs[level][pname] = {'checks': {}, 'module': None, 'collectors': {}, 'generators': {}}
Expand Down Expand Up @@ -148,7 +148,7 @@ def do_packs_show():
pack_level = generator.pack_level
packs[pack_level][pack_name]['generators'][gname] = generator

for level in ('global', 'zone', 'local'):
for level in ('core', 'global', 'zone', 'local'):
s1 = sprintf('Packs at level ', color='yellow', end='')
s2 = sprintf(level, color='blue', end='')
print_h1(s1 + s2, raw_title=True)
Expand Down Expand Up @@ -269,7 +269,7 @@ def do_packs_list():
for pname in pnames:
present_before = False
keywords = [] # useless but make lint code check happy
for level in ('global', 'zone', 'local'):
for level in ('core', 'global', 'zone', 'local'):
if pname in packs[level]:
(pack, _) = packs[level][pname]
if present_before:
Expand All @@ -285,7 +285,7 @@ def do_overload(pack_full_id, to_level='local'):
packs = packer.get_packs()
pack_level, pack_name = __split_pack_full_id(pack_full_id)

if pack_level not in ['global', 'zone']:
if pack_level not in ['core', 'global', 'zone']:
logger.error('The pack level %s is not valid for the pack overload.' % pack_level)
sys.exit(2)
packs_from_level = packs[pack_level]
Expand All @@ -294,7 +294,7 @@ def do_overload(pack_full_id, to_level='local'):
sys.exit(2)
package_data, dir_name = packs[pack_level][pack_name]

if to_level not in ['zone', 'local']:
if to_level not in ['global', 'zone', 'local']:
logger.error('The destination pack level %s is not valid for the pack overload.' % to_level)
sys.exit(2)

Expand Down
3 changes: 3 additions & 0 deletions opsbro/cli.py
Expand Up @@ -293,15 +293,18 @@ def __init__(self, config, opts):
os.mkdir(data_dir)

# Then we will need to look at other directories, list from
# * core-configuration = fill by installation, read-only
# * global-configration = common to all nodes
# * zone-configuration = common to zone nodes
# * local-configuration = on this specific node
core_configuration = os.path.join(data_dir, 'core-configuration')
global_configuration = os.path.join(data_dir, 'global-configuration')
zone_configuration = os.path.join(data_dir, 'zone-configuration')
local_configuration = os.path.join(data_dir, 'local-configuration')

# Ask the packer to load pack descriptions so it will be able to
# give us which pack directories must be read (with good order)
packer.load_pack_descriptions(core_configuration, 'core')
packer.load_pack_descriptions(global_configuration, 'global')
packer.load_pack_descriptions(zone_configuration, 'zone')
packer.load_pack_descriptions(local_configuration, 'local')
Expand Down
6 changes: 3 additions & 3 deletions opsbro/packer.py
Expand Up @@ -13,7 +13,7 @@

class PackManager(object):
def __init__(self):
self.packs = {'global': {}, 'zone': {}, 'local': {}}
self.packs = {'core': {}, 'global': {}, 'zone': {}, 'local': {}}

# We got an object, we can fill the http daemon part
self.export_http()
Expand Down Expand Up @@ -65,7 +65,7 @@ def load_pack_descriptions(self, root_dir, level):
def give_pack_directories_to_load(self):
to_load_idx = set() # used to know if we already see suck a pack
to_load = {}
for level in ('local', 'zone', 'global'):
for level in ('local', 'zone', 'global', 'core'):
for pname in self.packs[level]:
if pname in to_load_idx:
logger.debug('Skipping pack %s/%s to load because it was already present in a more priority level' % (level, pname))
Expand All @@ -83,7 +83,7 @@ def get_packs(self):


def get_pack_all_topics(self, pname):
for level in ('local', 'zone', 'global'):
for level in ('local', 'zone', 'global', 'core'):
pack = self.packs[level].get(pname, None)
if not pack:
continue
Expand Down

0 comments on commit 37ba22c

Please sign in to comment.