Пример #1
0
func (driver *Driver) getSnapshot(snapshotID, snapshotName string) ([]*xmsv3.Snapshot, error) {
	var snapshots []*xmsv3.Snapshot
	if snapshotID != "" || snapshotName != "" {
		snapshot, err := goxtremio.GetSnapshot(snapshotID, snapshotName)
		if err != nil {
			return nil, err
		}
		snapshots = append(snapshots, snapshot)
	} else {
		allSnapshots, err := goxtremio.GetSnapshots()
		if err != nil {
			return nil, err
		}
		for _, snapshot := range allSnapshots {
			hrefFields := strings.Split(snapshot.Href, "/")
			index, _ := strconv.Atoi(hrefFields[len(hrefFields)-1])
			snapshots = append(snapshots, &xmsv3.Snapshot{
				Name:  snapshot.Name,
				Index: index,
			})
		}
	}
	return snapshots, nil
}
Пример #2
0
//GetSnapshot returns snapshots from a volume or a specific snapshot
func (driver *Driver) GetSnapshot(volumeID, snapshotID, snapshotName string) ([]*storagedriver.Snapshot, error) {
	var snapshotsInt []*storagedriver.Snapshot
	if volumeID != "" {
		volumes, err := driver.getVolume(volumeID, "")
		if err != nil {
			return nil, err
		}

		for _, volume := range volumes {
			for _, destSnap := range volume.DestSnapList {
				snapshot, err := driver.getSnapshot(strconv.Itoa(int(destSnap.([]interface{})[2].(float64))), "")
				if err != nil {
					return nil, err
				}

				volSize, _ := strconv.Atoi(volume.VolSize)
				snapshotSD := &storagedriver.Snapshot{
					Name:        snapshot[0].Name,
					VolumeID:    strconv.Itoa(volume.Index),
					SnapshotID:  strconv.Itoa(snapshot[0].Index),
					VolumeSize:  strconv.Itoa(volSize / 1024 / 1024),
					StartTime:   snapshot[0].CreationTime,
					Description: "",
					Status:      "",
				}
				snapshotsInt = append(snapshotsInt, snapshotSD)
			}
		}
	} else {
		snapshots, err := driver.getSnapshot(snapshotID, snapshotName)
		if err != nil {
			return nil, err
		}

		for _, snapshot := range snapshots {
			snapshot, err := goxtremio.GetSnapshot(strconv.Itoa(snapshot.Index), "")
			if err != nil {
				return nil, err
			}

			volume, err := driver.getVolume(strconv.Itoa(int(snapshot.AncestorVolID[2].(float64))), "")
			if err != nil {
				return nil, err
			}

			volSize, _ := strconv.Atoi(volume[0].VolSize)
			snapshotSD := &storagedriver.Snapshot{
				Name:        snapshot.Name,
				VolumeID:    strconv.Itoa(int(snapshot.AncestorVolID[2].(float64))),
				SnapshotID:  strconv.Itoa(snapshot.Index),
				VolumeSize:  strconv.Itoa(volSize / 1024 / 1024),
				StartTime:   snapshot.CreationTime,
				Description: "",
				Status:      "",
			}
			snapshotsInt = append(snapshotsInt, snapshotSD)
		}

	}

	return snapshotsInt, nil
}