コード例 #1
0
ファイル: list.go プロジェクト: flazz/rack
func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	pager := osSnapshots.List(command.Ctx.ServiceClient, opts)
	var snapshots []map[string]interface{}
	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		info, err := osSnapshots.ExtractSnapshots(page)
		if err != nil {
			return false, err
		}
		result := make([]map[string]interface{}, len(info))
		for j, snapshot := range info {
			result[j] = snapshotSingle(&snapshot)
		}
		snapshots = append(snapshots, result...)
		return true, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
	if len(snapshots) == 0 {
		resource.Result = nil
	} else {
		resource.Result = snapshots
	}
}
コード例 #2
0
ファイル: storage.go プロジェクト: bkeyoumarsi/rexray
func (driver *Driver) getSnapshot(volumeID, snapshotID, snapshotName string) (allSnapshots []snapshots.Snapshot, err error) {

	if snapshotID != "" {
		snapshot, err := snapshots.Get(driver.ClientBlockStorage, snapshotID).Extract()
		if err != nil {
			return []snapshots.Snapshot{}, err
		}

		allSnapshots = append(allSnapshots, *snapshot)
	} else {
		opts := snapshots.ListOpts{
			VolumeID: volumeID,
			Name:     snapshotName,
		}

		allPages, err := snapshots.List(driver.ClientBlockStorage, opts).AllPages()
		if err != nil {
			return []snapshots.Snapshot{}, err
		}

		allSnapshots, err = snapshots.ExtractSnapshots(allPages)
		if err != nil {
			return []snapshots.Snapshot{}, fmt.Errorf("Failed to extract snapshots: %v", err)
		}
	}

	return allSnapshots, nil
}
コード例 #3
0
// GetSnapshots collects snapshot data by sending REST call to cinderhost:8776/v1/tenant_id/snapshots
func (s ServiceV1) GetSnapshots(provider *gophercloud.ProviderClient) (map[string]types.Snapshots, error) {
	snaps := map[string]types.Snapshots{}

	client, err := openstack.NewBlockStorageV1(provider, gophercloud.EndpointOpts{})
	if err != nil {
		return snaps, err
	}

	opts := snapshots.ListOpts{}

	pager := snapshots.List(client, opts)
	page, err := pager.AllPages()
	if err != nil {
		return snaps, err
	}

	snapshotList, err := snapshots.ExtractSnapshots(page)
	if err != nil {
		return snaps, err
	}

	for _, snapshot := range snapshotList {
		snapCounts := snaps["tenant_id"]
		snapCounts.Count += 1
		snapCounts.Bytes += snapshot.Size * 1024 * 1024 * 1024
	}

	return snaps, nil
}
コード例 #4
0
// 	// Snapshots returns all volumes or a filtered list of snapshots.
func (d *driver) Snapshots(
	ctx types.Context,
	opts types.Store) ([]*types.Snapshot, error) {
	allPages, err := snapshots.List(d.clientBlockStorage, nil).AllPages()
	if err != nil {
		return []*types.Snapshot{},
			goof.WithError("error listing volume snapshots", err)
	}
	allSnapshots, err := snapshots.ExtractSnapshots(allPages)
	if err != nil {
		return []*types.Snapshot{},
			goof.WithError("error listing volume snapshots", err)
	}

	var libstorageSnapshots []*types.Snapshot
	for _, snapshot := range allSnapshots {
		libstorageSnapshots = append(libstorageSnapshots, translateSnapshot(&snapshot))
	}

	return libstorageSnapshots, nil
}
コード例 #5
0
ファイル: openstack.go プロジェクト: nutmegdevelopment/rexray
func (d *driver) getSnapshot(
	volumeID,
	snapshotID,
	snapshotName string) (allSnapshots []snapshots.Snapshot, err error) {

	fields := eff(map[string]interface{}{
		"volumeId":     volumeID,
		"snapshotId":   snapshotID,
		"snapshotName": snapshotName,
	})

	if snapshotID != "" {
		snapshot, err := snapshots.Get(d.clientBlockStorage, snapshotID).Extract()
		if err != nil {
			return []snapshots.Snapshot{},
				errors.WithFieldsE(fields, "error getting snapshot", err)
		}

		allSnapshots = append(allSnapshots, *snapshot)
	} else {
		opts := snapshots.ListOpts{
			VolumeID: volumeID,
			Name:     snapshotName,
		}

		allPages, err := snapshots.List(d.clientBlockStorage, opts).AllPages()
		if err != nil {
			return []snapshots.Snapshot{},
				errors.WithFieldsE(fields, "error listing snapshot", err)
		}

		allSnapshots, err = snapshots.ExtractSnapshots(allPages)
		if err != nil {
			return []snapshots.Snapshot{},
				errors.WithFieldsE(fields, "error extracting snapshot", err)
		}
	}

	return allSnapshots, nil
}
コード例 #6
0
ファイル: delegate.go プロジェクト: Clarifai/kubernetes
// List returns Snapshots.
func List(client *gophercloud.ServiceClient) pagination.Pager {
	return os.List(client, os.ListOpts{})
}