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 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)
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)
示例#4
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)
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)
示例#6
0
def get_cluster_jobs(cluster: str, headers_inc: str):
    "update the ONTAP cluster software version"
    #assuming the package of ONTAP is already added"
    ontap_version = input("Enter the ontap software version to upgrade to :  ")
    dataobj = {"version": ontap_version}
    print(dataobj)

    url = "https://{}/api/cluster/software?skip_warnings=true".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)
    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)
示例#7
0
def update_svm(cluster: str, headers_inc: str):
    """ updates the svm"""
    show_svm(cluster, headers_inc)
    print("This option Updates a SVM: ")
    print()
    svm_name = input("Enter the SVM which needs to be updated:-")
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    print()
    print("The UUID of the requested SVM is:-")
    print(svm_uuid)
    urlpath = "https://{}/api/svm/svms/" + svm_uuid
    dataobj = {}
    dataobj['state'] = "running"
    print(dataobj)
    print()
    lanbool = input("Would you like to update language (y/n): ")
    if lanbool == 'y':
        lan = input("Enter the name of language: ")
        dataobj['language'] = lan
    print()
    namebool = input("Would you like to update the name (y/n): ")
    if namebool == 'y':
        nam = input("Enter the new  name of SVM: ")
        dataobj['name'] = nam
    print()
    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 : "
        )
        dataobj['snapshot_policy'] = snap
    print()
    aggrbool = input("Would you like to update Aggregate (y/n): ")
    if aggrbool == 'y':
        aggr = input(
            "Enter the name of aggregates(with commas) that needs to ne updated : "
        )
        dataobj['aggregates'] = {"aggregates": {"name": ["aggr"]}}
    print()
    print("\n JSON file to be submitted:-")
    print(dataobj)
    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)
示例#8
0
def create_svm(cluster: str, headers_inc: str):
    """ create svm"""
    svmname = input("Enter the name of the SVM: ")
    dataobj = {}
    dataobj['name'] = svmname
    dataobj['language'] = "c.utf_8"
    ipspaceobj = {"name": "Default"}
    dataobj['ipspace'] = ipspaceobj
    print()
    intbool = input("Would you like to configure an Interface (y/n): ")
    if intbool == 'y':
        mgmtlif = input("Enter the name of Management LIF: ")
        ipadd = input("Enter the IP address: ")
        nmask = input("Enter the NetMask: ")
        show_node(cluster, headers_inc)
        hnode = input("Enter the Home Node: ")
        uuid = input("Enter the UUID: ")
        intjson = [{
            "ip": {
                "address": ipadd,
                "netmask": nmask
            },
            "location": {
                "broadcast_domain": {
                    "name":
                    "Default_ckjfbvsnkfdjasbdkfsndlfe_cbekjrvckujeakbxjwc"
                },
                "home_node": {
                    "name": hnode,
                    "uuid": uuid
                }
            },
            "name": mgmtlif,
            "service_policy": "default-data-files"
        }]
        dataobj['ip_interfaces'] = intjson
    print()
    nfsbool = input("Would you like to configure an NFS (y/n): ")
    if nfsbool == 'y':
        nfsjson = {"enabled": bool("true")}
        dataobj['nfs'] = nfsjson
    print()
    cifsbool = input("Would you like to configure an CIFS (y/n): ")
    if cifsbool == 'y':
        fqdn = input("Enter the name of FQDN: ")
        aduser = input("Enter the User: "******"Enter the password: "******"Enter the AD Name: ")
        cifsjson = {
            "ad_domain": {
                "fqdn": fqdn,
                "password": adpassword,
                "user": aduser
            },
            "enabled": bool("true"),
            "name": adname
        }
        dataobj['cifs'] = cifsjson
    print()
    dnsbool = input("Would you like to configure an DNS (y/n): ")
    if dnsbool == 'y':
        domain = input("Enter the name of Domain: ")
        server = input("Enter the Server: ")
        dnsjson = {"domains": [domain], "servers": [server]}
        dataobj['dns'] = dnsjson

    print(dataobj)
    url = "https://{}/api/svm/svms".format(cluster)
    try:
        response = requests.post(url,
                                 headers=headers_inc,
                                 json=dataobj,
                                 verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        print(response)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        print(response)
        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)
        print(job_response)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        print(job_response)
        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 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)
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 create_volume(cluster: str, headers_inc: str):
    """Create volume"""
    print()
    show_svm(cluster, headers_inc)
    print()
    svmname = input(
        "Enter the name of the SVM on which the volume needs to be created:- ")
    dataobj = {}
    tmp1 = {"name": svmname}
    dataobj['svm'] = tmp1
    print()
    show_aggregate(cluster, headers_inc)
    print()
    aggrname = input(
        "Enter the name of the Aggregate on which the volume needs to be created:- "
    )
    tmp2 = [{"name": aggrname}]
    dataobj['aggregates'] = tmp2
    print()
    volname = input("Enter the name of the Volume:- ")
    dataobj['name'] = volname
    print()
    vol_size = input("Enter the size of the Volume in MB:- ")
    tmp3 = get_size(vol_size)
    dataobj['size'] = tmp3
    print()
    voltype = input("Enter the Volume Type[rw/dp]:- ")
    dataobj['type'] = voltype
    print()
    styletype = input("Enter the Volume Style Type[flexvol]:- ")
    dataobj['style'] = styletype
    print()
    autosize = input("Would you like to enable Autosize (y/n): ")
    if autosize == '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
    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)
