1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
results.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
package diskconfig
import (
"github.com/mitchellh/mapstructure"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
"github.com/rackspace/gophercloud/pagination"
)
func commonExtract(result gophercloud.Result) (*DiskConfig, error) {
var resp struct {
Server struct {
DiskConfig string `mapstructure:"OS-DCF:diskConfig"`
} `mapstructure:"server"`
}
err := mapstructure.Decode(result.Body, &resp)
if err != nil {
return nil, err
}
config := DiskConfig(resp.Server.DiskConfig)
return &config, nil
}
// ExtractGet returns the disk configuration from a servers.Get call.
func ExtractGet(result servers.GetResult) (*DiskConfig, error) {
return commonExtract(result.Result)
}
// ExtractUpdate returns the disk configuration from a servers.Update call.
func ExtractUpdate(result servers.UpdateResult) (*DiskConfig, error) {
return commonExtract(result.Result)
}
// ExtractRebuild returns the disk configuration from a servers.Rebuild call.
func ExtractRebuild(result servers.RebuildResult) (*DiskConfig, error) {
return commonExtract(result.Result)
}
// ExtractDiskConfig returns the DiskConfig setting for a specific server acquired from an
// servers.ExtractServers call, while iterating through a Pager.
func ExtractDiskConfig(page pagination.Page, index int) (*DiskConfig, error) {
casted := page.(servers.ServerPage).Body
type server struct {
DiskConfig string `mapstructure:"OS-DCF:diskConfig"`
}
var response struct {
Servers []server `mapstructure:"servers"`
}
err := mapstructure.Decode(casted, &response)
if err != nil {
return nil, err
}
config := DiskConfig(response.Servers[index].DiskConfig)
return &config, nil
}
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.21.0

搜索帮助