當前位置: 首頁>>代碼示例>>Golang>>正文


Golang volumes.List函數代碼示例

本文整理匯總了Golang中github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes.List函數的典型用法代碼示例。如果您正苦於以下問題:Golang List函數的具體用法?Golang List怎麽用?Golang List使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了List函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getVolume

// Takes a partial/full disk id or diskname
func (os *OpenStack) getVolume(diskName string) (volumes.Volume, error) {
	sClient, err := openstack.NewBlockStorageV1(os.provider, gophercloud.EndpointOpts{
		Region: os.region,
	})

	var volume volumes.Volume
	if err != nil || sClient == nil {
		glog.Errorf("Unable to initialize cinder client for region: %s", os.region)
		return volume, err
	}

	err = volumes.List(sClient, nil).EachPage(func(page pagination.Page) (bool, error) {
		vols, err := volumes.ExtractVolumes(page)
		if err != nil {
			glog.Errorf("Failed to extract volumes: %v", err)
			return false, err
		} else {
			for _, v := range vols {
				glog.V(4).Infof("%s %s %v", v.ID, v.Name, v.Attachments)
				if v.Name == diskName || strings.Contains(v.ID, diskName) {
					volume = v
					return true, nil
				}
			}
		}
		// if it reached here then no disk with the given name was found.
		errmsg := fmt.Sprintf("Unable to find disk: %s in region %s", diskName, os.region)
		return false, errors.New(errmsg)
	})
	if err != nil {
		glog.Errorf("Error occured getting volume: %s", diskName)
		return volume, err
	}
	return volume, err
}
開發者ID:RyanBinfeng,項目名稱:kubernetes,代碼行數:36,代碼來源:openstack.go

示例2: GetVolumes

// GetVolumes collects volumes data by sending REST call to cinderhost:8776/v1/tenant_id/volumes
func (s ServiceV1) GetVolumes(provider *gophercloud.ProviderClient) (map[string]types.Volumes, error) {
	vols := map[string]types.Volumes{}

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

	//opts := volumes.ListOpts{AllTenants: true}
	opts := volumes.ListOpts{}

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

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

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

	}

	return vols, nil
}
開發者ID:intelsdi-x,項目名稱:snap-plugin-collector-cinder,代碼行數:33,代碼來源:cinder.go

示例3: Execute

func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	pager := osVolumes.List(command.Ctx.ServiceClient, opts)
	var volumes []map[string]interface{}
	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		info, err := osVolumes.ExtractVolumes(page)
		if err != nil {
			return false, err
		}
		result := make([]map[string]interface{}, len(info))
		for j, volume := range info {
			result[j] = volumeSingle(&volume)
		}
		volumes = append(volumes, result...)
		return true, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
	if len(volumes) == 0 {
		resource.Result = nil
	} else {
		resource.Result = volumes
	}
}
開發者ID:flazz,項目名稱:rack,代碼行數:26,代碼來源:list.go

示例4: getVolume

func (d *driver) getVolume(
	volumeID, volumeName string) (volumesRet []volumes.Volume, err error) {

	if volumeID != "" {
		volume, err := volumes.Get(d.clientBlockStorage, volumeID).Extract()
		if err != nil {
			return []volumes.Volume{},
				errors.WithFieldsE(eff(errors.Fields{
					"volumeId":   volumeID,
					"volumeName": volumeName}),
					"error getting volumes", err)
		}
		volumesRet = append(volumesRet, *volume)
	} else {
		listOpts := &volumes.ListOpts{
		//Name:       volumeName,
		}

		allPages, err := volumes.List(d.clientBlockStorage, listOpts).AllPages()
		if err != nil {
			return []volumes.Volume{},
				errors.WithFieldsE(eff(errors.Fields{
					"volumeId":   volumeID,
					"volumeName": volumeName}),
					"error listing volumes", err)
		}
		volumesRet, err = volumes.ExtractVolumes(allPages)
		if err != nil {
			return []volumes.Volume{},
				errors.WithFieldsE(eff(errors.Fields{
					"volumeId":   volumeID,
					"volumeName": volumeName}),
					"error extracting volumes", err)
		}

		var volumesRetFiltered []volumes.Volume
		if volumeName != "" {
			var found bool
			for _, volume := range volumesRet {
				if volume.Name == volumeName {
					volumesRetFiltered = append(volumesRetFiltered, volume)
					found = true
					break
				}
			}
			if !found {
				return []volumes.Volume{}, nil
			}
			volumesRet = volumesRetFiltered
		}
	}

	return volumesRet, nil
}
開發者ID:nutmegdevelopment,項目名稱:rexray,代碼行數:54,代碼來源:openstack.go

示例5: getVolume

