def top(minion_id, storage_type=OPT_STORAGE_TYPE, inventory_base_uri=OPT_INVENTORY_BASE_URI, nodes_uri=OPT_NODES_URI, classes_uri=OPT_CLASSES_URI, class_mappings=None): nodes_uri, classes_uri = path_mangler(inventory_base_uri, nodes_uri, classes_uri) storage = get_storage(storage_type, nodes_uri, classes_uri, default_environment='base') reclass = Core(storage, class_mappings) # if the minion_id is not None, then return just the applications for the # specific minion, otherwise return the entire top data (which we need for # CLI invocations of the adapter): if minion_id is not None: data = reclass.nodeinfo(minion_id) applications = data.get('applications', []) env = data['environment'] return {env: applications} else: data = reclass.inventory() nodes = {} for node_id, node_data in data['nodes'].iteritems(): env = node_data['environment'] if env not in nodes: nodes[env] = {} nodes[env][node_id] = node_data['applications'] return nodes
def ext_pillar(minion_id, pillar, storage_type=OPT_STORAGE_TYPE, inventory_base_uri=OPT_INVENTORY_BASE_URI, nodes_uri=OPT_NODES_URI, classes_uri=OPT_CLASSES_URI, class_mappings=None, propagate_pillar_data_to_reclass=False): nodes_uri, classes_uri = path_mangler(inventory_base_uri, nodes_uri, classes_uri) storage = get_storage(storage_type, nodes_uri, classes_uri, default_environment='base') input_data = None if propagate_pillar_data_to_reclass: input_data = pillar reclass = Core(storage, class_mappings, input_data=input_data) data = reclass.nodeinfo(minion_id) params = data.get('parameters', {}) params['__reclass__'] = {} params['__reclass__']['nodename'] = minion_id params['__reclass__']['applications'] = data['applications'] params['__reclass__']['classes'] = data['classes'] params['__reclass__']['environment'] = data['environment'] return params
def _check_storage_params(storage_type, inventory_base_uri, nodes_uri, classes_uri): nodes_uri, classes_uri = config.path_mangler(inventory_base_uri, nodes_uri, classes_uri) if nodes_uri is None: raise InvocationError('missing nodes_uri or inventory_base_uri parameters') if classes_uri is None: raise InvocationError('missing classes_uri or inventory_base_uri parameters') if storage_type is None: storage_type = 'yaml_fs' # TODO: should be obtained from config return storage_type, nodes_uri, classes_uri
def get_core(key=None): """Initializes reclass Core() using /etc/reclass settings""" defaults = reclass_config.find_and_read_configfile() inventory_base_uri = defaults['inventory_base_uri'] storage_type = defaults['storage_type'] nodes_uri, classes_uri = reclass_config.path_mangler( inventory_base_uri, None, None) storage = reclass.get_storage(storage_type, nodes_uri, classes_uri, default_environment='base') #key = '_param.keepalived_vip_interface' return ReclassCore(storage, None, None, key=key)