Exemplo n.º 1
0
def unmap_inheritance(configuration, vgrid_name, cert_id):
    """Remove cert_id inherited access to all vgrid_name sub vgrids: Simply
    force refresh of those vgrids as cert_id was never really there.
    """
    (status, sub_vgrids) = vgrid_list_subvgrids(vgrid_name, configuration)
    for sub in sub_vgrids:
        mark_vgrid_modified(configuration, sub)
Exemplo n.º 2
0
def vgrid_set_entities(configuration, vgrid_name, kind, id_list, allow_empty):
    """Set kind list to provided id_list for given vgrid. The allow_empty
    argument cam be used to e.g. prevent empty owners lists.
    """

    if kind == 'owners':
        entity_filename = configuration.vgrid_owners
    elif kind == 'members':
        entity_filename = configuration.vgrid_members
    elif kind == 'resources':
        entity_filename = configuration.vgrid_resources
    elif kind == 'triggers':
        entity_filename = configuration.vgrid_triggers
    else:
        return (False, "vgrid_set_entities: unknown kind: '%s'" % kind)

    entity_filepath = os.path.join(configuration.vgrid_home, vgrid_name, 
                                   entity_filename)

    try:
        if not id_list and not allow_empty:
            raise ValueError("not allowed to set empty list of %s" % kind)
        dump(id_list, entity_filepath)
        mark_vgrid_modified(configuration, vgrid_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not set %s for %s: %s" % (kind, vgrid_name, exc))
Exemplo n.º 3
0
def vgrid_add_entities(configuration, vgrid_name, kind, id_list):
    """Append list of IDs to pickled list of kind for vgrid_name"""

    if kind == 'owners':
        entity_filename = configuration.vgrid_owners
    elif kind == 'members':
        entity_filename = configuration.vgrid_members
    elif kind == 'resources':
        entity_filename = configuration.vgrid_resources
    elif kind == 'triggers':
        entity_filename = configuration.vgrid_triggers
    else:
        return (False, "vgrid_add_entities: unknown kind: '%s'" % kind)

    entity_filepath = os.path.join(configuration.vgrid_home, vgrid_name, 
                                   entity_filename)
    try:
        if os.path.exists(entity_filepath):
            entities = load(entity_filepath)
        else:
            entities = []
            log_msg = "creating missing file: '%s'" % (entity_filepath)
            configuration.logger.info(log_msg)

        entities += [i for i in id_list if not i in entities]
        dump(entities, entity_filepath)
        mark_vgrid_modified(configuration, vgrid_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not add %s for %s: %s" % (kind, vgrid_name, exc))
Exemplo n.º 4
0
def vgrid_remove_entities(configuration, vgrid_name, kind, id_list,
                          allow_empty, dict_field=False):
    """Remove list of IDs from pickled list of kind for vgrid_name.
    The allow_empty argument can be used to prevent removal of e.g. the last
    owner.
    Use the dict_field if the entries are dictionaries and the id_list should
    be matched against dict_field in each of them. 
    """

    if kind == 'owners':
        entity_filename = configuration.vgrid_owners
    elif kind == 'members':
        entity_filename = configuration.vgrid_members
    elif kind == 'resources':
        entity_filename = configuration.vgrid_resources
    elif kind == 'triggers':
        entity_filename = configuration.vgrid_triggers
    else:
        return (False, "vgrid_remove_entities: unknown kind: '%s'" % kind)
    
    entity_filepath = os.path.join(configuration.vgrid_home, vgrid_name, 
                                   entity_filename)

    # Force raw string to list to avoid nasty silent substring matching below
    # I.e. removing abc.def.0 would also remove def.0
    
    if isinstance(id_list, basestring):
        id_list = [id_list]
        
    try:
        entities = load(entity_filepath)
        if dict_field:
            entities = [i for i in entities if not i[dict_field] in id_list]
        else:
            entities = [i for i in entities if not i in id_list]
        if not entities and not allow_empty:
            raise ValueError("not allowed to remove last entry of %s" % kind)
        dump(entities, entity_filepath)
        mark_vgrid_modified(configuration, vgrid_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not remove %s for %s: %s" % (kind, vgrid_name,
                                                           exc))
Exemplo n.º 5
0
    for (root, dirs, files) in os.walk(resource_path):
        for filename in files:
            try:
                os.remove(os.path.join(root, filename))
            except Exception, err:
                msg += "\n  Could not remove file: '%s'. Failure: %s"\
                     % (os.path.join(root, filename), err)
    try:
        os.rmdir(resource_path)
    except Exception, err:
        msg += "\n  Could not remove dir: '%s' Failure: %s"\
             % (resource_path, err)
        return (False, msg)

    mark_resource_modified(configuration, unique_resource_name)
    mark_vgrid_modified(configuration, unique_resource_name)
    return (True, msg)


def create_resource_conf(configuration,
                         client_id,
                         resource_name,
                         resource_identifier,
                         resource_configfile,
                         new_resource=True):
    """Create a resource from conf in pending file. If pending_file is a
    relative path it will prefixed with the resource_pending dir of the
    client_id.
    """
    if new_resource:
        msg = """
Exemplo n.º 6
0
    for (root, dirs, files) in os.walk(resource_path):
        for filename in files:
            try:
                os.remove(os.path.join(root, filename))
            except Exception, err:
                msg += "\n  Could not remove file: '%s'. Failure: %s"\
                     % (os.path.join(root, filename), err)
    try:
        os.rmdir(resource_path)
    except Exception, err:
        msg += "\n  Could not remove dir: '%s' Failure: %s"\
             % (resource_path, err)
        return (False, msg)

    mark_resource_modified(configuration, unique_resource_name)
    mark_vgrid_modified(configuration, unique_resource_name)
    return (True, msg)


def create_resource_conf(
    configuration,
    client_id,
    resource_name,
    resource_identifier,
    resource_configfile,
    new_resource=True
    ):
    """Create a resource from conf in pending file. If pending_file is a
    relative path it will prefixed with the resource_pending dir of the
    client_id.
    """
Exemplo n.º 7
0
def unmap_vgrid(configuration, vgrid_name):
    """Remove vgrid_name from vgrid map - simply force refresh"""
    mark_vgrid_modified(configuration, vgrid_name)
Exemplo n.º 8
0
def unmap_resource(configuration, res_id):
    """Remove res_id from resource and vgrid maps - simply force refresh"""
    mark_resource_modified(configuration, res_id)
    mark_vgrid_modified(configuration, res_id)