Update gophercloud vendor dependency to v0.1.0

This commit is contained in:
liushi
2019-07-01 02:22:54 -07:00
parent a33840e023
commit 094fed6598
43 changed files with 405 additions and 99 deletions

View File

@@ -13,15 +13,19 @@ AuthOptionsFromEnv fills out an identity.AuthOptions structure with the
settings found on the various OpenStack OS_* environment variables.
The following variables provide sources of truth: OS_AUTH_URL, OS_USERNAME,
OS_PASSWORD, OS_TENANT_ID, and OS_TENANT_NAME.
OS_PASSWORD and OS_PROJECT_ID.
Of these, OS_USERNAME, OS_PASSWORD, and OS_AUTH_URL must have settings,
or an error will result. OS_TENANT_ID, OS_TENANT_NAME, OS_PROJECT_ID, and
OS_PROJECT_NAME are optional.
or an error will result. OS_PROJECT_ID, is optional.
OS_TENANT_ID and OS_TENANT_NAME are mutually exclusive to OS_PROJECT_ID and
OS_PROJECT_NAME. If OS_PROJECT_ID and OS_PROJECT_NAME are set, they will
still be referred as "tenant" in Gophercloud.
OS_TENANT_ID and OS_TENANT_NAME are deprecated forms of OS_PROJECT_ID and
OS_PROJECT_NAME and the latter are expected against a v3 auth api.
If OS_PROJECT_ID and OS_PROJECT_NAME are set, they will still be referred
as "tenant" in Gophercloud.
If OS_PROJECT_NAME is set, it requires OS_PROJECT_ID to be set as well to
handle projects not on the default domain.
To use this function, first set the OS_* environment variables (for example,
by sourcing an `openrc` file), then:
@@ -83,6 +87,13 @@ func AuthOptionsFromEnv() (gophercloud.AuthOptions, error) {
return nilOptions, err
}
if domainID == "" && domainName == "" && tenantID == "" && tenantName != "" {
err := gophercloud.ErrMissingEnvironmentVariable{
EnvironmentVariable: "OS_PROJECT_ID",
}
return nilOptions, err
}
if applicationCredentialID == "" && applicationCredentialName != "" && applicationCredentialSecret != "" {
if userID == "" && username == "" {
return nilOptions, gophercloud.ErrMissingAnyoneOfEnvironmentVariables{

View File

@@ -77,6 +77,8 @@ type Volume struct {
ConsistencyGroupID string `json:"consistencygroup_id"`
// Multiattach denotes if the volume is multi-attach capable.
Multiattach bool `json:"multiattach"`
// Image metadata entries, only included for volumes that were created from an image, or from a snapshot of a volume originally created from an image.
VolumeImageMetadata map[string]string `json:"volume_image_metadata"`
}
// UnmarshalJSON another unmarshalling function

View File

@@ -135,7 +135,7 @@ func v2auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
result := tokens2.Create(v2Client, v2Opts)
token, err := result.ExtractToken()
err = client.SetTokenAndAuthResult(result)
if err != nil {
return err
}
@@ -150,9 +150,9 @@ func v2auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
// with the token and reauth func zeroed out. combined with setting `AllowReauth` to `false`,
// this should retry authentication only once
tac := *client
tac.IsThrowaway = true
tac.SetThrowaway(true)
tac.ReauthFunc = nil
tac.TokenID = ""
tac.SetTokenAndAuthResult(nil)
tao := options
tao.AllowReauth = false
client.ReauthFunc = func() error {
@@ -160,11 +160,10 @@ func v2auth(client *gophercloud.ProviderClient, endpoint string, options gopherc
if err != nil {
return err
}
client.TokenID = tac.TokenID
client.CopyTokenFrom(&tac)
return nil
}
}
client.TokenID = token.ID
client.EndpointLocator = func(opts gophercloud.EndpointOpts) (string, error) {
return V2EndpointURL(catalog, opts)
}
@@ -190,7 +189,7 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, opts tokens3.Au
result := tokens3.Create(v3Client, opts)
token, err := result.ExtractToken()
err = client.SetTokenAndAuthResult(result)
if err != nil {
return err
}
@@ -200,16 +199,14 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, opts tokens3.Au
return err
}
client.TokenID = token.ID
if opts.CanReauth() {
// here we're creating a throw-away client (tac). it's a copy of the user's provider client, but
// with the token and reauth func zeroed out. combined with setting `AllowReauth` to `false`,
// this should retry authentication only once
tac := *client
tac.IsThrowaway = true
tac.SetThrowaway(true)
tac.ReauthFunc = nil
tac.TokenID = ""
tac.SetTokenAndAuthResult(nil)
var tao tokens3.AuthOptionsBuilder
switch ot := opts.(type) {
case *gophercloud.AuthOptions:
@@ -228,7 +225,7 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, opts tokens3.Au
if err != nil {
return err
}
client.TokenID = tac.TokenID
client.CopyTokenFrom(&tac)
return nil
}
}
@@ -307,6 +304,18 @@ func initClientOpts(client *gophercloud.ProviderClient, eo gophercloud.EndpointO
return sc, nil
}
// NewBareMetalV1 creates a ServiceClient that may be used with the v1
// bare metal package.
func NewBareMetalV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
return initClientOpts(client, eo, "baremetal")
}
// NewBareMetalIntrospectionV1 creates a ServiceClient that may be used with the v1
// bare metal introspection package.
func NewBareMetalIntrospectionV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
return initClientOpts(client, eo, "baremetal-inspector")
}
// NewObjectStorageV1 creates a ServiceClient that may be used with the v1
// object storage package.
func NewObjectStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {

View File

@@ -148,7 +148,7 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
return
}
// Get retrieves details of a single flavor. Use ExtractFlavor to convert its
// Get retrieves details of a single flavor. Use Extract to convert its
// result into a Flavor.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)

View File

@@ -5,6 +5,7 @@ go_library(
srcs = [
"doc.go",
"errors.go",
"microversions.go",
"requests.go",
"results.go",
"urls.go",

View File

@@ -0,0 +1,11 @@
package servers
// ExtractTags will extract the tags of a server.
// This requires the client to be set to microversion 2.26 or later.
func (r serverResult) ExtractTags() ([]string, error) {
var s struct {
Tags []string `json:"tags"`
}
err := r.ExtractInto(&s)
return s.Tags, err
}

View File

@@ -183,12 +183,22 @@ type CreateOpts struct {
// AccessIPv4 specifies an IPv4 address for the instance.
AccessIPv4 string `json:"accessIPv4,omitempty"`
// AccessIPv6 pecifies an IPv6 address for the instance.
// AccessIPv6 specifies an IPv6 address for the instance.
AccessIPv6 string `json:"accessIPv6,omitempty"`
// Min specifies Minimum number of servers to launch.
Min int `json:"min_count,omitempty"`
// Max specifies Maximum number of servers to launch.
Max int `json:"max_count,omitempty"`
// ServiceClient will allow calls to be made to retrieve an image or
// flavor ID by name.
ServiceClient *gophercloud.ServiceClient `json:"-"`
// Tags allows a server to be tagged with single-word metadata.
// Requires microversion 2.52 or later.
Tags []string `json:"tags,omitempty"`
}
// ToServerCreateMap assembles a request body based on the contents of a
@@ -272,6 +282,14 @@ func (opts CreateOpts) ToServerCreateMap() (map[string]interface{}, error) {
b["flavorRef"] = flavorID
}
if opts.Min != 0 {
b["min_count"] = opts.Min
}
if opts.Max != 0 {
b["max_count"] = opts.Max
}
return map[string]interface{}{"server": b}, nil
}

View File

@@ -135,6 +135,21 @@ func (r CreateResult) ExtractToken() (*Token, error) {
}, nil
}
// ExtractTokenID implements the gophercloud.AuthResult interface. The returned
// string is the same as the ID field of the Token struct returned from
// ExtractToken().
func (r CreateResult) ExtractTokenID() (string, error) {
var s struct {
Access struct {
Token struct {
ID string `json:"id"`
} `json:"token"`
} `json:"access"`
}
err := r.ExtractInto(&s)
return s.Access.Token.ID, err
}
// ExtractServiceCatalog returns the ServiceCatalog that was generated along
// with the user's Token.
func (r CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) {

View File

@@ -134,9 +134,9 @@ func Get(c *gophercloud.ServiceClient, token string) (r GetResult) {
OkCodes: []int{200, 203},
})
if resp != nil {
r.Err = err
r.Header = resp.Header
}
r.Err = err
return
}

