def make_snap_pycl(vol_name: str, snapshot_name: str, svm_name: str) -> None:
    """Create a new snapshot with default settings for a given volume"""

    volume = Volume.find(**{'svm.name': svm_name, 'name': vol_name})
    snapshot = Snapshot(volume.uuid, name=snapshot_name)

    try:
        snapshot.post()
        print("Snapshot %s created successfully" % snapshot.name)
    except NetAppRestError as err:
        print("Error: Snapshot was not created: %s" % err)
def make_snap(vol_name: str, snapshot_name: str) -> Optional[Snapshot]:
    """Create a new snapshot with default settings for a given volume"""

    volume = Volume.find(name=vol_name)
    snapshot = Snapshot(volume.uuid, name=snapshot_name)

    try:
        snapshot.post()
        print("Snapshot %s created successfullys" % snapshot.name)
        return snapshot
    except NetAppRestError as err:
        print("Error: Snapshot was not created: %s" % err)
    return None
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 patch_snapshot() -> None:
    """Update Snapshot"""
    print("=============================================")
    print()
    vol_uuid = show_snapshot()
    print()
    print("=============================================")
    print("Please enter the following to update the required snapshot")

    snapshot_name = input("Enter the name of the snapshot to be updated:-")

    snapshot = Snapshot.find(vol_uuid, name=snapshot_name)
    snapbool = input("Would you like to update the name (y/n): ")
    if snapbool == 'y':
        snapname = input("Enter the name of the snapshot to be updated:-")
        snapshot.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:-")
        snapshot.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):-"
        )
        snapshot.expiry_time = snapexpiry

    try:
        if snapshot.patch(poll=True):
            print("Snapshot  %s Updated Successfully" % snapshot.name)
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
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']
Example #6
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))
Example #7
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))
Example #8
0
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
Example #9
0
def show_snapshot(svm_name, volume_name) -> None:
    """List Snapshots in a volume"""
    print()
    vol_uuid = get_key_volume(svm_name, volume_name)
    print("The List of Snapshots:-")
    print("=======================")
    try:
        for snapshot in Snapshot.get_collection(vol_uuid):
            print(snapshot.name)
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
def lista_snapshots(nombre_vol, vol_uuid) -> None:
    try:
        print()
        print("Listado de Snapshots para el volumen << %s >>" % nombre_vol)
        print()
        for snapshot in Snapshot.get_collection(vol_uuid):
            print(" - " + snapshot.name)
    except NetAppRestError as error:
        print("Volumen inexistente!\n " +
              error.http_err_response.http_response.text)
        print("   --- por favor, especifique un volumen valido ---")
    print("\n")
Example #11
0
    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))
Example #12
0
def patch_snapshot() -> None:
    """Update 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()

    snapshot_name = input("Enter the name of the snapshot to be updated:-")

    snapshot = Snapshot.find(vol_uuid, name=snapshot_name)
    snapbool = input("Would you like to update the name (y/n): ")
    if snapbool == 'y':
        snapname = input("Enter the name of the snapshot to be updated:-")
        snapshot.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:-")
        snapshot.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):-"
        )
        snapshot.expiry_time = snapexpiry

    try:
        if snapshot.patch(poll=True):
            print("Snapshot  %s Updated Successfully" % snapshot.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def show_snapshot() -> None:
    """List Snapshots in a volume"""
    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()
    vol_uuid = input(
        "Enter the Volume UUID from which the Snapshots need to be listed [UUID]:-"
    )

    print("The List of Snapshots:-")
    try:
        for snapshot in Snapshot.get_collection(vol_uuid):
            print(snapshot.name)
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
Example #14
0
def list_snapshot() -> None:
    """List Snapshots in a volume"""
    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()
    print("The List of Snapshots:-")
    print("=======================")
    try:
        for snapshot in Snapshot.get_collection(vol_uuid):
            print(snapshot.name)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def delete_snapshot() -> None:
    """Delete Snapshot"""
    print("=============================================")
    print()
    vol_uuid = show_snapshot()
    print()
    print("=============================================")
    print("please enter the following the details to delete snapshot.")
    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("Error:- " % error.http_err_response.http_response.text)
        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("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
Example #16
0
def get_snapshot(volume, snapshot_name):
    return (Snapshot.find(volume.uuid, name=snapshot_name))
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()
Example #18
0
def get_snapshot_list(volume):
    result = Snapshot.get_collection(volume.uuid, name="*")
    lst = list(result)
    lst.reverse()  # sort from more to least recent
    return lst