Exemple #1
0
def get_volume_name(serialno):
    array = purestorage_custom.FlashArray(flasharray,
                                          flasharrayuser,
                                          flasharraypassword,
                                          verify_https=False)
    vendor_string = serialno[0:8]
    volname = None
    if (vendor_string == '3624a937'):
        volumes = array.list_volumes()
        for key in volumes:
            volname = key.get("name")
            volserial = str(key.get("serial")).lower()
            found = volserial in serialno
            if found:
                return volname
    elif (vendor_string == '36000c29'):
        # Then this is a VMware vdisk volume ,need to check if it is vvol based
        vm_disk_info = None
        array = purestorage_custom.FlashArray(flasharray,
                                              flasharrayuser,
                                              flasharraypassword,
                                              verify_https=False)
        if (vcenteraddress is not None and vcenteruser is not None
                and vcenterpassword is not None):
            vcenter_dict = {
                'address': vcenteraddress,
                'vc_user': vcenteruser,
                'vc_pass': vcenterpassword
            }
        else:
            raise NameError(
                'The volume has been detected to be a virtual disk but no vCenter credentials have been supplied to further parse the request'
            )
        vm_disk_info = vsphere_get_vvol_disk_identifiers(
            serialno, vcenter_dict)
        if vm_disk_info is not None:
            volume = array.list_virtual_volume(
                vm_disk_info.get('backingObjectId'))
            if (volume.__len__() != 0):
                for attr in volume:
                    if (attr.get('key') == 'PURE_VVOL_ID'):
                        volname = attr.get('name')
                        vol = array.get_volume(volname)
                        vvolvolserial = vol.get('serial')
                        volumes_toparse = array.list_volumes()
                        for key in volumes_toparse:
                            thisvolname = key.get("name")
                            thisvolserial = str(key.get("serial")).lower()
                            found = thisvolserial.lower(
                            ) in vvolvolserial.lower()
                            if found:
                                volname = thisvolname
                                return volname
    return volname
Exemple #2
0
def create_flasharray_volume_snapshot(serialnumber, snapshot_suffix):
    array = purestorage_custom.FlashArray(flasharray,
                                          flasharrayuser,
                                          flasharraypassword,
                                          verify_https=False)
    snapserial = None
    vendor_string = serialnumber[0:8]
    # This is a disk directly attached to the host
    if (vendor_string == '3624a937'):
        volumes = array.list_volumes()
        for key in volumes:
            volname = key.get("name")
            volserial = str(key.get("serial")).lower()
            found = volserial.lower() in serialnumber.lower()
            if found:
                snapshot_id = array.create_snapshot(volname,
                                                    suffix=snapshot_suffix)
                snapserial = str(snapshot_id.get("serial"))
                return snapserial
    elif (vendor_string == '36000c29'):
        # Then this is a VMware vdisk volume ,need to check if it is vvol based
        vm_disk_info = None
        if (vcenteraddress is not None and vcenteruser is not None
                and vcenterpassword is not None):
            vcenter_dict = {
                'address': vcenteraddress,
                'vc_user': vcenteruser,
                'vc_pass': vcenterpassword
            }
        else:
            raise NameError(
                'The volume has been detected to be a virtual disk but no vCenter credentials have been supplied to further parse the request'
            )
        vm_disk_info = vsphere_get_vvol_disk_identifiers(
            serialnumber, vcenter_dict)
        if vm_disk_info is not None:
            volume = array.list_virtual_volume(
                vm_disk_info.get('backingObjectId'))
            if (volume.__len__() != 0):
                for attr in volume:
                    if (attr.get('key') == 'PURE_VVOL_ID'):
                        volname = attr.get('name')
                        vol = array.get_volume(volname)
                        vvolvolserial = vol.get('serial')
                        volumes = array.list_volumes()
                        for key in volumes:
                            volname = key.get("name")
                            volserial = str(key.get("serial")).lower()
                            found = volserial.lower() in vvolvolserial.lower()
                            if found:
                                snapshot_id = array.create_snapshot(
                                    volname, suffix=snapshot_suffix)
                                snapserial = str(snapshot_id.get("serial"))
                                return snapserial
    if (snapserial is None):
        raise NameError(
            'The volume was not found on this array or this is not a supported volume for a data snapshot'
        )
def check_storage_snapshot(backupid):
    array = purestorage_custom.FlashArray(flasharray,
                                          flasharrayuser,
                                          flasharraypassword,
                                          verify_https=False)
    volumes = array.list_volumes()
    for key in volumes:
        volname = key.get("name")
        snaps = array.get_volume(volname, snap=True)
        for snap in snaps:
            found = str(backupid) in snap.get("name")
            if found:
                return snap
Exemple #4
0
def create_protection_group_snap(volumes):
    instanceid = get_saphana_instanceid()
    pgname = "SAPHANA-" + instanceid + "-CrashConsistency"
    array = purestorage_custom.FlashArray(flasharray,
                                          flasharrayuser,
                                          flasharraypassword,
                                          verify_https=False)
    try:
        pgroup = array.get_pgroup(pgname)
    except Exception:
        array.create_pgroup(pgname)
    for vol in volumes:
        protectiongroups = array.add_volume(vol.get('volumename'), pgname)
    pgsnap = array.create_pgroup_snapshot(pgname)
    return pgsnap
