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)
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 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)