func (d *driver) getVolume(
	ctx types.Context,
	volumeID, volumeName string,
	attachments types.VolumeAttachmentsTypes) ([]*types.Volume, error) {

	var volumesRet []volumes.Volume
	fields := eff(goof.Fields{
		"moduleName": ctx,
		"volumeId":   volumeID,
		"volumeName": volumeName})

	if volumeID != "" {
		volume, err := volumes.Get(d.clientBlockStorage, volumeID).Extract()
		if err != nil {
			return nil,
				goof.WithFieldsE(fields, "error getting volumes", err)
		}
		volumesRet = append(volumesRet, *volume)
	} else {
		listOpts := &volumes.ListOpts{
		//Name:       volumeName,
		}

		allPages, err := volumes.List(d.clientBlockStorage, listOpts).AllPages()
		if err != nil {
			return nil,
				goof.WithFieldsE(fields, "error listing volumes", err)
		}
		volumesRet, err = volumes.ExtractVolumes(allPages)
		if err != nil {
			return nil,
				goof.WithFieldsE(fields, "error extracting volumes", err)
		}

		var volumesRetFiltered []volumes.Volume
		if volumeName != "" {
			for _, volumer := range volumesRet { //volumer avoids any namespace confict
				if volumer.Name == volumeName {
					volumesRetFiltered = append(volumesRetFiltered, volumer)
					break
				}
			}
			volumesRet = volumesRetFiltered
		}
	}
	//now cast from []volumes.Volume to []types.Volume
	var volumesSD []*types.Volume
	for _, volume := range volumesRet {
		volumesSD = append(volumesSD, translateVolume(&volume, attachments))
	}
	return volumesSD, nil
}
開發者ID:emccode,項目名稱:libstorage,代碼行數:52,代碼來源:rackspace_storage.go

示例6: getVolume

func (driver *Driver) getVolume(volumeID, volumeName string) (volumesRet []volumes.Volume, err error) {
	if volumeID != "" {
		volume, err := volumes.Get(driver.ClientBlockStorage, volumeID).Extract()
		if err != nil {
			return []volumes.Volume{}, err
		}
		volumesRet = append(volumesRet, *volume)
	} else {
		listOpts := &volumes.ListOpts{
		//Name:       volumeName,
		}

		allPages, err := volumes.List(driver.ClientBlockStorage, listOpts).AllPages()
		if err != nil {
			return []volumes.Volume{}, err
		}
		volumesRet, err = volumes.ExtractVolumes(allPages)
		if err != nil {
			return []volumes.Volume{}, err
		}

		var volumesRetFiltered []volumes.Volume
		if volumeName != "" {
			var found bool
			for _, volume := range volumesRet {
				if volume.Name == volumeName {
					volumesRetFiltered = append(volumesRetFiltered, volume)
					found = true
					break
				}
			}
			if !found {
				return []volumes.Volume{}, nil
			}
		}
		volumesRet = volumesRetFiltered
	}

	return volumesRet, nil
}
開發者ID:bkeyoumarsi,項目名稱:rexray,代碼行數:40,代碼來源:storage.go

示例7: TestVolumes

func TestVolumes(t *testing.T) {
	client, err := newClient(t)
	th.AssertNoErr(t, err)

	cv, err := volumes.Create(client, &volumes.CreateOpts{
		Size: 1,
		Name: "gophercloud-test-volume",
	}).Extract()
	th.AssertNoErr(t, err)
	defer func() {
		err = volumes.WaitForStatus(client, cv.ID, "available", 60)
		th.AssertNoErr(t, err)
		err = volumes.Delete(client, cv.ID).ExtractErr()
		th.AssertNoErr(t, err)
	}()

	_, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{
		Name: "gophercloud-updated-volume",
	}).Extract()
	th.AssertNoErr(t, err)

	v, err := volumes.Get(client, cv.ID).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Got volume: %+v\n", v)

	if v.Name != "gophercloud-updated-volume" {
		t.Errorf("Unable to update volume: Expected name: gophercloud-updated-volume\nActual name: %s", v.Name)
	}

	err = volumes.List(client, &volumes.ListOpts{Name: "gophercloud-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) {
		vols, err := volumes.ExtractVolumes(page)
		th.CheckEquals(t, 1, len(vols))
		return true, err
	})
	th.AssertNoErr(t, err)
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:36,代碼來源:volumes_test.go

示例8: List

// List returns volumes optionally limited by the conditions provided in ListOpts.
func List(client *gophercloud.ServiceClient) pagination.Pager {
	return os.List(client, os.ListOpts{})
}
開發者ID:COLDTURNIP,項目名稱:kubernetes,代碼行數:4,代碼來源:delegate.go


注:本文中的github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes.List函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。