def restore_copyvolume(snapshot, mount_point, backupid, serialno):
    array = purestorage_custom.FlashArray(flasharray,
                                          flasharrayuser,
                                          flasharraypassword,
                                          verify_https=False)
    new_volume = array.copy_volume(
        snapshot.get("name"),
        snapshot.get("source") + "-" + str(backupid))
    hosts = array.list_hosts()
    for host in hosts:
        host_volumes = array.list_host_connections(host.get("name"))
        for hostvol in host_volumes:
            if (hostvol.get("vol") != 'pure-protocol-endpoint'):
                volume = array.get_volume(hostvol.get("vol"))
                found = str(volume.get("serial")).lower() in serialno
                if found:
                    #disconnect existing data volume from host
                    array.disconnect_host(host.get("name"), volume.get("name"))
                    #operating system remove device maps
                    sshclient = prepare_ssh_connection()
                    rescan_scsi_bus_remove_string = "sudo rescan-scsi-bus.sh -r"
                    stdin, stdout, stderr = sshclient.exec_command(
                        rescan_scsi_bus_remove_string)
                    time.sleep(30)
                    opt = stdout.readlines()
                    #connect new data volume to host
                    array.connect_host(host.get("name"),
                                       new_volume.get("name"))
                    #operating system rescan for new device
                    rescan_scsi_bus_add_string = "sudo rescan-scsi-bus.sh -a"
                    stdin, stdout, stderr = sshclient.exec_command(
                        rescan_scsi_bus_add_string)
                    time.sleep(30)
                    opt = stdout.readlines()
                    #mount new volume
                    device_mount_string = "mount /dev/mapper/3624a9370" + new_volume.get(
                        "serial").lower() + " " + mount_point
                    stdin, stdout, stderr = sshclient.exec_command(
                        device_mount_string)
                    time.sleep(30)
                    sshclient.close()
                    returned_serial_number = get_volume_serialno(mount_point)
                    foundfinal = str(new_volume.get(
                        "serial")).lower() in returned_serial_number
                    if (foundfinal):
                        return True
                    else:
                        return False
def restore_overwrite_volume(snapshot, mount_point, backupid, serialno,
                             virtual_disk, data_vol_mount_point, block_device):
    array = purestorage_custom.FlashArray(flasharray,
                                          flasharrayuser,
                                          flasharraypassword,
                                          verify_https=False)
    volumes = array.list_volumes()
    new_volume = None
    if (virtual_disk):
        vm_disk_info = None
        if (vcenteraddress is not None and vcenteruser is not None
                and vcenterpassword is not None):
            vcenter_dict = {
                'address': vcenteraddress,
                'vc_user': vcenteruser,
                'vc_pass': vcenterpassword
            }
        else:
            raise NameError(
                'The volume has been detected to be a virtual disk but no vCenter credentials \
                have been supplied to further parse the request')
        vm_disk_info = vsphere_get_vvol_disk_identifiers(
            serialno, vcenter_dict)
        if vm_disk_info is not None:
            volume = array.list_virtual_volume(
                vm_disk_info.get('backingObjectId'))
            if (volume.__len__() != 0):
                for attr in volume:
                    if (attr.get('key') == 'PURE_VVOL_ID'):
                        volname = attr.get('name')
                        vol = array.get_volume(volname)
                        vvolvolserial = vol.get('serial')
                        volumes = array.list_volumes()
                        for key in volumes:
                            volname = key.get("name")
                            volserial = str(key.get("serial")).lower()
                            found = volserial.lower() in vvolvolserial.lower()
                            if found:
                                new_volume = array.copy_volume(
                                    snapshot.get("name"),
                                    volname,
                                    overwrite=True)
                                break
    else:
        for key in volumes:
            volname = key.get("name")
            volserial = str(key.get("serial")).lower()
            found = volserial in serialno
            if (found):
                new_volume = array.copy_volume(snapshot.get("name"),
                                               volname,
                                               overwrite=True)
                break
        if (new_volume is None):
            raise NameError(
                'There was an error location the source volume on the array')
    #operating system rescan for new device
    sshclient = prepare_ssh_connection()
    rescan_scsi_bus_add_string = "sudo rescan-scsi-bus.sh -a"
    stdin, stdout, stderr = sshclient.exec_command(rescan_scsi_bus_add_string)
    time.sleep(30)
    opt = stdout.readlines()
    #mount new volume
    device_mount_string = None
    if (data_vol_mount_point is not None and block_device is not None):
        device_mount_string = "mount " + block_device + " " + mount_point
    else:
        device_mount_string = "mount /dev/mapper/3624a9370" + new_volume.get(
            "serial").lower() + " " + mount_point
    stdin, stdout, stderr = sshclient.exec_command(device_mount_string)
    time.sleep(30)
    sshclient.close()
    returned_serial_number = get_volume_serialno(mount_point)
    foundfinal = returned_serial_number in serialno
    if (foundfinal):
        return True
    else:
        return False