本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes.ExtractVolumes函数的典型用法代码示例。如果您正苦于以下问题:Golang ExtractVolumes函数的具体用法?Golang ExtractVolumes怎么用?Golang ExtractVolumes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExtractVolumes函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例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
注:本文中的github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes.ExtractVolumes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论