update gophercloud/gophercloud dependency

Why:
* fixes #44461
This commit is contained in:
stuart.warren
2017-05-09 15:29:58 +01:00
parent d602ea69dc
commit adaade6a22
19 changed files with 185 additions and 126 deletions

View File

@@ -1,8 +1,8 @@
package apiversions
import (
"strings"
"net/url"
"strings"
"github.com/gophercloud/gophercloud"
)

View File

@@ -310,6 +310,19 @@ func NewDBV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*
return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil
}
// NewDNSV2 creates a ServiceClient that may be used to access the v2 DNS service.
func NewDNSV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
eo.ApplyDefaults("dns")
url, err := client.EndpointLocator(eo)
if err != nil {
return nil, err
}
return &gophercloud.ServiceClient{
ProviderClient: client,
Endpoint: url,
ResourceBase: url + "v2/"}, nil
}
// NewImageServiceV2 creates a ServiceClient that may be used to access the v2 image service.
func NewImageServiceV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
eo.ApplyDefaults("image")

View File

@@ -54,6 +54,47 @@ func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) paginat
})
}
type CreateOptsBuilder interface {
ToFlavorCreateMap() (map[string]interface{}, error)
}
// CreateOpts is passed to Create to create a flavor
// Source:
// https://github.com/openstack/nova/blob/stable/newton/nova/api/openstack/compute/schemas/flavor_manage.py#L20
type CreateOpts struct {
Name string `json:"name" required:"true"`
// memory size, in MBs
RAM int `json:"ram" required:"true"`
VCPUs int `json:"vcpus" required:"true"`
// disk size, in GBs
Disk *int `json:"disk" required:"true"`
ID string `json:"id,omitempty"`
// non-zero, positive
Swap *int `json:"swap,omitempty"`
RxTxFactor float64 `json:"rxtx_factor,omitempty"`
IsPublic *bool `json:"os-flavor-access:is_public,omitempty"`
// ephemeral disk size, in GBs, non-zero, positive
Ephemeral *int `json:"OS-FLV-EXT-DATA:ephemeral,omitempty"`
}
// ToFlavorCreateMap satisfies the CreateOptsBuilder interface
func (opts *CreateOpts) ToFlavorCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "flavor")
}
// Create a flavor
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToFlavorCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 201},
})
return
}
// Get instructs OpenStack to provide details on a single flavor, identified by its ID.
// Use ExtractFlavor to convert its result into a Flavor.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {

View File

