Exemplo n.º 1
0
def create_qtree() -> None:
    """Create qtrees"""
    print()
    print("The List of SVMs")
    print("================")
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM Name on which the qtree need to be created:-")
    print()
    show_volume(svm_name)
    print()
    vol_name = input(
        "Enter the Volume Name on which the Qtree need to be created:-")

    print()
    qtree_name = input("Enter the name of the Qtree to be created:-")

    qtree = Qtree.from_dict({
        'name': qtree_name,
        'volume.name': vol_name,
        'svm.name': svm_name
    })

    try:
        if qtree.post(poll=True):
            print("Qtree  %s created Successfully" % qtree.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 2
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))
Exemplo n.º 3
0
def list_qtree():
    """List Qtrees in a Volume"""
    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 Qtrees need to be listed:-")
    print()
    vol_uuid = get_key_volume(svm_name, volume_name)
    print()
    print("The List of Qtrees:-")
    print("====================")
    try:
        for qtree in Qtree.get_collection(**{"volume.uuid": vol_uuid}):
            print("Name:- %s  ID:- %s" % (qtree.name, qtree.id))
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
    return vol_uuid
Exemplo n.º 4
0
def create_snapshot() -> None:
    """Create snapshot """
    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)

    print()
    snapshot_name = input("Enter the name of the snapshot to be created:-")

    snapshot = Snapshot.from_dict({
        'name': snapshot_name,
        'volume.uuid': vol_uuid
    })

    try:
        if snapshot.post(poll=True):
            print("Snapshot  %s created Successfully" % snapshot.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 5
0
def delete_snapshot(cluster: str, headers_inc: str):
    """ snapshot delete"""
    print("=============================================")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the required SVM :-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input("Enter the Volume to list the snapshots :-")
    print()
    show_snapshot(svm_name, volume_name, cluster, headers_inc)
    print()
    snapshot_name = input("Enter the Snapshot to be deleted :-")
    print()
    snapshot_uuid = get_key_snapshot(svm_name, volume_name, snapshot_name,
                                     cluster, headers_inc)
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    urlpath = "https://{}/api/storage/volumes/" + \
        vol_uuid + "/snapshots/" + snapshot_uuid
    url = urlpath.format(cluster)
    try:
        response = requests.delete(url, headers=headers_inc, 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)
Exemplo n.º 6
0
def patch_collection_volume() -> None:
    """Update the volume collection"""
    print("=============================================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(svm_name)
    print()

    noofnames = int(
        input("Enter number of Volumes to be Updated [eg: int value:1,2,3] : "))
    volume_names = list(map(str, input(
        "\nEnter the Volume names to be updated [eg: aaa bbb ccc] : ").strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])
    vol_state = input("Enter the new state of the Volume [offline/online]: ")
    print("Please ensure that the volumes are unmounted in case you are offlining.")
    page_size = min(len(volume_names_final) - 1, 1)

    try:
        Volume.patch_collection({"state": vol_state},
                                name=volume_names_final,
                                max_records=page_size)
        print(
            list(
                Volume.get_collection(
                    fields='state',
                    name=volume_names_final)))
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 7
0
def delete_snapshot() -> None:
    """Delete Snapshot"""

    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_snapshot(svm_name, volume_name)
    print()

    snapshotname = input(
        "Enter the name of the snapshot that needs to be Deleted:- ")

    try:
        snapshot = Snapshot.find(vol_uuid, name=snapshotname)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))

    try:
        if snapshot.delete(poll=True):
            print("Snapshot  %s has been deleted Successfully." %
                  snapshot.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 8
0
def delete_collection_volume() -> None:
    """Delete a collection of volumes"""
    print("=============================================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(svm_name)
    print()

    noofnames = int(
        input(
            "Enter number of Volumes to be Deleted [eg: int value:1,2,3] : "))
    volume_names = list(
        map(
            str,
            input("\nEnter the Volume names to be Deleted [eg: aaa bbb ccc] : "
                  ).strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])

    try:
        Volume.delete_collection(name=volume_names_final)
        print(list(Volume.get_collection()))
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 9
0
def create_lun(cluster: str, headers_inc: str) -> None:
    """Create a LUN"""
    print("======================")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the name of the SVM :- ")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    vol_name = input(
        "Choose the volume on which you would like to create the LUN : ")

    print()
    lun_name = input("Enter the name of the LUN  : ")
    lun_name_ext = "/vol/" + vol_name + "/" + lun_name
    os_type = input("Enter the name of the OS-TYPE  : ")
    lun_size = input("Enter the LUN size in MBs :")
    l_size = get_size(lun_size)

    payload2 = {
        "comment": lun_name,
        "location": {
            "logical_unit": lun_name,
            "volume": {
                "name": vol_name
            }
        },
        "name": lun_name_ext,
        "os_type": os_type,
        "space": {
            "guarantee": {
                "requested": bool("")
            },
            "size": l_size
        },
        "svm": {
            "name": svm_name
        }
    }

    url = "https://{}/api/storage/luns".format(cluster)
    try:
        response = requests.post(
            url,
            headers=headers_inc,
            json=payload2,
            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("LUN created successfully...")
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")
Exemplo n.º 11
0
def patch_snapshot(cluster: str, headers_inc: str):
    "update snapshot"
    print("=============================================")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the required SVM :-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input("Enter the Volume to list the snapshots :-")
    print()
    show_snapshot(svm_name, volume_name, cluster, headers_inc)
    print()
    snapshot_name = input("Enter the Snapshot to be Updated :-")
    print()
    snapshot_uuid = get_key_snapshot(
        svm_name,
        volume_name,
        snapshot_name,
        cluster,
        headers_inc)
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)

    dataobj = {}
    snapbool = input("Would you like to update the name (y/n):- ")
    if snapbool == 'y':
        snapname = input("Enter the new name of the snapshot to be updated:-")
        dataobj['name'] = snapname
    combool = input("Would you like to update the comment (y/n):- ")
    if combool == 'y':
        snapcom = input("Enter the comment of the snapshot to be updated:-")
        dataobj['comment'] = snapcom
    expirybool = input("Would you like to update the Expiry Date (y/n):- ")
    if expirybool == 'y':
        snapexpiry = input(
            "Enter the expiry date of the snapshot to be updated (format:- 2019-02-04T19:00:00Z):-")
        dataobj['expiry_time'] = snapexpiry
    print(dataobj)
    print()
    urlpath = "https://{}/api/storage/volumes/" + \
        vol_uuid + "/snapshots/" + snapshot_uuid
    url = urlpath.format(cluster)
    try:
        response = requests.patch(
            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)
Exemplo n.º 12
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))
Exemplo n.º 13
0
def get_analytics(cluster: str, headers_inc: str):
    """ To get file system details and permissions """
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the SVM name:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volname = input(
        "Enter the name of the volume that needs to be modified:- ")
    path = input("Enter the Path: ")
    print()
    vol_uuid = get_key_volumes(svm_name, volname, cluster, headers_inc)
    print()
    url = "https://{}/api/storage/volumes/{}/files/{}?type=directory&fields=*&order_by=name".format(
        cluster, vol_uuid, path)
    try:
        response = requests.get(url, headers=headers_inc, verify=False)
        print(response)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = dict(response.json())
    if 'error' in url_text:
        print(url_text)
    vols = url_text['records']
    tab = tt.Texttable()
    header = [
        'Name', 'Type', 'changed_time', 'Hard_links Count', 'Unix Permission'
    ]
    tab.header(header)
    tab.set_cols_align(['c', 'c', 'c', 'c', 'c'])
    ctr = 0
    for eventlist in vols:
        ctr = ctr + 1
        vol = eventlist['name']
        eve = eventlist['type']
        sev = eventlist['changed_time']
        har = eventlist['hard_links_count']
        per = eventlist['unix_permissions']
        row = [vol, eve, sev, har, per]
        tab.set_cols_width([10, 15, 30, 15, 15])
        tab.add_row(row)
        tab.set_cols_align(['c', 'c', 'i', 'c', 'i'])
    setdisplay = tab.draw()
    print(setdisplay)
    print("\nThe total no of directory is : ", ctr)
Exemplo n.º 14
0
def create_lun():
    """Create Interface"""
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the name of the SVM on which the interface should be created :- "
    )
    print()
    show_volume(svm_name)
    print()
    vol_name = input(
        "Choose the volume on which you would like to create the LUN : ")

    print()
    lun_name = input("Enter the name of the LUN  : ")
    lun_name_ext = "/vol/" + vol_name + "/" + lun_name
    os_type = input("Enter the name of the OS-TYPE  : ")
    lun_size = input("Enter the LUN size in MBs :")
    l_size = get_size(lun_size)

    payload2 = {
        "comment": lun_name,
        "location": {
            "logical_unit": lun_name,
            "volume": {
                "name": vol_name
            }
        },
        "name": lun_name_ext,
        "os_type": os_type,
        "space": {
            "guarantee": {
                "requested": bool("")
            },
            "size": l_size
        },
        "svm": {
            "name": svm_name
        }
    }

    lun_object = Lun.from_dict(payload2)

    try:
        if lun_object.post(poll=True):
            print("LUN created  %s created Successfully" % lun_object.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def delete_volume(cluster: str, headers_inc: str):
    """ Delete the volume"""
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input(
        "Enter the name of the volume that needs to be Deleted:- ")
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    dataobj = {}
    urlpath = "https://{}/api/storage/volumes/" + vol_uuid
    url = urlpath.format(cluster)
    try:
        response = requests.delete(url,
                                   headers=headers_inc,
                                   json=dataobj,
                                   verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    try:
        job_response = requests.get(job_status,
                                    headers=headers_inc,
                                    verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = job_response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = job_response.json()
    check_job_status(job_status, headers_inc, cluster)
def disable_analytics(cluster: str, headers_inc: str):
    """ Disable Analytics on a volume"""
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the SVM :")
    print()
    show_volume(cluster, headers_inc, svm_name)
    volname = input("Enter the name of the volume to enable analytics:- ")
    tmp4 = {"state": "off"}
    dataobj = {}
    dataobj['analytics'] = tmp4
    vol_uuid = get_key_volumes(svm_name, volname, cluster, headers_inc)
    urlpath = "https://{}/api/storage/volumes/" + vol_uuid
    url = urlpath.format(cluster)
    try:
        response = requests.patch(url,
                                  headers=headers_inc,
                                  json=dataobj,
                                  verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    try:
        job_response = requests.get(job_status,
                                    headers=headers_inc,
                                    verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = job_response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = job_response.json()
    check_job_status(job_status, headers_inc, cluster)
Exemplo n.º 17
0
def get_analytics_meta(cluster: str, headers_inc: str):
    """ To get File System Analytics information for a single directory"""
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the SVM name:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volname = input(
        "Enter the name of the volume that needs to be modified:- ")
    path = input("Enter the Path: ")
    print()
    vol_uuid = get_key_volumes(svm_name, volname, cluster, headers_inc)
    print()
    url = "https://{}/api/storage/volumes/{}/files/{}?return_metadata=true".format(
        cluster, vol_uuid, path)
    try:
        response = requests.get(url, headers=headers_inc, verify=False)
        print(response)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = dict(response.json())
    if 'error' in url_text:
        print(url_text)
    vols = url_text['records']
    tab = tt.Texttable()
    header = ['Type', 'creation_time', 'inode_number', 'is_junction']
    tab.header(header)
    tab.set_cols_align(['c', 'c', 'c', 'c'])
    ctr = 0
    for eventlist in vols:
        ctr = ctr + 1
        eve = eventlist['type']
        sev = eventlist['creation_time']
        har = eventlist['inode_number']
        per = eventlist['is_junction']
        row = [eve, sev, har, per]
        tab.set_cols_width([15, 30, 15, 15])
        tab.add_row(row)
        tab.set_cols_align(['c', 'i', 'c', 'c'])
    setdisplay = tab.draw()
    print(setdisplay)
    print("\nThe total no of directory is : ", ctr)
Exemplo n.º 18
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)
Exemplo n.º 19
0
def create_qtree(cluster: str, headers_inc: str):
    """ Create 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()
    qtree_name = input("Enter the name of the Qtree to be created:-")

    dataobj = {
        "name": qtree_name,
        "volume.uuid": vol_uuid,
        "svm.name": svm_name
    }

    print(dataobj)

    url = "https://{}/api/storage/qtrees".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)

    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()
Exemplo n.º 21
0
def patch_snapshot() -> None:
    """Update Snapshot"""
    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_snapshot(svm_name, volume_name)
    print()

    snapshot_name = input("Enter the name of the snapshot to be updated:-")

    snapshot = Snapshot.find(vol_uuid, name=snapshot_name)
    snapbool = input("Would you like to update the name (y/n): ")
    if snapbool == 'y':
        snapname = input("Enter the name of the snapshot to be updated:-")
        snapshot.name = snapname
    combool = input("Would you like to update the comment (y/n): ")
    if combool == 'y':
        snapcom = input("Enter the comment of the snapshot to be updated:-")
        snapshot.comment = snapcom
    expirybool = input("Would you like to update the expiry date (y/n): ")
    if expirybool == 'y':
        snapexpiry = input(
            "Enter the expiry date of the snapshot to be updated (format:- 2019-02-04T19:00:00Z):-"
        )
        snapshot.expiry_time = snapexpiry

    try:
        if snapshot.patch(poll=True):
            print("Snapshot  %s Updated Successfully" % snapshot.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 22
0
def create_snapshot(cluster: str, headers_inc: str):
    """ create snapshot"""
    print("=============================================")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the required SVM :-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input(
        "Enter the Volume on which the snapshot need to be created:-")
    print()
    show_snapshot(svm_name, volume_name, cluster, headers_inc)
    print()
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    snapshot_name = input("Enter the name of the Snapshot to be created:- ")
    print()
    dataobj = {}
    dataobj['name'] = snapshot_name
    # dataobj['volume.uuid']=vol_uuid
    print(dataobj)
    url = "https://{}/api/storage/volumes/{}/snapshots".format(
        cluster, vol_uuid)
    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)
Exemplo n.º 23
0
def list_qtree(cluster: str, headers_inc: str):
    """ Show Qtree"""
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()

    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input(
        "Enter the Volume from which the Qtree need to be listed:-")
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    print()
    print("Getting Qtree Details")
    print("======================")
    qtree_api_url = "https://{}/api/storage/qtrees?volume.uuid={}".format(
        cluster, vol_uuid)
    try:
        response = requests.get(
            qtree_api_url,
            headers=headers_inc,
            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)

    qtreedict = dict(response.json())
    qtrees = qtreedict['records']
    print()
    print(" List of Qtrees :- ")
    for qtree in qtrees:
        print("Qtree Name:-%s Qtree ID:-%s" % (qtree['name'], qtree['id']))
Exemplo n.º 24
0
def list_snapshot(cluster: str, headers_inc: str):
    """ list snapshot"""
    print("=============================================")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input("Enter the required SVM :-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input("Enter the Volume to list the snapshots :-")
    print()
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)

    print()
    print("Getting Snapshot Details")
    print("========================")
    snap_api_url = "https://{}/api/storage/volumes/{}/snapshots".format(
        cluster, vol_uuid)
    try:
        response = requests.get(
            snap_api_url,
            headers=headers_inc,
            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)
    snapshotsdict = dict(response.json())
    snapshots = snapshotsdict['records']
    print()
    for snapshot in snapshots:
        print("Snapshot Name:-%s Snapshot UUID:-%s" %
              (snapshot['name'], snapshot['uuid']))
Exemplo n.º 25
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))
Exemplo n.º 26
0
def list_snapshot() -> None:
    """List Snapshots in a volume"""
    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)
    print()
    print("The List of Snapshots:-")
    print("=======================")
    try:
        for snapshot in Snapshot.get_collection(vol_uuid):
            print(snapshot.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Exemplo n.º 27
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))
Exemplo n.º 28
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))
def patch_volume(cluster: str, headers_inc: str):
    """ Update a volume"""
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volname = input(
        "Enter the name of the volume that needs to be modified:- ")
    dataobj = {}
    dataobj['name'] = volname
    print()
    nambool = input("Would you like to change the volume name (y/n):- ")
    if nambool == 'y':
        nam = input("Enter the new name of the Volume: ")
        dataobj['name'] = nam
    print()
    sizebool = input("Would you like to change the volume size (y/n):- ")
    if sizebool == 'y':
        vol_size = input("Enter the new size of the Volume: ")
        vol_size_format = get_size(vol_size)
        dataobj['size'] = vol_size_format
    print()
    autosizebool = input("Would you like to change autosize options (y/n):- ")
    if autosizebool == 'y':
        print("Enter the following Details")
        grow_threshold = input("grow_threshold?:- ")
        maximum = input("maximum?:- ")
        minimum = input("minimum?:- ")
        mode = input("mode?:- ")
        shrink_threshold = input("shrink_threshold?:- ")
        autosizejson = {
            "grow_threshold": grow_threshold,
            "maximum": maximum,
            "minimum": minimum,
            "mode": mode,
            "shrink_threshold": shrink_threshold
        }
        dataobj['autosize'] = autosizejson
    print()
    efficiency = input("Would you like to enable Efficiency (y/n): ")
    if efficiency == 'y':
        print("Enter the following Details")
        compaction = input("compaction?:- ")
        compression = input("compression?:- ")
        cross_volume_dedupe = input("cross_volume_dedupe?:- ")
        dedupe = input("dedupe?:- ")
        policy_name_e = input("Efficiency Policy Name?:- ")
        efficiencyjson = {
            "compaction": compaction,
            "compression": compression,
            "cross_volume_dedupe": cross_volume_dedupe,
            "dedupe": dedupe,
            "policy": {
                "name": policy_name_e
            }
        }
        dataobj['efficiency'] = efficiencyjson
    print()
    encryption = input("Would you like to enable Encryption (y/n): ")
    if encryption == 'y':
        print("Enter the following Details")
        enabled_encry = input("Enable Encryption ?:- ")
        encryptionjson = {"enabled": bool(enabled_encry), "status": {}}
        dataobj['encryption'] = encryptionjson
    print()
    files = input("Would you like to enable Max File Count (y/n): ")
    if files == 'y':
        print("Enter the following Details")
        maximum_files = input("Max File Count?:- ")
        filesjson = {"maximum": maximum_files}
        dataobj['files'] = filesjson
    print()
    nas = input("Would you like to enable NAS parameters (y/n): ")
    if nas == 'y':
        print("Enter the following Details")
        export_policy_name = input("export_policy_name?:- ")
        path = input("path?:- ")
        security_style = input("security_style?:- ")
        unix_permissions = input("unix_permissions?:- ")
        nasjson = {
            "export_policy": {
                "name": export_policy_name
            },
            "path": path,
            "security_style": security_style,
            "unix_permissions": unix_permissions
        }
        dataobj['efficiency'] = nasjson
    print()
    qos = input("Would you like to enable QoS (y/n): ")
    if qos == 'y':
        print("Enter the following Details")
        max_throughput_iops = input("max_throughput_iops?:- ")
        max_throughput_mbps = input("max_throughput_mbps?:- ")
        min_throughput_iops = input("min_throughput_iops?:- ")
        qosname = input("qosname?:- ")
        qosjson = {
            "policy": {
                "max_throughput_iops": max_throughput_iops,
                "max_throughput_mbps": max_throughput_mbps,
                "min_throughput_iops": min_throughput_iops,
                "name": qosname
            }
        }
        dataobj['qos'] = qosjson
    print()
    quota = input("Would you like to enable Quota (y/n): ")
    if quota == 'y':
        print("Enter the following Details")
        enable_quota = input("enable_quota?:- ")
        quotajson = {"enabled": bool(enable_quota)}
        dataobj['quota'] = quotajson

    vol_uuid = get_key_volumes(svm_name, volname, cluster, headers_inc)
    print()
    urlpath = "https://{}/api/storage/volumes/" + vol_uuid
    url = urlpath.format(cluster)
    try:
        response = requests.patch(url,
                                  headers=headers_inc,
                                  json=dataobj,
                                  verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    try:
        job_response = requests.get(job_status,
                                    headers=headers_inc,
                                    verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = job_response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = job_response.json()
    check_job_status(job_status, headers_inc, cluster)
    return
def clone_volume(cluster: str, headers_inc: str):
    """ Clone a volume"""
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volume_name = input(
        "Enter the name of the volume that needs to be Cloned:- ")
    vol_uuid = get_key_volumes(svm_name, volume_name, cluster, headers_inc)
    print()
    clone_name = input("Enter the name of the clone:- ")
    dataobj = {}
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    tmp = {'uuid': svm_uuid}
    dataobj['svm'] = tmp
    dataobj['name'] = clone_name
    clone_volume_json = {
        "is_flexclone": bool("true"),
        "parent_svm": {
            "name": svm_name,
            "uuid": svm_uuid
        },
        "parent_volume": {
            "name": volume_name,
            "uuid": vol_uuid
        }
    }
    dataobj['clone'] = clone_volume_json
    clonesnapshot = input("Would you like to Clone from Snapshot (y/n): ")
    if clonesnapshot == 'y':
        show_snapshot(svm_name, volume_name, cluster, headers_inc)
        snapshot_name = input(
            "Enter the name of the snapshot that needs to be Cloned:- ")
        snapshot_uuid = get_key_snapshot(svm_name, volume_name, snapshot_name,
                                         cluster, headers_inc)
        clone_snapshot_json = {
            "is_flexclone": bool("true"),
            "parent_snapshot": {
                "name": snapshot_name,
                "uuid": snapshot_uuid
            },
            "parent_svm": {
                "name": svm_name,
                "uuid": svm_uuid
            },
            "parent_volume": {
                "name": volume_name,
                "uuid": vol_uuid
            }
        }
        dataobj['clone'] = clone_snapshot_json
    print(dataobj)
    url = "https://{}/api/storage/volumes".format(cluster)
    try:
        response = requests.post(url,
                                 headers=headers_inc,
                                 json=dataobj,
                                 verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    try:
        job_response = requests.get(job_status,
                                    headers=headers_inc,
                                    verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = job_response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = job_response.json()
    check_job_status(job_status, headers_inc, cluster)