Esempio n. 1
0
def patch_svm() -> None:
    """Update SVM"""
    print()
    show_svm()
    print("=============================================")
    svmname = input("Enter the name of the SVM that needs to be updated: ")
    svm = Svm.find(name=svmname)
    lanbool = input("Would you like to update language (y/n): ")
    if lanbool == 'y':
        lan = input(
            "Enter the name of language the you would like to update: ")
        svm.language = lan
    namebool = input("Would you like to update the name (y/n): ")
    if namebool == 'y':
        nam = input("Enter the name of SVM: ")
        svm.name = nam
    snapbool = input("Would you like to update an SnapShot Policy (y/n): ")
    if snapbool == 'y':
        snap = input(
            "Enter the name of default snapshot policy that needs to ne updated : "
        )
        svm.snapshot_policy = snap
    aggrbool = input(
        "Would you like to update the SVM with new Aggregate (y/n): ")
    if aggrbool == 'y':
        aggr = input(
            "Enter the name of aggregates(with commas) that needs to be updated : "
        )
        svm.aggregates.name = aggr

    try:
        if svm.patch(poll=True):
            print("SVM  %s has been updated/patched Successfully" % svm.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def list_volume(cluster: str, headers_inc: str):
    """ List the volumes"""
    print("The List of SVMs")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    print("Getting Volume Details")
    print("======================")
    url = "https://{}/api/storage/volumes/?svm.name={}".format(
        cluster, svm_name)
    try:
        response = requests.get(url, 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 = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    tmp = dict(response.json())
    svms = tmp['records']
    print()
    print("List of Volumes :- ")
    print("===================")
    for i in svms:
        print("Volume Name :- %s; Volume UUID :- %s" % (i['name'], i['uuid']))
def patch_file_permissions(cluster: str, headers_inc: str):
    """ patch file permissions"""
    print(
        "=================Modify file permissions interface=================")
    print(
        "===================================================================")
    print()
    dataobj = {}
    show_svm(cluster, headers_inc)
    svm_name = input("\n\n Enter the svm name: ")
    path = input("\n Enter the path (target): ")
    path = urllib.parse.quote(path)
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    control_flags = input(
        "\nEnter the control flags (Hexadecimal value e.g: 8014): ")
    group = input("Enter the owner's primary group: ")
    owner = input(" Enter the owner of the SD: ")
    print()
    dataobj['control_flags'] = control_flags
    dataobj['group'] = group
    dataobj['owner'] = owner
    print()
    url = "https://{}/api/protocols/file-security/permissions/{}/{}".format(
        cluster, svm_uuid, path)
    print(url)
    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()
    print(url_text)
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    print("New job is created for this creation ... \n {}", job_status)
    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 get_file_security_permissions(cluster: str, headers_inc: str):
    """ Retrieving file security permissions"""
    print()
    print("=======================================")
    print("  Getting File Security Permissions  ")
    print("=======================================")
    show_svm(cluster, headers_inc)
    svm_name = input("\n Enter the svm name:")
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    path = input("\nEnter the path (target path): ")
    api_url = "https://{}/api/protocols/file-security/permissions/{}/{}".format(
        cluster, svm_uuid, path)
    print(api_url)
    try:
        response = requests.get(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()
    print(url_text)
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    print("\nRetrieving File security permissions for target path\n ")
    print(json.dumps(response.json(), indent=7))
Esempio n. 5
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))
def create_igroup() -> None:
    """Create Initiator Group."""
    print("Create Initiator Group.")
    print("=======================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the name of the SVM on which the volume needs to be created:- ")
    igroup_name = input(
        "Enter the name of the Igroup that you would like to create  : ")
    initiator_name = input(
        "Enter the name of the Initiator that you would like to add in the InitiatorGroup :"
    )
    os_type2 = input("Enter the OS-TYPE :")

    payload3 = {
        "initiators": [{
            "name": initiator_name
        }],
        "name": igroup_name,
        "os_type": os_type2,
        "svm": {
            "name": svm_name
        }
    }

    igroup_object = Igroup.from_dict(payload3)

    try:
        if igroup_object.post(poll=True):
            print("IGROUP created  %s created Successfully" %
                  igroup_object.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Esempio n. 7
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))
Esempio n. 8
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))
Esempio n. 9
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))
Esempio n. 10
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
Esempio n. 11
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))
Esempio n. 12
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)
Esempio n. 13
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))
def delete_initiator(cluster, headers_inc):
    """Delete Initiator Group"""

    print("=============================================")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_igroup(svm_name, cluster, headers_inc)
    igroup_name = input("Enter the Igroup name:- ")
    igroup_uuid = get_key_igroup(svm_name, igroup_name, cluster, headers_inc)

    url = "https://{}/api/protocols/san/igroups/{}".format(
        cluster, igroup_uuid)
    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)

    print("Initiator Group  has been deleted.")
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_interface(cluster: str, headers_inc: str):
    """Create Interface"""
    int_name = input("Enter the name of the Interface:- ")
    print()
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the name of the SVM on which the interface should be created :- "
    )
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    print()
    show_node(cluster, headers_inc)
    print()
    node_name = input(
        "Enter the name of the home node on which the interface should be created :- "
    )
    node_uuid = input(
        "Enter the uuid of the home node on which the interface should be created :- "
    )
    ip_add = input("Enter the IP address:- ")
    netmask = input("Enter the NetMask:- ")

    interfaceobj = {
        "enabled": True,
        "ip": {
            "address": ip_add,
            "netmask": netmask
        },
        "name": int_name,
        "scope": "svm",
        "svm": {
            "name": svm_name,
            "uuid": svm_uuid
        },
        "location": {
            "home_node": {
                "name": node_name,
                "uuid": node_uuid
            }
        }
    }
    url = "https://{}/api/network/ip/interfaces".format(cluster)
    try:
        response = requests.post(url,
                                 headers=headers_inc,
                                 json=interfaceobj,
                                 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("Interface 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")
Esempio n. 18
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))
Esempio n. 19
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)
def delete_file_permissions(cluster: str, headers_inc: str):
    """ file permissions delete"""
    print(
        "=================Modify file permissions interface=================")
    print(
        "===================================================================")
    print()
    dataobj = {}
    show_svm(cluster, headers_inc)
    svm_name = input("\n\n Enter the svm name: ")
    path = input("\n Enter the path (target): ")
    path = urllib.parse.quote(path)
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    user = input("\nEnter the user name:  ")
    print()
    url = "https://{}/api/protocols/file-security/permissions/{}/{}/acl/{}".format(
        cluster, svm_uuid, path, user)
    print(url)
    try:
        response = requests.delete(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()
    print(url_text)
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    print("New job is created for this creation ... \n {}", job_status)
    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)
