Last active
October 16, 2015 02:54
-
-
Save feiskyer/d6ebd844ee5187bd53ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/rackspace/gophercloud" | |
| "github.com/rackspace/gophercloud/openstack" | |
| "github.com/rackspace/gophercloud/openstack/identity/v2/tenants" | |
| "github.com/rackspace/gophercloud/pagination" | |
| "os" | |
| ) | |
| func main() { | |
| auth_opts := gophercloud.AuthOptions{ | |
| IdentityEndpoint: "http://127.0.0.1:5000/v2.0", | |
| Username: "demo", | |
| Password: "demo", | |
| AllowReauth: true, | |
| } | |
| provider, err := openstack.AuthenticatedClient(auth_opts) | |
| if err != nil { | |
| fmt.Println("Authentication error: ", err) | |
| os.Exit(1) | |
| } | |
| identity := openstack.NewIdentityV2(provider) | |
| opts := tenants.ListOpts{Limit: 5} | |
| pager := tenants.List(identity, &opts) | |
| err = pager.EachPage(func(page pagination.Page) (bool, error) { | |
| tenantList, err := tenants.ExtractTenants(page) | |
| if err != nil { | |
| return false, nil | |
| } | |
| for _, t := range tenantList { | |
| fmt.Println(t) | |
| } | |
| return true, nil | |
| }) | |
| if err != nil { | |
| fmt.Println("Tenat list error: ", err) | |
| os.Exit(1) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment