// GetSnapshots collects snapshot data by sending REST call to cinderhost:8776/v2/tenant_id/snapshots/detail?all_tenants=true
func (s ServiceV2) GetSnapshots(provider *gophercloud.ProviderClient) (map[string]types.Snapshots, error) {
	snaps := map[string]types.Snapshots{}

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

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

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

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

	return snaps, nil
}
// GetVolumes collects volumes data by sending REST call to cinderhost:8776/v2/tenant_id/volumes/detail?all_tenants=true
func (s ServiceV2) GetVolumes(provider *gophercloud.ProviderClient) (map[string]types.Volumes, error) {
	vols := map[string]types.Volumes{}

	client, err := openstackintel.NewBlockStorageV2(provider, gophercloud.EndpointOpts{})
	if err != nil {
		return nil, err
	}

	opts := volumesintel.ListOpts{AllTenants: true}

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

	volumes, err := volumesintel.ExtractVolumes(page)
	if err != nil {
		return nil, err
	}

	for _, volume := range volumes {
		volCounts := vols[volume.OsVolTenantAttrTenantID]
		volCounts.Count += 1
		volCounts.Bytes += volume.Size * 1024 * 1024 * 1024
		vols[volume.OsVolTenantAttrTenantID] = volCounts
	}

	return vols, nil
}
// GetApiVersions is used to retrieve list of available Cinder API versions
// List of api version is then used to dispatch calls to proper API version based on defined priority
func (c Common) GetApiVersions(provider *gophercloud.ProviderClient) ([]string, error) {
	apis := []string{}

	client, err := openstackintel.NewBlockStorageV2(provider, gophercloud.EndpointOpts{})

	if err != nil {
		return apis, err
	}

	pager := apiversionsintel.List(client)
	page, err := pager.AllPages()
	if err != nil {
		fmt.Println("err ", err)
		return apis, err
	}

	apiVersions, err := apiversions.ExtractAPIVersions(page)
	if err != nil {
		return apis, err
	}

	for _, apiVersion := range apiVersions {
		apis = append(apis, apiVersion.ID)
	}

	return apis, nil
}
// GetLimits collects tenant limits by sending REST call to cinderhost:8776/v2/tenant_id/limits
func (s ServiceV2) GetLimits(provider *gophercloud.ProviderClient) (types.Limits, error) {
	limits := types.Limits{}

	client, err := openstackintel.NewBlockStorageV2(provider, gophercloud.EndpointOpts{})
	if err != nil {
		return limits, err
	}

	tenantLimits, err := limitsintel.Get(client, "limits").Extract()
	if err != nil {
		return limits, err
	}

	limits.MaxTotalVolumes = tenantLimits.MaxTotalVolumes
	limits.MaxTotalVolumeGigabytes = tenantLimits.MaxTotalVolumeGigabytes

	return limits, nil
}