Esempio n. 21
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)
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)
Esempio n. 23
0
def create_interface():
    """Create Interface"""
    int_name = input("Enter the name of the Interface:- ")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the name of the SVM on which the interface should be created :- "
    )
    svm_uuid = input(
        "Enter the UUID of the SVM on which the interface should be created :- "
    )
    print()
    show_node()
    print()
    node_name = input(
        "Enter the name of the home node on which the interface should be created :- "
    )
    node_uuid = input(
        "Enter the uuid of the home node on which the interface should be created :- "
    )
    ip_add = input("Enter the IP address:- ")
    netmask = input("Enter the NetMask:- ")

    interfaceobj = {
        "enabled": True,
        "ip": {
            "address": ip_add,
            "netmask": netmask
        },
        "name": int_name,
        "scope": "svm",
        "svm": {
            "name": svm_name,
            "uuid": svm_uuid
        },
        "location": {
            "home_node": {
                "name": node_name,
                "uuid": node_uuid
            }
        }
    }
    try:
        ipint = IpInterface.from_dict(interfaceobj)
        if ipint.post(poll=True):
            print("Interface created successfully.")
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
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))
Esempio n. 25
0
def start_svm(cluster: str, headers_inc: str):
    """ starts svm"""
    show_svm(cluster, headers_inc)
    print()
    print("=============================================")
    print("This option starts a SVM: ")
    print()
    svm_name = input("Enter the SVM which needs to be started:-")
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    print()
    print("The UUID of the requested SVM is:-")
    print(svm_uuid)
    dataobj = {"state": "running", "comment": "This SVM is running."}
    urlpath = "https://{}/api/svm/svms/" + svm_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)
Esempio n. 26
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)
Esempio n. 27
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)
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)
Esempio n. 29
0
def stop_svm() -> None:
    """Stop SVM"""
    print()
    show_svm()
    print("=============================================")
    print()
    svmname = input(
        "Enter the name of the SVM name that needs to be stopped: ")
    svm = Svm.find(name=svmname)
    svm.state = "stopped"

    try:
        if svm.patch(poll=True):
            print("SVM  %s has been stopped Successfully." % svm.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Esempio n. 30
0
def delete_svm() -> None:
    """Delete SVM"""
    print()
    show_svm()
    print("=============================================")
    print()
    svmname = input("Enter the name of the SVM that needs to be deleted: ")
    try:
        svm = Svm.find(name=svmname)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))

    try:
        if svm.delete(poll=True):
            print("SVM  %s has been deleted Successfully." % svm.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))