-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from xieyunyue/v1.5.0-es
Add CRUD operation for flavor, flavor profile, az, az profile of octavia
- Loading branch information
Showing
12 changed files
with
1,062 additions
and
0 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
openstack/loadbalancer/v2/availability_zone_profile/requests.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package availability_zone_profile | ||
|
||
import ( | ||
"github.com/gophercloud/gophercloud" | ||
"github.com/gophercloud/gophercloud/pagination" | ||
) | ||
|
||
// ListOptsBuilder allows extensions to add additional parameters to the | ||
// List request. | ||
type ListOptsBuilder interface { | ||
ToAvailabilityZoneProfileListQuery() (string, error) | ||
} | ||
|
||
// ListOpts allows the filtering and sorting of paginated collections through | ||
// the API. | ||
type ListOpts struct { | ||
ID string `q:"id"` | ||
Name string `q:"name"` | ||
ProviderName string `q:"provider_name"` | ||
AvailabilityZoneData string `q:"availability_zone_data"` | ||
Limit int `q:"limit"` | ||
Marker string `q:"marker"` | ||
SortKey string `q:"sort_key"` | ||
SortDir string `q:"sort_dir"` | ||
} | ||
|
||
// ToAvailabilityZoneProfileListQuery formats a ListOpts into a query string. | ||
func (opts ListOpts) ToAvailabilityZoneProfileListQuery() (string, error) { | ||
q, err := gophercloud.BuildQueryString(opts) | ||
return q.String(), err | ||
} | ||
|
||
// List returns a Pager which allows you to iterate over a collection of | ||
// availability zone profile. It accepts a ListOpts struct, which allows you to filter | ||
// and sort the returned collection for greater efficiency. | ||
// | ||
// Default policy settings return only those availability zone profiles that are owned by | ||
// the project who submits the request, unless an admin user submits the request. | ||
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { | ||
url := rootURL(c) | ||
if opts != nil { | ||
query, err := opts.ToAvailabilityZoneProfileListQuery() | ||
if err != nil { | ||
return pagination.Pager{Err: err} | ||
} | ||
url += query | ||
} | ||
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { | ||
return AvailabilityZoneProfilePage{pagination.LinkedPageBase{PageResult: r}} | ||
}) | ||
} | ||
|
||
// CreateOptsBuilder allows extensions to add additional parameters to the | ||
// Create request. | ||
type CreateOptsBuilder interface { | ||
ToAvailabilityZoneProfileCreateMap() (map[string]interface{}, error) | ||
} | ||
|
||
// CreateOpts is the common options struct used in this package's Create | ||
// operation. | ||
type CreateOpts struct { | ||
// Human-readable name for the AvailabilityZoneProfile. Does not have to be unique. | ||
Name string `json:"name"` | ||
|
||
// The name of the provider. | ||
ProviderName string `json:"provider_name"` | ||
|
||
// The JSON string containing the availability zone metadata. | ||
AvailabilityZoneData string `json:"availability_zone_data"` | ||
} | ||
|
||
// ToAvailabilityZoneProfileCreateMap builds a request body from CreateOpts. | ||
func (opts CreateOpts) ToAvailabilityZoneProfileCreateMap() (map[string]interface{}, error) { | ||
return gophercloud.BuildRequestBody(opts, "availability_zone_profile") | ||
} | ||
|
||
// Create is an operation which provisions a new availability zone profiles based on the | ||
// configuration defined in the CreateOpts struct. Once the request is | ||
// validated and progress has started on the provisioning process, a | ||
// CreateResult will be returned. | ||
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { | ||
b, err := opts.ToAvailabilityZoneProfileCreateMap() | ||
if err != nil { | ||
r.Err = err | ||
return | ||
} | ||
resp, err := c.Post(rootURL(c), b, &r.Body, nil) | ||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err) | ||
return | ||
} | ||
|
||
// Get retrieves a particular AvailabilityZoneProfile based on its unique ID. | ||
func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { | ||
resp, err := c.Get(resourceURL(c, id), &r.Body, nil) | ||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err) | ||
return | ||
} | ||
|
||
// UpdateOptsBuilder allows extensions to add additional parameters to the | ||
// Update request. | ||
type UpdateOptsBuilder interface { | ||
ToAvailabilityZoneProfileUpdateMap() (map[string]interface{}, error) | ||
} | ||
|
||
// UpdateOpts is the common options struct used in this package's Update | ||
// operation. | ||
type UpdateOpts struct { | ||
// Human-readable name for the AvailabilityZoneProfile. Does not have to be unique. | ||
Name string `json:"name"` | ||
|
||
// The name of the provider. | ||
ProviderName string `json:"provider_name"` | ||
|
||
// The JSON string containing the availability zone metadata. | ||
AvailabilityZoneData string `json:"availability_zone_data"` | ||
} | ||
|
||
// ToAvailabilityZoneProfileUpdateMap builds a request body from UpdateOpts. | ||
func (opts UpdateOpts) ToAvailabilityZoneProfileUpdateMap() (map[string]interface{}, error) { | ||
return gophercloud.BuildRequestBody(opts, "availability_zone_profile") | ||
} | ||
|
||
// Update is an operation which modifies the attributes of the specified | ||
// AvailabilityZoneProfile. | ||
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { | ||
b, err := opts.ToAvailabilityZoneProfileUpdateMap() | ||
if err != nil { | ||
r.Err = err | ||
return | ||
} | ||
resp, err := c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ | ||
OkCodes: []int{200, 202}, | ||
}) | ||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err) | ||
return | ||
} | ||
|
||
// Delete will permanently delete a particular AvailabilityZoneProfile based on its | ||
// unique ID. | ||
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { | ||
url := resourceURL(c, id) | ||
resp, err := c.Delete(url, nil) | ||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err) | ||
return | ||
} |
101 changes: 101 additions & 0 deletions
101
openstack/loadbalancer/v2/availability_zone_profile/results.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package availability_zone_profile | ||
|
||
import ( | ||
"github.com/gophercloud/gophercloud" | ||
"github.com/gophercloud/gophercloud/pagination" | ||
) | ||
|
||
// AvailabilityZoneProfile is the primary octavia az configuration object that | ||
// specifies the compute az and cpu arch, etc. | ||
type AvailabilityZoneProfile struct { | ||
|
||
// The unique ID for the AvailabilityZoneProfile. | ||
ID string `json:"id"` | ||
|
||
// Human-readable name for the AvailabilityZoneProfile. Does not have to be unique. | ||
Name string `json:"name"` | ||
|
||
// The name of the provider. | ||
ProviderName string `json:"provider_name"` | ||
|
||
// The JSON string containing the availability zone metadata. | ||
AvailabilityZoneData string `json:"availability_zone_data"` | ||
} | ||
|
||
// AvailabilityZoneProfilePage is the page returned by a pager when traversing over a | ||
// collection of availability zone profiles. | ||
type AvailabilityZoneProfilePage struct { | ||
pagination.LinkedPageBase | ||
} | ||
|
||
// NextPageURL is invoked when a paginated collection of availability zone profiles has | ||
// reached the end of a page and the pager seeks to traverse over a new one. | ||
// In order to do this, it needs to construct the next page's URL. | ||
func (r AvailabilityZoneProfilePage) NextPageURL() (string, error) { | ||
var s struct { | ||
Links []gophercloud.Link `json:"availabilityzone_profile_links"` | ||
} | ||
err := r.ExtractInto(&s) | ||
if err != nil { | ||
return "", err | ||
} | ||
return gophercloud.ExtractNextURL(s.Links) | ||
} | ||
|
||
// IsEmpty checks whether a AvailabilityZoneProfilePage struct is empty. | ||
func (r AvailabilityZoneProfilePage) IsEmpty() (bool, error) { | ||
if r.StatusCode == 204 { | ||
return true, nil | ||
} | ||
|
||
is, err := ExtractAvailabilityZoneProfiles(r) | ||
return len(is) == 0, err | ||
} | ||
|
||
// ExtractAvailabilityZoneProfiles accepts a Page struct, specifically a AvailabilityZoneProfilePage | ||
// struct, and extracts the elements into a slice of AvailabilityZoneProfiles structs. In | ||
// other words, a generic collection is mapped into a relevant slice. | ||
func ExtractAvailabilityZoneProfiles(r pagination.Page) ([]AvailabilityZoneProfile, error) { | ||
var s struct { | ||
AvailabilityZoneProfiles []AvailabilityZoneProfile `json:"AvailabilityZoneProfiles"` | ||
} | ||
err := (r.(AvailabilityZoneProfilePage)).ExtractInto(&s) | ||
return s.AvailabilityZoneProfiles, err | ||
} | ||
|
||
type commonResult struct { | ||
gophercloud.Result | ||
} | ||
|
||
// Extract is a function that accepts a result and extracts a availability_zone_profile. | ||
func (r commonResult) Extract() (*AvailabilityZoneProfile, error) { | ||
var s struct { | ||
AvailabilityZoneProfile *AvailabilityZoneProfile `json:"availability_zone_profile"` | ||
} | ||
err := r.ExtractInto(&s) | ||
return s.AvailabilityZoneProfile, err | ||
} | ||
|
||
// CreateResult represents the result of a create operation. Call its Extract | ||
// method to interpret it as a AvailabilityZoneProfile. | ||
type CreateResult struct { | ||
commonResult | ||
} | ||
|
||
// GetResult represents the result of a get operation. Call its Extract | ||
// method to interpret it as a AvailabilityZoneProfile. | ||
type GetResult struct { | ||
commonResult | ||
} | ||
|
||
// UpdateResult represents the result of an update operation. Call its Extract | ||
// method to interpret it as a AvailabilityZoneProfile. | ||
type UpdateResult struct { | ||
commonResult | ||
} | ||
|
||
// DeleteResult represents the result of a delete operation. Call its | ||
// ExtractErr method to determine if the request succeeded or failed. | ||
type DeleteResult struct { | ||
gophercloud.ErrResult | ||
} |
16 changes: 16 additions & 0 deletions
16
openstack/loadbalancer/v2/availability_zone_profile/urls.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package availability_zone_profile | ||
|
||
import "github.com/gophercloud/gophercloud" | ||
|
||
const ( | ||
rootPath = "lbaas" | ||
resourcePath = "availabilityzoneprofiles" | ||
) | ||
|
||
func rootURL(c *gophercloud.ServiceClient) string { | ||
return c.ServiceURL(rootPath, resourcePath) | ||
} | ||
|
||
func resourceURL(c *gophercloud.ServiceClient, id string) string { | ||
return c.ServiceURL(rootPath, resourcePath, id) | ||
} |
Oops, something went wrong.