Ejemplo n.º 1
0
def create_nfs_share(path, desc, client_list):
    share = NfsShare.objects(share_path=path).first()
    if share:
        raise DatabaseError('Nfs share already exists!')
    else:
        NfsShare(share_path=path,
                 share_desc=desc,
                 share_client_list=client_list).save()
Ejemplo n.º 2
0
def update_client_in_nfs_share(client_type, ip, permission, write_mode,
                               permission_constraint,
                               root_permission_constraint, path):
    share = NfsShare.objects(share_path=path).first()
    if share:
        client_list = get_client_in_nfs_share(path)
        client_ip_list = map(lambda client: client['ip'], client_list)

        def create_new_client():
            return {
                'type': client_type,
                'ip': ip,
                'permission': permission,
                'writeMode': write_mode,
                'permissionConstraint': permission_constraint,
                'rootPermissionConstraint': root_permission_constraint
            }

        if ip in client_ip_list:
            client_list = map(
                lambda client: client
                if client['ip'] != ip else create_new_client(), client_list)
            update_nfs_share_client_list(path, client_list)
        else:
            raise DatabaseError('No such client share!')
    else:
        raise DatabaseError('No such nfs share!')
Ejemplo n.º 3
0
def create_client_in_nfs_share(client_type, ip, permission, write_mode,
                               permission_constraint,
                               root_permission_constraint, path):
    share = NfsShare.objects(share_path=path).first()
    if share:
        client_list = get_client_in_nfs_share(path)
        client_ip_list = map(lambda client: client['ip'], client_list)
        if ip in client_ip_list:
            raise DatabaseError('Client already exists!')
        else:
            client_list.append({
                'type':
                client_type,
                'ip':
                ip,
                'permission':
                permission,
                'writeMode':
                write_mode,
                'permissionConstraint':
                permission_constraint,
                'rootPermissionConstraint':
                root_permission_constraint
            })
        update_nfs_share_client_list(path, client_list)
    else:
        raise DatabaseError('No such nfs share!')
Ejemplo n.º 4
0
def get_nfs_share(path):
    share = NfsShare.objects(share_path=path).first()
    if share:
        return {
            'path': share.share_path,
            'description': share.share_desc,
            'clientList': share.share_client_list
        }
    else:
        raise DatabaseError('No such nfs share!')
Ejemplo n.º 5
0
def delete_client_in_nfs_share(ip, path):
    share = NfsShare.objects(share_path=path).first()
    if share:
        client_list = get_client_in_nfs_share(path)
        client_ip_list = map(lambda client: client['ip'], client_list)
        if ip in client_ip_list:
            client_list = filter(lambda client: client['ip'] != ip,
                                 client_list)
            update_nfs_share_client_list(path, client_list)
        else:
            raise DatabaseError('No such client share!')
    else:
        raise DatabaseError('No such nfs share user!')
Ejemplo n.º 6
0
def get_client_in_nfs_share(path):
    share = NfsShare.objects(share_path=path).first()
    if share:
        return share.share_client_list
    else:
        raise DatabaseError('No such nfs share!')
Ejemplo n.º 7
0
def delete_nfs_share(path):
    share = NfsShare.objects(share_path=path).first()
    if share:
        share.delete()
    else:
        raise DatabaseError('No such nfs share!')
Ejemplo n.º 8
0
def update_nfs_share_client_list(path, client_list):
    share = NfsShare.objects(share_path=path).first()
    if share:
        share.update(set__share_client_list=client_list)
    else:
        raise DatabaseError('No such nfs share!')
Ejemplo n.º 9
0
def update_nfs_share_desc(path, desc):
    share = NfsShare.objects(share_path=path).first()
    if share:
        share.update(set__share_desc=desc)
    else:
        raise DatabaseError('No such nfs share!')