Last active
May 11, 2018 03:02
-
-
Save j-griffith/0dee9a3c871a3e6988d11be530bbd9bb to your computer and use it in GitHub Desktop.
Example extensible gophercloud for microversions
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/gophercloud/gophercloud" | |
| "github.com/gophercloud/gophercloud/openstack" | |
| "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" | |
| ) | |
| type myCreateOpts struct { | |
| volumes.CreateOpts | |
| GroupID string `json:"group_id,omitempty"` | |
| } | |
| func main() { | |
| // Boilerplate to set up a provider | |
| opts := gophercloud.AuthOptions{ | |
| IdentityEndpoint: "http://10.117.36.5:5000/v3", | |
| Username: "jdg", | |
| Password: "r7gh8ae", | |
| TenantID: "394337ba489a40678dc6ebf4d4c4af78", | |
| DomainName: "default", | |
| } | |
| provider, err := openstack.AuthenticatedClient(opts) | |
| if err != nil { | |
| fmt.Printf("Error is: %+v", err) | |
| } | |
| eopts := gophercloud.EndpointOpts{ | |
| Region: "RegionOne", | |
| } | |
| // Ok, now that that's done, try something interesting... | |
| createMV := "3.13" | |
| cOpts := myCreateOpts{} | |
| cOpts.Size = 1 | |
| client, _ := openstack.NewBlockStorageV3(provider, eopts) | |
| client.Microversion = createMV | |
| r := gophercloud.Result{} | |
| b, err := gophercloud.BuildRequestBody(cOpts, "volume") | |
| if err != nil { | |
| fmt.Printf("Error building request: %v", err) | |
| fmt.Printf("DOH!!") | |
| } | |
| _, r.Err = client.Post(client.ServiceURL("volumes"), b, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{202}}) | |
| if r.Err != nil { | |
| fmt.Printf("Ouch! So close!: %v", r.Err) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment