Beispiel #1
0
def create_policy_rule(user_name, space_hard_limit, files_hard_limit,
                       qtree_name, volume_name, vserver_name) -> None:
    print("Creating Quota Rule...")
    data = {
        "files": {
            "hard_limit": files_hard_limit
        },
        "qtree": {
            "name": qtree_name
        },
        "space": {
            "hard_limit": space_hard_limit
        },
        "svm": {
            "name": vserver_name
        },
        "type": "user",
        "user_mapping": "off",
        "users": [{
            "name": user_name
        }],
        "volume": {
            "name": volume_name
        }
    }

    qr = QuotaRule(**data)

    try:
        qr.post()
        print("quota rule for %s created successfully" % qtree_name)
    except NetAppRestError as err:
        print("Error: Quota Rule: %s" % err)
    return
Beispiel #2
0
def delete_quotarule() -> None:
    """Delete Quota"""
    print("=============================================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    print()
    show_volume(svm_name)
    print()
    volume_name = input(
        "Enter the name of the volume for which the quota needs to be modified:- "
    )
    print()
    option = input(
        "Would you like to update Quotas of Volume or Qtree [group/users/qtree]:- "
    )
    if option == "users":
        users_name = input(
            "Enter the name of the user,s for which the quota needs to be modified:- "
        )
        try:
            quotarule = QuotaRule.find(svm=svm_name,
                                       volume=volume_name,
                                       users=users_name)
        except NetAppRestError as error:
            print("Exception caught :" + str(error))
    if option == "qtree":
        show_qtree(svm_name, volume_name)
        qtree_name = input(
            "Enter the name of the qtree for which the quota needs to be modified:- "
        )
        try:
            quotarule = QuotaRule.find(svm=svm_name,
                                       volume=volume_name,
                                       qtree=qtree_name)
        except NetAppRestError as error:
            print("Exception caught :" + str(error))
    if option == "group":
        group_name = input(
            "Enter the name of the group for which the quota needs to be modified:- "
        )
        try:
            quotarule = QuotaRule.find(svm=svm_name,
                                       volume=volume_name,
                                       group=group_name)
        except NetAppRestError as error:
            print("Exception caught :" + str(error))
    print()
    try:
        if quotarule.delete(poll=True):
            print("Quota-Rule deleted Successfully")
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def create_policy_rule(volume_name: str, vserver_name: str, qtree_name: str, user_name: str, space_hard: int, file_hard: int) -> None:
    """Creates a new policy rule for the qtree"""

    data = {
        'qtree': {'name': qtree_name},
        'volume': {'name': volume_name},
        'svm': {'name': vserver_name},
        'files': {'hard_limit': file_hard, 'soft_limit': 100},
        'space': {'hard_limit': space_hard, 'soft_limit': 100},
        'type': 'tree',
    }
    quotarule = QuotaRule(**data)
    try:
        quotarule.post()
        print("Rule 'tree' created successfully for %s" % qtree_name)
    except NetAppRestError as err:
        print("Error: Rule was not created: %s" % err)
    return
Beispiel #4
0
def list_quotarule() -> None:
    """Lists Quota Rule"""
    print()
    print("Getting Quota Rule Details")
    print("==========================")
    try:
        for quotarule in QuotaRule.get_collection():
            print("Quota-Rule UUID = %s;  Volume Name = %s" %
                  (quotarule.uuid, quotarule.volume.name))
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Beispiel #5
0
def get_key_quotarule_volume(svm_name, volume_name) -> None:
    """Gets key of Quota Rule of volume"""
    print()
    print("Getting Quota Rule Details")
    print("==========================")
    try:
        for quotarule in QuotaRule.get_collection(
                **{'svm.name': svm_name, 'volume.name': volume_name}):
            print(
                "Quota-Rule UUID = %s;  Volume Name = %s" %
                (quotarule.uuid, quotarule.volume.name))
            return quotarule.uuid
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
Beispiel #6
0
def create_quotarule() -> None:
    """Create Quota Rule """
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(svm_name)
    print()
    volume_name = input(
        "Enter the Volume on which the Quotas needs to be created:-")
    print()
    dataobj = {}
    tmp1 = {"name": svm_name}
    dataobj['svm'] = tmp1
    tmp2 = {"name": volume_name}
    dataobj['volume'] = tmp2
    quota_type = input("Enter the Quota Type [qtree/users/group]:-")
    if quota_type == 'qtree':
        show_qtree(svm_name, volume_name)
        qtree_name = input(
            "Enter the Qtree on which the Quota needs to be applied:-")
        tmp3 = {"name": qtree_name}
        dataobj['qtree'] = tmp3
        dataobj['type'] = "tree"
    if quota_type == 'users':
        dataobj['type'] = "user"
        dataobj['user_mapping'] = False
        tmp3 = []
        dataobj['users'] = tmp3
    if quota_type == 'group':
        dataobj['type'] = "group"
        dataobj['group'] = {}
    spahali = input("Enter the Space Hard-Limit:- ")
    spasoli = input("Enter the Space Soft-Limit:- ")
    fihali = input("Enter the File Hard-Limit:- ")
    fisoli = input("Enter the File Soft-Limit:- ")
    tmp4 = {"hard_limit": spahali, "soft_limit": spasoli}
    dataobj['space'] = tmp4
    tmp5 = {"hard_limit": fihali, "soft_limit": fisoli}
    dataobj['files'] = tmp5
    print(dataobj)

    qrule_info = {
        'qtree': {
            'name': qtree_name
        },
        'svm': {
            'name': svm_name
        },
        'volume': {
            'name': volume_name
        },
        'type': 'tree'
    }
    print(qrule_info)
    try:
        quotarule = QuotaRule.from_dict(qrule_info)
        if quotarule.post(poll=True):
            print("Quota-Rule %s created Successfully" % quotarule.uuid)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Beispiel #7
0
def patch_quotarule() -> None:
    """Update Quota"""
    print("=============================================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    print()
    show_volume(svm_name)
    print()
    volume_name = input(
        "Enter the name of the volume for which the quota needs to be modified:- "
    )
    print()
    option = input(
        "Would you like to update Quotas of Volume or Qtree [group/users/qtree]:- "
    )
    if option == "users":
        users_name = input(
            "Enter the name of the user,s for which the quota needs to be modified:- "
        )
        try:
            quotarule = QuotaRule.find(svm=svm_name,
                                       volume=volume_name,
                                       users=users_name)
        except NetAppRestError as error:
            print("Exception caught :" + str(error))
    if option == "qtree":
        show_qtree(svm_name, volume_name)
        qtree_name = input(
            "Enter the name of the qtree for which the quota needs to be modified:- "
        )
        try:
            quotarule = QuotaRule.find(svm=svm_name,
                                       volume=volume_name,
                                       qtree=qtree_name)
        except NetAppRestError as error:
            print("Exception caught :" + str(error))
    if option == "group":
        group_name = input(
            "Enter the name of the group for which the quota needs to be modified:- "
        )
        try:
            quotarule = QuotaRule.find(svm=svm_name,
                                       volume=volume_name,
                                       group=group_name)
        except NetAppRestError as error:
            print("Exception caught :" + str(error))

    print()
    spacechange = input("Would you like to change the space limits (y/n):- ")
    if spacechange == 'y':
        spahali = input("Enter the Space Hard-Limit:- ")
        spasoli = input("Enter the Space Soft-Limit:- ")
        quotarule.space = {"hard_limit": spahali, "soft_limit": spasoli}

    filechange = input("Would you like to change the file limits (y/n):- ")
    if filechange == 'y':
        fihali = input("Enter the File Hard-Limit:- ")
        fisoli = input("Enter the File Soft-Limit:- ")
        quotarule.files = {"hard_limit": fihali, "soft_limit": fisoli}

    try:
        if quotarule.patch(poll=True):
            print("Quota-Rule updated successfully")
    except NetAppRestError as error:
        print("Exception caught :" + str(error))