View File

@@ -102,6 +102,13 @@ func (r commonResult) ExtractToken() (*Token, error) {
return &s, err
}
// ExtractTokenID implements the gophercloud.AuthResult interface. The returned
// string is the same as the ID field of the Token struct returned from
// ExtractToken().
func (r CreateResult) ExtractTokenID() (string, error) {
return r.Header.Get("X-Subject-Token"), r.Err
}
// ExtractServiceCatalog returns the ServiceCatalog that was generated along
// with the user's Token.
func (r commonResult) ExtractServiceCatalog() (*ServiceCatalog, error) {

View File

@@ -5,6 +5,12 @@ import (
"github.com/gophercloud/gophercloud/pagination"
)
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToFloatingIPListQuery() (string, error)
}
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the floating IP attributes you want to see returned. SortKey allows you to
@@ -31,16 +37,25 @@ type ListOpts struct {
NotTagsAny string `q:"not-tags-any"`
}
// ToNetworkListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToFloatingIPListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List returns a Pager which allows you to iterate over a collection of
// floating IP resources. It accepts a ListOpts struct, which allows you to
// filter and sort the returned collection for greater efficiency.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q, err := gophercloud.BuildQueryString(&opts)
if err != nil {
return pagination.Pager{Err: err}
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := rootURL(c)
if opts != nil {
query, err := opts.ToFloatingIPListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
u := rootURL(c) + q.String()
return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
return FloatingIPPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -124,6 +139,7 @@ type UpdateOptsBuilder interface {
type UpdateOpts struct {
Description *string `json:"description,omitempty"`
PortID *string `json:"port_id,omitempty"`
FixedIP string `json:"fixed_ip_address,omitempty"`
}
// ToFloatingIPUpdateMap allows UpdateOpts to satisfy the UpdateOptsBuilder

View File

@@ -56,11 +56,13 @@ type commonResult struct {
// Extract will extract a FloatingIP resource from a result.
func (r commonResult) Extract() (*FloatingIP, error) {
var s struct {
FloatingIP *FloatingIP `json:"floatingip"`
}
var s FloatingIP
err := r.ExtractInto(&s)
return s.FloatingIP, err
return &s, err
}
func (r commonResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "floatingip")
}
// CreateResult represents the result of a create operation. Call its Extract
@@ -123,3 +125,7 @@ func ExtractFloatingIPs(r pagination.Page) ([]FloatingIP, error) {
err := (r.(FloatingIPPage)).ExtractInto(&s)
return s.FloatingIPs, err
}
func ExtractFloatingIPsInto(r pagination.Page, v interface{}) error {
return r.(FloatingIPPage).Result.ExtractIntoSlicePtr(v, "floatingips")
}

View File

@@ -8,7 +8,7 @@ import (
// GatewayInfo represents the information of an external gateway for any
// particular network router.
type GatewayInfo struct {
NetworkID string `json:"network_id"`
NetworkID string `json:"network_id,omitempty"`
EnableSNAT *bool `json:"enable_snat,omitempty"`
ExternalFixedIPs []ExternalFixedIP `json:"external_fixed_ips,omitempty"`
}

View File

@@ -45,8 +45,9 @@ Example to Update a Network
networkID := "484cda0e-106f-4f4b-bb3f-d413710bbe78"
name := "new_name"
updateOpts := networks.UpdateOpts{
Name: "new_name",
Name: &name,
}
network, err := networks.Update(networkClient, networkID, updateOpts).Extract()

View File

@@ -112,7 +112,7 @@ type UpdateOptsBuilder interface {
// UpdateOpts represents options used to update a network.
type UpdateOpts struct {
AdminStateUp *bool `json:"admin_state_up,omitempty"`
Name string `json:"name,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Shared *bool `json:"shared,omitempty"`
}