def create_file_security_permissions(cluster: str, headers_inc: str):
    """ create file_security_permissions """
    print("=============================================")
    print()
    print("\n Enter the following Details of acls \n")
    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)
    # path = base64.b64encode(path)
    print("Path is ", path)
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    url = "https://{}/api/protocols/file-security/permissions/{}/{}".format(
        cluster, svm_uuid, path)
    print(url)
    access = input("dacl/sacl access? [e.g: access_allow]: ")
    files = input("apply to files? [True]: ")
    sub_folders = input("apply to sub_folders? [True]: ")
    this_folder = input("apply to this_folder? [True]: ")
    rights = input("Enter the access right control [e.g: full_control] : ")
    user = input("Enter the user account name or SID to ACE applies: ")
    temp1 = {
        "files": files,
        "sub_folders": sub_folders,
        "this_folder": this_folder
    }
    acls = [{
        "access": access,
        "apply_to": temp1,
        "rights": rights,
        "user": user
    }]
    dataobj['acls'] = acls
    # below line to be removed in 9.9.1
    #dataobj["access_control"] = "file_directory"
    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: ")
    propagation_mode = input(" Enter the propogation mode: ")
    print()
    dataobj['control_flags'] = control_flags
    dataobj['group'] = group
    dataobj['owner'] = owner
    dataobj['propagation_mode'] = propagation_mode
    print(dataobj)
    #url_path = "https://{}/api/protocols/file-security/permissions/" + svm_uuid + path

    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()
    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)
示例#13
0
def xdp_new_dest_svm(cluster: str, headers_inc: str):
    "Provision the destination SVM endpoint and create a SnapMirror relationship of type XDP."
    endpoint = "api/snapmirror/relationships"
    url = "https://{}/{}".format(cluster, endpoint)
    source_cluster = input("\nEnter the Source Cluster name: ")
    source_svm = input("\nEnter the Source SVM name: ")
    source_svm = source_svm + ':'
    des_svm = input("\nEnter name for destination svm: ")
    des_svm = des_svm + ':'
    print(des_svm)
    print()
    dataobj = {
        "create_destination": {
            "enabled": "true"
        },
        "source": {
            "path": source_svm,
            "cluster": {
                "name": source_cluster
            }
        },
        "destination": {
            "path": des_svm
        },
        "policy": {
            "name": "Asynchronous"
        },
        "state": "snapmirrored"
    }
    try:
        response = requests.post(url,
                                 headers=headers_inc,
                                 json=dataobj,
                                 verify=False)
        time.sleep(5)

    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)
    json_formatted_str = json.dumps(url_text, indent=2)
    print(json_formatted_str)