Beispiel #1
0
def delete_qtree() -> None:
    """Delete Qtree"""
    print("=============================================")
    print()
    print("The List of SVMs:-")
    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 from which the Snapshots need to be listed:-")
    print()
    vol_uuid = get_key_volume(svm_name, volume_name)
    show_qtree(svm_name, volume_name)
    print()
    print("=============================================")
    print("Enter the following details to Delete a qtree")

    qtree_name = input("Enter the Name of the Qtree to be Deleted:-")

    try:
        qtree = Qtree.find(vol_uuid, name=qtree_name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))

    try:
        if qtree.delete(poll=True):
            print("Qtree  %s has been deleted Successfully." % qtree.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def create_quotarule(cluster: str, headers_inc: str) -> None:
    """Create Quota Rule """
    show_svm(cluster, headers_inc)
    svm_name = input(
        "\nEnter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    volume_name = input(
        "\nEnter the Volume on which the Quotas needs to be created:-")
    print()
    get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    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, cluster, headers_inc)
        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)
    url = "https://{}/api/storage/quota/rules".format(cluster)
    try:
        response = requests.post(url,
                                 headers=headers_inc,
                                 json=dataobj,
                                 verify=False)
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    print("\n............Quota created successfully............\n")
Beispiel #3
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))
Beispiel #4
0
def patch_qtree(cluster: str, headers_inc: str):
    """ Update Qtree"""

    print()
    print("The List of SVMs")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM Name on which the qtree need to be created:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input(
        "Enter the Volume Name on which the Qtree need to be created:-")
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    print()
    show_qtree(svm_name, volume_name, cluster, headers_inc)
    print()

    qtree_id = input("Enter the ID of the Qtree to be Updated [ID Number]:-")
    print()
    new_qtree_name = input("Enter the new Name of the Qtree to be Updated:-")

    dataobj = {"name": new_qtree_name}

    print(dataobj)

    url = "https://{}/api/storage/qtrees/{}/{}".format(cluster, vol_uuid,
                                                       qtree_id)
    try:
        response = requests.patch(url,
                                  headers=headers_inc,
                                  json=dataobj,
                                  verify=False)
        print("Qtree has been updated.")
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)

    url_text = response.json()
    print(url_text)
def get_qtree_metrics(cluster: str, headers_inc: str):
    "Get Policy name in all vserver"
    show_svm(cluster, headers_inc)
    svm_name = input("\nEnter the SVM Name:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input("Enter the Volume Name on which the Qtree resides:-")
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    print()
    show_qtree(svm_name, volume_name, cluster, headers_inc)
    qtree_id = input("\nEnter the Qtree ID: ")
    url = "https://{}/api/storage/qtrees/{}/{}".format(cluster, vol_uuid,
                                                       qtree_id)
    print()
    print(url)
    print()
    response = requests.get(url, headers=headers_inc, verify=False)
    return response.json()
Beispiel #6
0
def patch_qtree() -> None:
    """Update Qtree"""
    print("=============================================")
    print()
    print("The List of SVMs:-")
    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 from which the Snapshots need to be listed:-")
    print()
    vol_uuid = get_key_volume(svm_name, volume_name)
    show_qtree(svm_name, volume_name)
    print()
    print("=============================================")
    print("Enter the following details to Update a qtree")

    qtree_name = input("Enter the Name of the Qtree to be updated:-")

    try:
        qtree = Qtree.find(vol_uuid, name=qtree_name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))

    nambool = input("Would you like to update the Qtree name (y/n): ")
    if nambool == 'y':
        qtreename = input("Enter the name of the qtree to be updated:-")
        qtree.name = qtreename

    try:
        if qtree.patch(poll=True):
            print("Qtree  %s Updated Successfully" % qtree.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Beispiel #7
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 #8
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))