예제 #1
0
    def main(conninfo, credentials, args):
        # Get the user object
        user_id = int(users.get_user_id(conninfo, credentials, args.id).data)

        response = users.list_user(conninfo, credentials, user_id)
        user_info, etag = response

        # Modify the user object according to specified arguments
        name = user_info['name']
        if args.name is not None:
            name = args.name

        primary_group = user_info['primary_group']
        if args.primary_group is not None:
            primary_group = str(
                groups.get_group_id(conninfo, credentials,
                                    args.primary_group).data)

        uid = user_info['uid']
        if args.uid is not None:
            uid = args.uid.strip()
            if uid.lower() == 'none':
                uid = ''

        home_directory = user_info['home_directory']
        if args.home_directory is not None:
            if args.home_directory.lower().strip() == "none":
                home_directory = None
            else:
                home_directory = args.home_directory

        # Set the user object, ignore output
        users.modify_user(conninfo, credentials, user_id, name, primary_group,
                          uid, home_directory, etag)

        # Add specified groups, ignore output
        if args.add_group:
            group_id = groups.get_group_id(conninfo, credentials,
                                           args.add_group)
            groups.group_add_member(conninfo, credentials, group_id.data,
                                    user_id)

        # Remove specified groups, ignore output
        if args.remove_group:
            group_id = groups.get_group_id(conninfo, credentials,
                                           args.remove_group)
            groups.group_remove_member(conninfo, credentials, group_id.data,
                                       user_id)

        # Get all related group info
        group_info_msg = get_user_group_info_msg(conninfo, credentials,
                                                 user_id)

        # Get all related IDs
        related_info_msg = get_expanded_identity_information_for_user(
            conninfo, credentials, user_id)

        print users.list_user(conninfo, credentials, user_id)
        print group_info_msg
        print related_info_msg
예제 #2
0
    def main(conninfo, credentials, args):
        user_id = users.get_user_id(conninfo, credentials, args.id)

        if args.password is not None:
            password = args.password
        else:
            password = \
                qumulo.lib.opts.read_password("New password for %s: " % args.id)

        users.set_user_password(conninfo, credentials, user_id.data, password)
        print "Changed password for %s" % args.id
예제 #3
0
    def main(conninfo, credentials, args):
        user_id = int(users.get_user_id(conninfo, credentials, args.id).data)
        user = users.list_user(conninfo, credentials, user_id)

        # Get all related group info
        group_info_msg = get_user_group_info_msg(conninfo, credentials,
                                                 user_id)

        # Get all related IDs
        related_info_msg = get_expanded_identity_information_for_user(
            conninfo, credentials, user_id)

        print user
        print group_info_msg
        print related_info_msg
예제 #4
0
def parse_nfs_restrictions_file(conninfo, credentials, path):
    # Parse JSON file.
    with open(path) as f:
        contents = f.read()
        try:
            restrictions = json.loads(contents)
        except ValueError as e:
            raise ValueError('Error parsing JSON restrictions file ' + str(e))

    # Validate the restrictions are well formed, and create the
    # NFSRestriction object.
    nfs_restrictions = list()
    for r in restrictions['restrictions']:
        # Get read-only.
        read_only = r.get('read_only', False)

        # Process host restrictions.
        host_restrictions = r.get('host_restrictions', [])

        # Process user mapping values.
        try:
            user_mapping = process_user_mapping(r.get('user_mapping', 'none'),
                                                r.get('map_to_user_id', '0'))
        except ValueError as e:
            raise ValueError('When trying to process the following ' +
                             'restriction: ' + str(r) +
                             ', this error was thrown: ' + str(e))

        # Allow either auth_id or user name.
        user_id = users.get_user_id(conninfo, credentials,
                                    r.get('map_to_user_id', '0'))

        # Add the NFSRestriction to the list.
        nfs_restrictions.append(
            NFSRestriction({
                'read_only': read_only,
                'host_restrictions': host_restrictions,
                'user_mapping': user_mapping,
                'map_to_user_id': str(user_id.data)
            }))

    # Return the list of restrictions.
    return nfs_restrictions
예제 #5
0
        read_only = r.get('read_only', False)

        # Process host restrictions.
        host_restrictions = r.get('host_restrictions', [])

        # Process user mapping values.
        try:
            user_mapping = process_user_mapping(r.get('user_mapping', 'none'),
                r.get('map_to_user_id', '0'))
        except ValueError as e:
            raise ValueError('When trying to process the following ' +
                'restriction: ' + str(r) + ', this error was thrown: ' +
                e.message)

        # Allow either auth_id or user name.
        user_id = users.get_user_id(conninfo, credentials,
            r.get('map_to_user_id', '0'))

        # Add the NFSRestriction to the list.
        nfs_restrictions.append(
            NFSRestriction({'read_only': read_only,
                            'host_restrictions': host_restrictions,
                            'user_mapping': user_mapping,
                            'map_to_user_id': str(user_id.data)}))

    # Return the list of restrictions.
    return nfs_restrictions


class NFSListSharesCommand(qumulo.lib.opts.Subcommand):
    NAME = "nfs_list_shares"
    DESCRIPTION = "List all NFS shares"
예제 #6
0
 def main(conninfo, credentials, args):
     user_id = users.get_user_id(conninfo, credentials, args.id)
     users.delete_user(conninfo, credentials, user_id.data)
     print "User was deleted."