【转】gophercloud 不错的openstack golang sdk
原文: https://www.cnblogs.com/rongfengliang/p/14069237.html
---------------------------
gophercloud 是一个基于golang 包装的openstack api,功能比较强大,使用上也很不错,同时 也提供了比较完备的参考资料
一个参考使用demo
package main
import (
"log"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/pagination"
)
func main() {
// 1. ops
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: "https://openstack.example.com:5000/v2.0",
Username: "{username}",
Password: "{password}",
}
// 2. provider
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {
log.Fatal("some wrong", err.Error())
}
// 3. different ops (compute,block-storage,identity,networking,object-storage。。。。)
client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: "RegionOne",
})
// 4. servers ops
opts := servers.ListOpts{Name: "server_1"}
// Retrieve a pager (i.e. a paginated collection)
pager := servers.List(client, opts)
// page for fetch serverList
err = pager.EachPage(func(page pagination.Page) (bool, error) {
serverList, err := servers.ExtractServers(page)
if err != nil {
log.Println("some wrong:", err.Error())
return false, err
}
for _, s := range serverList {
log.Println(s)
}
return true, nil
})
}
文档dockerfile
为了方便学习以及使用,使用wget 镜像了gophercloud 的文档,同时制作了一个dockerfile
镜像网站命令
wget -mkEpnp http://gophercloud.io/
dockerimage dalongrong/gophercloud-docs
说明
因为以前是rackspace 已经迁移到了gophercloud,所以目前文档可能不是很全,最好参考godoc 学习使用
参考资料
https://github.com/gophercloud/gophercloud
http://gophercloud.io/docs/
https://developer.rackspace.com/docs/cloud-servers/quickstart/?lang=go
https://github.com/rongfengliang/gophercloud-docs-docker-image
https://pkg.go.dev/github.com/gophercloud/gophercloud