def netappSnapshot( ontapClusterMgmtHostname: str, pvName: str, verifySSLCert: bool = True ) -> str : # Install netapp_ontap package import sys, subprocess; subprocess.run([sys.executable, '-m', 'pip', 'install', 'netapp_ontap']) # Import needed functions/classes from netapp_ontap import config as netappConfig from netapp_ontap.host_connection import HostConnection as NetAppHostConnection from netapp_ontap.resources import Volume, Snapshot from datetime import datetime import json # Retrieve ONTAP cluster admin account details from mounted K8s secrets usernameSecret = open('/mnt/secret/username', 'r') ontapClusterAdminUsername = usernameSecret.read().strip() passwordSecret = open('/mnt/secret/password', 'r') ontapClusterAdminPassword = passwordSecret.read().strip() # Configure connection to ONTAP cluster/instance netappConfig.CONNECTION = NetAppHostConnection( host = ontapClusterMgmtHostname, username = ontapClusterAdminUsername, password = ontapClusterAdminPassword, verify = verifySSLCert ) # Convert pv name to ONTAP volume name # The following will not work if you specified a custom storagePrefix when creating your # Trident backend. If you specified a custom storagePrefix, you will need to update this # code to match your prefix. volumeName = 'trident_%s' % pvName.replace("-", "_") print('\npv name: ', pvName) print('ONTAP volume name: ', volumeName) # Create snapshot; print API response volume = Volume.find(name = volumeName) timestamp = datetime.today().strftime("%Y%m%d_%H%M%S") snapshot = Snapshot.from_dict({ 'name': 'kfp_%s' % timestamp, 'comment': 'Snapshot created by a Kubeflow pipeline', 'volume': volume.to_dict() }) response = snapshot.post() print("\nAPI Response:") print(response.http_response.text) # Retrieve snapshot details snapshot.get() # Convert snapshot details to JSON string and print snapshotDetails = snapshot.to_dict() print("\nSnapshot Details:") print(json.dumps(snapshotDetails, indent=2)) # Return name of newly created snapshot return snapshotDetails['name']
def create_snapshot() -> None: """Create snapshot """ print() print("The List of SVMs") show_svm() print() svm_name = input( "Enter the SVM on which the Volume Snapshot need to be created:-") print() show_volume(svm_name) print() vol_uuid = input( "Enter the Volume UUID on which the Snapshots need to be created[UUID]:-" ) 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("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error))
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_snapshot(volume, basename): snapshot = None if volume and basename: seq = int(time.time()) snapshot = Snapshot.from_dict({ 'name': '%s_%d' % (basename, seq), 'volume': volume.to_dict(), }) snapshot.post() return snapshot
async def create_snapshot(self, message): """ A skills function to take a snapshot of a volume. The parser looks for the message argument. Arguments: message {str} -- create a snapshot of {volume} on svm {svm} """ name = message.regex.group('name') svm = message.regex.group('svm') time = datetime.now() time = str(time) volume = Volume.find(name=name, svm={'name': svm}) volume.get() snapshot = Snapshot.from_dict({ 'name': 'snapshot_%s' % time, 'volume': volume.to_dict(), }) snapshot.post() await message.respond('All done! Response: {}'.format(snapshot))
from netapp_ontap import config from netapp_ontap import HostConnection from netapp_ontap.resources import Cluster, Aggregate, Port, Volume, Autosupport, IpInterface, Disk, Chassis, Account, Svm, Snapshot from datetime import datetime import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) conn = HostConnection('192.168.1.200', username='******', password='******', verify=False) config.CONNECTION = conn #vol = Volume.find(name='movies') #vol.get() #print(vol) #volume = Volume(name='vol1', svm={'name': 'study'}, aggregates=[{'name': 'ntap_study_data'}]) #volume.post() time = datetime.now() time = str(time) volume = Volume.find(name='soccer', svm={'name': 'study'}) volume.get() snapshot = Snapshot.from_dict({ 'name': 'snapshot_%s' % time, 'volume': volume.to_dict(), }) snapshot.post()