예제 #1
0
파일: resource.py 프로젝트: heromod/migrid
def resource_set_owners(configuration, unique_resource_name, clients):
    """Set list of owners for given resource"""
    owners_file = os.path.join(configuration.resource_home,
                               unique_resource_name, 'owners')
    try:
        dump(clients, owners_file)
        mark_resource_modified(configuration, unique_resource_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not set owners for %s: %s" % \
                (unique_resource_name, exc))
예제 #2
0
파일: resource.py 프로젝트: ucphhpc/migrid
def resource_set_owners(configuration, unique_resource_name, clients):
    """Set list of owners for given resource"""
    owners_file = os.path.join(configuration.resource_home,
                               unique_resource_name, 'owners')
    try:
        dump(clients, owners_file)
        mark_resource_modified(configuration, unique_resource_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not set owners for %s: %s" % \
                (unique_resource_name, exc))
예제 #3
0
파일: resource.py 프로젝트: ucphhpc/migrid
def resource_add_owners(configuration, unique_resource_name, clients):
    """Append list of clients to pickled list of resource owners"""
    owners_file = os.path.join(configuration.resource_home,
                               unique_resource_name, 'owners')
    try:
        owners = load(owners_file)
        owners += [i for i in clients if not i in owners]
        dump(owners, owners_file)
        mark_resource_modified(configuration, unique_resource_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not add owners for %s: %s" % \
                (unique_resource_name, exc))
예제 #4
0
파일: resource.py 프로젝트: heromod/migrid
def resource_add_owners(configuration, unique_resource_name, clients):
    """Append list of clients to pickled list of resource owners"""
    owners_file = os.path.join(configuration.resource_home,
                               unique_resource_name, 'owners')
    try:
        owners = load(owners_file)
        owners += [i for i in clients if not i in owners]
        dump(owners, owners_file)
        mark_resource_modified(configuration, unique_resource_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not add owners for %s: %s" % \
                (unique_resource_name, exc))
예제 #5
0
파일: resource.py 프로젝트: heromod/migrid
def resource_remove_owners(configuration, unique_resource_name, clients,
                           allow_empty=False):
    """Remove list of clients from pickled list of resource owners. The
    optional allow_empty option is used to prevent or allow removal of last
    owner.
    """
    owners_file = os.path.join(configuration.resource_home,
                               unique_resource_name, 'owners')
    try:
        owners = load(owners_file)
        owners = [i for i in owners if not i in clients]
        if not owners and not allow_empty:
            raise ValueError("not allowed to remove last owner")
        dump(owners, owners_file)
        mark_resource_modified(configuration, unique_resource_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not remove owners for %s: %s" % \
                (unique_resource_name, exc))
예제 #6
0
파일: resource.py 프로젝트: ucphhpc/migrid
def resource_remove_owners(configuration,
                           unique_resource_name,
                           clients,
                           allow_empty=False):
    """Remove list of clients from pickled list of resource owners. The
    optional allow_empty option is used to prevent or allow removal of last
    owner.
    """
    owners_file = os.path.join(configuration.resource_home,
                               unique_resource_name, 'owners')
    try:
        owners = load(owners_file)
        owners = [i for i in owners if not i in clients]
        if not owners and not allow_empty:
            raise ValueError("not allowed to remove last owner")
        dump(owners, owners_file)
        mark_resource_modified(configuration, unique_resource_name)
        return (True, '')
    except Exception, exc:
        return (False, "could not remove owners for %s: %s" % \
                (unique_resource_name, exc))
예제 #7
0
파일: resource.py 프로젝트: ucphhpc/migrid
    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:
예제 #8
0
파일: resource.py 프로젝트: heromod/migrid
    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.
예제 #9
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)