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 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)
def nfs_setup(cluster: str, headers_inc: str): """Demonstrates NFS Setup using REST APIs.""" print("Demonstrates NFS Setup using REST APIs.") print("=======================================") print() show_svm(cluster, headers_inc) print() svm_name = input( "Choose the SVM on which you would like to create a NFS Share :") print("Make sure that NAS LIFs on each nodes are created on the SVM :") print() print("Checking and Enabling NFS Protocol on SVM:-") print("===========================================") payload1 = { "enabled": bool("true"), "protocol": { "v3_enabled": bool("true") }, "svm": { "name": svm_name } } url1 = "https://{}/api/protocols/nfs/services".format(cluster) try: response = requests.post(url1, headers=headers_inc, json=payload1, 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) print() print("Create the Export Policy:-") print("==========================") export_policy_name = input("Enter the Export Policy Name :- ") protocol = input( "Enter the protocol name for the Export Policy(nfs/cifs/any):- ") clients = input("Enter client details [0.0.0.0/0]:- ") url2 = "https://{}/api/protocols/nfs/export-policies".format(cluster) svm_uuid = get_key_svms(svm_name, cluster, headers_inc) payload2 = { "name": export_policy_name, "rules": [{ "clients": [{ "match": clients }], "protocols": [protocol], "ro_rule": ["any"], "rw_rule": ["any"] }], "svm.uuid": svm_uuid } try: response = requests.post(url2, 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) url_text = response.json() print() print("Create the Volume:-") print("===================") vol_name = input("Enter the Volume Name to create NFS Share:-") vol_size = input("Enter the Volume Size in MBs :-") aggr_name = input("Enter the aggregate name:-") v_size = get_size(vol_size) pather = "/" + vol_name payload3 = { "aggregates": [{ "name": aggr_name }], "svm": { "name": svm_name }, "name": vol_name, "size": v_size, "nas": { "export_policy": { "name": export_policy_name }, "security_style": "unix", "path": pather } } url3 = "https://{}/api/storage/volumes".format(cluster) try: response = requests.post(url3, headers=headers_inc, json=payload3, verify=False) print("Volume %s created" % vol_name) 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("NAS creation script completed.")
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 create_quotarule(cluster: str, headers_inc: str) -> None: """Create Quota Rule """ print() show_svm(cluster, headers_inc) print() svm_name = input( "Enter the SVM from which the Volumes need to be listed:-") svm_uuid = get_key_svms(svm_name, cluster, headers_inc) print() show_volume(cluster, headers_inc, svm_name) print() volume_name = input( "Enter the Volume on which the Quotas needs to be created:-") print() vol_uuid = 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("Quota created successfully...")
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)