Exemplo n.º 1
0
def get_options(name,
                version,
                description,
                inventory_shortopt='-i',
                inventory_longopt='--inventory',
                inventory_help='output the entire inventory',
                nodeinfo_shortopt='-n',
                nodeinfo_longopt='--nodeinfo',
                nodeinfo_dest='nodename',
                nodeinfo_help='output information for a specific node',
                add_options_cb=None,
                defaults={}):

    parser, checker = make_parser_and_checker(name,
                                              version,
                                              description,
                                              inventory_shortopt,
                                              inventory_longopt,
                                              inventory_help,
                                              nodeinfo_shortopt,
                                              nodeinfo_longopt,
                                              nodeinfo_dest,
                                              nodeinfo_help,
                                              add_options_cb,
                                              defaults=defaults)
    options, args = parser.parse_args()
    checker(options, args)

    path_mangler = get_path_mangler(options.storage_type)
    options.nodes_uri, options.classes_uri = path_mangler(
        options.inventory_base_uri, options.nodes_uri, options.classes_uri)

    return options
Exemplo n.º 2
0
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,
        **kwargs):

    path_mangler = get_path_mangler(storage_type)
    nodes_uri, classes_uri = path_mangler(inventory_base_uri, nodes_uri,
                                          classes_uri)
    storage = get_storage(storage_type, nodes_uri, classes_uri)
    settings = Settings(kwargs)
    reclass = Core(storage, class_mappings, settings, input_data=None)

    # 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 iteritems(data['nodes']):
            env = node_data['environment']
            if env not in nodes:
                nodes[env] = {}
            nodes[env][node_id] = node_data['applications']

        return nodes
Exemplo n.º 3
0
 def _core(self, dataset, opts={}):
     inventory_uri = os.path.dirname(os.path.abspath(__file__)) + '/data/' + dataset
     path_mangler = get_path_mangler('yaml_fs')
     nodes_uri, classes_uri = path_mangler(inventory_uri, 'nodes', 'classes')
     settings = Settings(opts)
     storage = get_storage('yaml_fs', nodes_uri, classes_uri, settings.compose_node_name)
     return Core(storage, None, settings)
Exemplo n.º 4
0
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,
               **kwargs):

    path_mangler = get_path_mangler(storage_type)
    nodes_uri, classes_uri = path_mangler(inventory_base_uri, nodes_uri,
                                          classes_uri)
    storage = get_storage(storage_type, nodes_uri, classes_uri)
    input_data = None
    if propagate_pillar_data_to_reclass:
        input_data = pillar
    settings = Settings(kwargs)
    reclass = Core(storage, class_mappings, settings, 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