@@ -8,13 +8,21 @@ import (
"github.com/gophercloud/gophercloud/pagination"
)
// GetResult temporarily holds the response from a Get call.
type GetResult struct {
type commonResult struct {
gophercloud.Result
}
// Extract provides access to the individual Flavor returned by the Get function.
func (r GetResult) Extract() (*Flavor, error) {
type CreateResult struct {
commonResult
}
// GetResult temporarily holds the response from a Get call.
type GetResult struct {
commonResult
}
// Extract provides access to the individual Flavor returned by the Get and Create functions.
func (r commonResult) Extract() (*Flavor, error) {
var s struct {
Flavor *Flavor `json:"flavor"`
}
@@ -40,41 +48,32 @@ type Flavor struct {
VCPUs int `json:"vcpus"`
}
func (f *Flavor) UnmarshalJSON(b []byte) error {
var flavor struct {
ID string `json:"id"`
Disk int `json:"disk"`
RAM int `json:"ram"`
Name string `json:"name"`
RxTxFactor float64 `json:"rxtx_factor"`
Swap interface{} `json:"swap"`
VCPUs int `json:"vcpus"`
func (r *Flavor) UnmarshalJSON(b []byte) error {
type tmp Flavor
var s struct {
tmp
Swap interface{} `json:"swap"`
}
err := json.Unmarshal(b, &flavor)
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
f.ID = flavor.ID
f.Disk = flavor.Disk
f.RAM = flavor.RAM
f.Name = flavor.Name
f.RxTxFactor = flavor.RxTxFactor
f.VCPUs = flavor.VCPUs
*r = Flavor(s.tmp)
switch t := flavor.Swap.(type) {
switch t := s.Swap.(type) {
case float64:
f.Swap = int(t)
r.Swap = int(t)
case string:
switch t {
case "":
f.Swap = 0
r.Swap = 0
default:
swap, err := strconv.ParseFloat(t, 64)
if err != nil {
return err
}
f.Swap = int(swap)
r.Swap = int(swap)
}
}

View File

@@ -11,3 +11,7 @@ func getURL(client *gophercloud.ServiceClient, id string) string {
func listURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("flavors", "detail")
}
func createURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("flavors")
}

View File

@@ -45,8 +45,8 @@ type Image struct {
Status string
Updated string
Metadata map[string]string
Metadata map[string]interface{}
}
// ImagePage contains a single page of results from a List operation.

View File

@@ -401,11 +401,10 @@ type RebuildOptsBuilder interface {
// operation
type RebuildOpts struct {
// The server's admin password
AdminPass string `json:"adminPass" required:"true"`
AdminPass string `json:"adminPass,omitempty"`
// The ID of the image you want your server to be provisioned on
ImageID string `json:"imageRef"`
ImageName string `json:"-"`
//ImageName string `json:"-"`
// Name to set the server to
Name string `json:"name,omitempty"`
// AccessIPv4 [optional] provides a new IPv4 address for the instance.

View File

@@ -19,11 +19,17 @@ type serverResult struct {
// Extract interprets any serverResult as a Server, if possible.
func (r serverResult) Extract() (*Server, error) {
var s struct {
Server *Server `json:"server"`
}
var s Server
err := r.ExtractInto(&s)
return s.Server, err
return &s, err
}
func (r serverResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "server")
}
func ExtractServersInto(r pagination.Page, v interface{}) error {
return r.(ServerPage).Result.ExtractIntoSlicePtr(v, "servers")
}
// CreateResult temporarily contains the response from a Create call.
@@ -221,11 +227,9 @@ func (r ServerPage) NextPageURL() (string, error) {
// ExtractServers interprets the results of a single page from a List() call, producing a slice of Server entities.
func ExtractServers(r pagination.Page) ([]Server, error) {
var s struct {
Servers []Server `json:"servers"`
}
err := (r.(ServerPage)).ExtractInto(&s)
return s.Servers, err
var s []Server
err := ExtractServersInto(r, &s)
return s, err
}
// MetadataResult contains the result of a call for (potentially) multiple key-value pairs.

View File

@@ -21,6 +21,7 @@ type ListOpts struct {
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
RouterID string `q:"router_id"`
}
// List returns a Pager which allows you to iterate over a collection of

View File

@@ -34,6 +34,9 @@ type FloatingIP struct {
// The condition of the API resource.
Status string `json:"status"`
//The ID of the router used for this Floating-IP
RouterID string `json:"router_id"`
}
type commonResult struct {

View File

@@ -47,13 +47,31 @@ type RuleEtherType string
// Constants useful for CreateOpts
const (
DirIngress RuleDirection = "ingress"
DirEgress RuleDirection = "egress"
ProtocolTCP RuleProtocol = "tcp"
ProtocolUDP RuleProtocol = "udp"
ProtocolICMP RuleProtocol = "icmp"
EtherType4 RuleEtherType = "IPv4"
EtherType6 RuleEtherType = "IPv6"
DirIngress RuleDirection = "ingress"
DirEgress RuleDirection = "egress"
EtherType4 RuleEtherType = "IPv4"
EtherType6 RuleEtherType = "IPv6"
ProtocolAH RuleProtocol = "ah"
ProtocolDCCP RuleProtocol = "dccp"
ProtocolEGP RuleProtocol = "egp"
ProtocolESP RuleProtocol = "esp"
ProtocolGRE RuleProtocol = "gre"
ProtocolICMP RuleProtocol = "icmp"
ProtocolIGMP RuleProtocol = "igmp"
ProtocolIPv6Encap RuleProtocol = "ipv6-encap"
ProtocolIPv6Frag RuleProtocol = "ipv6-frag"
ProtocolIPv6ICMP RuleProtocol = "ipv6-icmp"
ProtocolIPv6NoNxt RuleProtocol = "ipv6-nonxt"
ProtocolIPv6Opts RuleProtocol = "ipv6-opts"
ProtocolIPv6Route RuleProtocol = "ipv6-route"
ProtocolOSPF RuleProtocol = "ospf"
ProtocolPGM RuleProtocol = "pgm"
ProtocolRSVP RuleProtocol = "rsvp"
ProtocolSCTP RuleProtocol = "sctp"
ProtocolTCP RuleProtocol = "tcp"
ProtocolUDP RuleProtocol = "udp"
ProtocolUDPLite RuleProtocol = "udplite"
ProtocolVRRP RuleProtocol = "vrrp"
)
// CreateOptsBuilder is what types must satisfy to be used as Create