From abe705b553123467c3546ab6854f63029b2dc67a Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 01:07:20 +0200 Subject: [PATCH 01/54] ELB --- openstack/elb/v3/certificates/Create.go | 46 +++++++ openstack/elb/v3/certificates/Delete.go | 9 ++ openstack/elb/v3/certificates/Get.go | 11 ++ openstack/elb/v3/certificates/List.go | 44 +++++++ openstack/elb/v3/certificates/Update.go | 39 ++++++ openstack/elb/v3/certificates/requests.go | 135 --------------------- openstack/elb/v3/certificates/urls.go | 17 --- openstack/elb/v3/flavors/requests.go | 4 +- openstack/elb/v3/flavors/urls.go | 17 --- openstack/elb/v3/listeners/requests.go | 10 +- openstack/elb/v3/listeners/urls.go | 17 --- openstack/elb/v3/loadbalancers/requests.go | 12 +- openstack/elb/v3/loadbalancers/urls.go | 22 ---- openstack/elb/v3/members/requests.go | 10 +- openstack/elb/v3/members/urls.go | 16 --- openstack/elb/v3/monitors/requests.go | 10 +- openstack/elb/v3/monitors/urls.go | 15 --- openstack/elb/v3/policies/requests.go | 10 +- openstack/elb/v3/policies/urls.go | 17 --- openstack/elb/v3/pools/requests.go | 10 +- openstack/elb/v3/pools/urls.go | 15 --- openstack/elb/v3/rules/requests.go | 10 +- openstack/elb/v3/rules/urls.go | 18 --- 23 files changed, 187 insertions(+), 327 deletions(-) create mode 100644 openstack/elb/v3/certificates/Create.go create mode 100644 openstack/elb/v3/certificates/Delete.go create mode 100644 openstack/elb/v3/certificates/Get.go create mode 100644 openstack/elb/v3/certificates/List.go create mode 100644 openstack/elb/v3/certificates/Update.go delete mode 100644 openstack/elb/v3/certificates/requests.go delete mode 100644 openstack/elb/v3/certificates/urls.go delete mode 100644 openstack/elb/v3/flavors/urls.go delete mode 100644 openstack/elb/v3/listeners/urls.go delete mode 100644 openstack/elb/v3/loadbalancers/urls.go delete mode 100644 openstack/elb/v3/members/urls.go delete mode 100644 openstack/elb/v3/monitors/urls.go delete mode 100644 openstack/elb/v3/policies/urls.go delete mode 100644 openstack/elb/v3/pools/urls.go delete mode 100644 openstack/elb/v3/rules/urls.go diff --git a/openstack/elb/v3/certificates/Create.go b/openstack/elb/v3/certificates/Create.go new file mode 100644 index 000000000..ad1371527 --- /dev/null +++ b/openstack/elb/v3/certificates/Create.go @@ -0,0 +1,46 @@ +package certificates + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// CreateOptsBuilder is the interface options structs have to satisfy in order +// to be used in the main Create operation in this package. Since many +// extensions decorate or modify the common logic, it is useful for them to +// satisfy a basic interface in order for them to be used. +type CreateOptsBuilder interface { + ToCertificateCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options' struct used in this package's Create +// operation. +type CreateOpts struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + Domain string `json:"domain,omitempty"` + PrivateKey string `json:"private_key,omitempty"` + Certificate string `json:"certificate" required:"true"` +} + +// ToCertificateCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "certificate") +} + +// Create is an operation which provisions a new loadbalancer 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. +// +// Users with an admin role can create loadbalancers on behalf of other tenants by +// specifying a TenantID attribute different from their own. +func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToCertificateCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("certificates"), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} diff --git a/openstack/elb/v3/certificates/Delete.go b/openstack/elb/v3/certificates/Delete.go new file mode 100644 index 000000000..2654a3048 --- /dev/null +++ b/openstack/elb/v3/certificates/Delete.go @@ -0,0 +1,9 @@ +package certificates + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Delete will permanently delete a particular Certificate based on its unique ID. +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("certificates", id), nil) + return +} diff --git a/openstack/elb/v3/certificates/Get.go b/openstack/elb/v3/certificates/Get.go new file mode 100644 index 000000000..67cea98e3 --- /dev/null +++ b/openstack/elb/v3/certificates/Get.go @@ -0,0 +1,11 @@ +package certificates + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" +) + +// Get retrieves a particular Loadbalancer based on its unique ID. +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("certificates", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/certificates/List.go b/openstack/elb/v3/certificates/List.go new file mode 100644 index 000000000..ba6671f51 --- /dev/null +++ b/openstack/elb/v3/certificates/List.go @@ -0,0 +1,44 @@ +package certificates + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToCertificateListQuery() (string, error) +} + +type ListOpts struct { + ID []string `q:"id"` + Name []string `q:"name"` + Description []string `q:"description"` + Type []string `q:"type"` + Domain []string `q:"domain"` + + Limit int `q:"limit"` + Marker string `q:"marker"` + PageReverse bool `q:"page_reverse"` +} + +// ToCertificateListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToCertificateListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + return q.String(), err +} + +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("certificates") + if opts != nil { + query, err := opts.ToCertificateListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return CertificatePage{pagination.SinglePageBase(r)} + }) +} diff --git a/openstack/elb/v3/certificates/Update.go b/openstack/elb/v3/certificates/Update.go new file mode 100644 index 000000000..db18b6ba4 --- /dev/null +++ b/openstack/elb/v3/certificates/Update.go @@ -0,0 +1,39 @@ +package certificates + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// UpdateOptsBuilder is the interface options structs have to satisfy in order +// to be used in the main Update operation in this package. Since many +// extensions decorate or modify the common logic, it is useful for them to +// satisfy a basic interface in order for them to be used. +type UpdateOptsBuilder interface { + ToCertificateUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options' struct used in this package's Update +// operation. +type UpdateOpts struct { + Name string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + Domain string `json:"domain,omitempty"` + PrivateKey string `json:"private_key,omitempty"` + Certificate string `json:"certificate,omitempty"` +} + +// ToCertificateUpdateMap casts a UpdateOpts struct to a map. +func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "certificate") +} + +// Update is an operation which modifies the attributes of the specified Certificate. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { + b, err := opts.ToCertificateUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("certificates", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/openstack/elb/v3/certificates/requests.go b/openstack/elb/v3/certificates/requests.go deleted file mode 100644 index 6d465445b..000000000 --- a/openstack/elb/v3/certificates/requests.go +++ /dev/null @@ -1,135 +0,0 @@ -package certificates - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToCertificateListQuery() (string, error) -} - -type ListOpts struct { - ID []string `q:"id"` - Name []string `q:"name"` - Description []string `q:"description"` - Type []string `q:"type"` - Domain []string `q:"domain"` - - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` -} - -// ToCertificateListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToCertificateListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - return q.String(), err -} - -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := rootURL(client) - if opts != nil { - query, err := opts.ToCertificateListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return CertificatePage{pagination.SinglePageBase(r)} - }) -} - -// CreateOptsBuilder is the interface options structs have to satisfy in order -// to be used in the main Create operation in this package. Since many -// extensions decorate or modify the common logic, it is useful for them to -// satisfy a basic interface in order for them to be used. -type CreateOptsBuilder interface { - ToCertificateCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's Create -// operation. -type CreateOpts struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Type string `json:"type,omitempty"` - Domain string `json:"domain,omitempty"` - PrivateKey string `json:"private_key,omitempty"` - Certificate string `json:"certificate" required:"true"` -} - -// ToCertificateCreateMap casts a CreateOpts struct to a map. -func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "certificate") -} - -// Create is an operation which provisions a new loadbalancer 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. -// -// Users with an admin role can create loadbalancers on behalf of other tenants by -// specifying a TenantID attribute different from their own. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToCertificateCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(rootURL(client), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 201}, - }) - return -} - -// Get retrieves a particular Loadbalancer based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) - return -} - -// UpdateOptsBuilder is the interface options structs have to satisfy in order -// to be used in the main Update operation in this package. Since many -// extensions decorate or modify the common logic, it is useful for them to -// satisfy a basic interface in order for them to be used. -type UpdateOptsBuilder interface { - ToCertificateUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts is the common options' struct used in this package's Update -// operation. -type UpdateOpts struct { - Name string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - PrivateKey string `json:"private_key,omitempty"` - Certificate string `json:"certificate,omitempty"` -} - -// ToCertificateUpdateMap casts a UpdateOpts struct to a map. -func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "certificate") -} - -// Update is an operation which modifies the attributes of the specified Certificate. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { - b, err := opts.ToCertificateUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - -// Delete will permanently delete a particular Certificate based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, id), nil) - return -} diff --git a/openstack/elb/v3/certificates/urls.go b/openstack/elb/v3/certificates/urls.go deleted file mode 100644 index 6824a8f0e..000000000 --- a/openstack/elb/v3/certificates/urls.go +++ /dev/null @@ -1,17 +0,0 @@ -package certificates - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -const ( - resourcePath = "certificates" -) - -func rootURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL(resourcePath) -} - -func resourceURL(c *golangsdk.ServiceClient, id string) string { - return c.ServiceURL(resourcePath, id) -} diff --git a/openstack/elb/v3/flavors/requests.go b/openstack/elb/v3/flavors/requests.go index b5d06f0de..40d9fe767 100644 --- a/openstack/elb/v3/flavors/requests.go +++ b/openstack/elb/v3/flavors/requests.go @@ -35,7 +35,7 @@ func (opts ListOpts) ToFlavorListMap() (string, error) { // List returns a Pager which allows you to iterate over a collection of // flavors. func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := listURL(client) + url := client.ServiceURL("flavors") if opts != nil { queryString, err := opts.ToFlavorListMap() if err != nil { @@ -50,6 +50,6 @@ func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Page // Get returns additional information about a Flavor, given its ID. func Get(client *golangsdk.ServiceClient, flavorID string) (r GetResult) { - _, r.Err = client.Get(getURL(client, flavorID), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("flavors", flavorID), &r.Body, nil) return } diff --git a/openstack/elb/v3/flavors/urls.go b/openstack/elb/v3/flavors/urls.go deleted file mode 100644 index 3a451bee6..000000000 --- a/openstack/elb/v3/flavors/urls.go +++ /dev/null @@ -1,17 +0,0 @@ -package flavors - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -const ( - resourcePath = "flavors" -) - -func listURL(sc *golangsdk.ServiceClient) string { - return sc.ServiceURL(resourcePath) -} - -func getURL(sc *golangsdk.ServiceClient, flavorID string) string { - return sc.ServiceURL(resourcePath, flavorID) -} diff --git a/openstack/elb/v3/listeners/requests.go b/openstack/elb/v3/listeners/requests.go index fb9503eaa..7126fa0b5 100644 --- a/openstack/elb/v3/listeners/requests.go +++ b/openstack/elb/v3/listeners/requests.go @@ -137,13 +137,13 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe r.Err = err return } - _, r.Err = client.Post(rootURL(client), b, &r.Body, nil) + _, r.Err = client.Post(client.ServiceURL("listeners"), b, &r.Body, nil) return } // Get retrieves a particular Listeners based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("listeners", id), &r.Body, nil) return } @@ -238,7 +238,7 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) r.Err = err return } - _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("listeners", id), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) return @@ -246,7 +246,7 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) // Delete will permanently delete a particular Listeners based on its unique ID. func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, id), nil) + _, r.Err = client.Delete(client.ServiceURL("listeners", id), nil) return } @@ -285,7 +285,7 @@ func (opts ListOpts) ToListenerListQuery() (string, error) { } func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := rootURL(client) + url := client.ServiceURL("listeners") if opts != nil { q, err := opts.ToListenerListQuery() if err != nil { diff --git a/openstack/elb/v3/listeners/urls.go b/openstack/elb/v3/listeners/urls.go deleted file mode 100644 index 1c21cf64c..000000000 --- a/openstack/elb/v3/listeners/urls.go +++ /dev/null @@ -1,17 +0,0 @@ -package listeners - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -const ( - resourcePath = "listeners" -) - -func rootURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL(resourcePath) -} - -func resourceURL(c *golangsdk.ServiceClient, id string) string { - return c.ServiceURL(resourcePath, id) -} diff --git a/openstack/elb/v3/loadbalancers/requests.go b/openstack/elb/v3/loadbalancers/requests.go index 76e1337d0..94a46e751 100644 --- a/openstack/elb/v3/loadbalancers/requests.go +++ b/openstack/elb/v3/loadbalancers/requests.go @@ -38,7 +38,7 @@ func (opts ListOpts) ToLoadbalancerListQuery() (string, error) { } func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := rootURL(client) + url := client.ServiceURL("loadbalancers") if opts != nil { query, err := opts.ToLoadbalancerListQuery() if err != nil { @@ -167,13 +167,13 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe r.Err = err return } - _, r.Err = client.Post(rootURL(client), b, &r.Body, nil) + _, r.Err = client.Post(client.ServiceURL("loadbalancers"), b, &r.Body, nil) return } // Get retrieves a particular Loadbalancer based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("loadbalancers", id), &r.Body, nil) return } @@ -237,7 +237,7 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r Upda r.Err = err return } - _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("loadbalancers", id), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) return @@ -246,12 +246,12 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r Upda // Delete will permanently delete a particular LoadBalancer based on its // unique ID. func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, id), nil) + _, r.Err = client.Delete(client.ServiceURL("loadbalancers", id), nil) return } // GetStatuses will return the status of a particular LoadBalancer. func GetStatuses(client *golangsdk.ServiceClient, id string) (r GetStatusesResult) { - _, r.Err = client.Get(statusURL(client, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("loadbalancers", id, "statuses"), &r.Body, nil) return } diff --git a/openstack/elb/v3/loadbalancers/urls.go b/openstack/elb/v3/loadbalancers/urls.go deleted file mode 100644 index e763d3464..000000000 --- a/openstack/elb/v3/loadbalancers/urls.go +++ /dev/null @@ -1,22 +0,0 @@ -package loadbalancers - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -const ( - resourcePath = "loadbalancers" - statusPath = "statuses" -) - -func rootURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL(resourcePath) -} - -func resourceURL(c *golangsdk.ServiceClient, id string) string { - return c.ServiceURL(resourcePath, id) -} - -func statusURL(c *golangsdk.ServiceClient, id string) string { - return c.ServiceURL(resourcePath, id, statusPath) -} diff --git a/openstack/elb/v3/members/requests.go b/openstack/elb/v3/members/requests.go index 3f3e2f568..965e96326 100644 --- a/openstack/elb/v3/members/requests.go +++ b/openstack/elb/v3/members/requests.go @@ -47,7 +47,7 @@ func (opts ListOpts) ToMembersListQuery() (string, error) { // Default policy settings return only those members that are owned by the // tenant who submits the request, unless an admin user submits the request. func List(client *golangsdk.ServiceClient, poolID string, opts ListOptsBuilder) pagination.Pager { - url := rootURL(client, poolID) + url := client.ServiceURL("pools", poolID, "members") if opts != nil { query, err := opts.ToMembersListQuery() if err != nil { @@ -112,7 +112,7 @@ func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOptsBuild r.Err = err return } - _, r.Err = client.Post(rootURL(client, poolID), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Post(client.ServiceURL("pools", poolID, "members"), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{201}, }) return @@ -120,7 +120,7 @@ func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOptsBuild // Get retrieves a particular Pool Member based on its unique ID. func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, poolID, memberID), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("pools", poolID, "members", memberID), &r.Body, nil) return } @@ -159,7 +159,7 @@ func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opt r.Err = err return } - _, r.Err = client.Put(resourceURL(client, poolID, memberID), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("pools", poolID, "members", memberID), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 201, 202}, }) return @@ -168,6 +168,6 @@ func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opt // Delete will remove and disassociate a Member from a particular // Pool. func Delete(client *golangsdk.ServiceClient, poolID string, memberID string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, poolID, memberID), nil) + _, r.Err = client.Delete(client.ServiceURL("pools", poolID, "members", memberID), nil) return } diff --git a/openstack/elb/v3/members/urls.go b/openstack/elb/v3/members/urls.go deleted file mode 100644 index d5f94b18a..000000000 --- a/openstack/elb/v3/members/urls.go +++ /dev/null @@ -1,16 +0,0 @@ -package members - -import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - -const ( - resourcePath = "pools" - memberPath = "members" -) - -func rootURL(c *golangsdk.ServiceClient, poolID string) string { - return c.ServiceURL(resourcePath, poolID, memberPath) -} - -func resourceURL(c *golangsdk.ServiceClient, poolID string, memberID string) string { - return c.ServiceURL(resourcePath, poolID, memberPath, memberID) -} diff --git a/openstack/elb/v3/monitors/requests.go b/openstack/elb/v3/monitors/requests.go index 4bd0ef9f8..72136002a 100644 --- a/openstack/elb/v3/monitors/requests.go +++ b/openstack/elb/v3/monitors/requests.go @@ -53,7 +53,7 @@ func (opts ListOpts) ToMonitorListQuery() (string, error) { // Default policy settings return only those health monitors that are owned by the // tenant who submits the request, unless an admin user submits the request. func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := rootURL(client) + url := client.ServiceURL("healthmonitors") if opts != nil { query, err := opts.ToMonitorListQuery() if err != nil { @@ -158,13 +158,13 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe r.Err = err return } - _, r.Err = client.Post(rootURL(client), b, &r.Body, nil) + _, r.Err = client.Post(client.ServiceURL("healthmonitors"), b, &r.Body, nil) return } // Get retrieves a particular Health Monitor based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("healthmonitors", id), &r.Body, nil) return } @@ -235,7 +235,7 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) return } - _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("healthmonitors", id), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) return @@ -243,6 +243,6 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) // Delete will permanently delete a particular Monitor based on its unique ID. func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, id), nil) + _, r.Err = client.Delete(client.ServiceURL("healthmonitors", id), nil) return } diff --git a/openstack/elb/v3/monitors/urls.go b/openstack/elb/v3/monitors/urls.go deleted file mode 100644 index d75f7c77f..000000000 --- a/openstack/elb/v3/monitors/urls.go +++ /dev/null @@ -1,15 +0,0 @@ -package monitors - -import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - -const ( - resourcePath = "healthmonitors" -) - -func rootURL(client *golangsdk.ServiceClient) string { - return client.ServiceURL(resourcePath) -} - -func resourceURL(client *golangsdk.ServiceClient, id string) string { - return client.ServiceURL(resourcePath, id) -} diff --git a/openstack/elb/v3/policies/requests.go b/openstack/elb/v3/policies/requests.go index 78e9ff048..64da02c85 100644 --- a/openstack/elb/v3/policies/requests.go +++ b/openstack/elb/v3/policies/requests.go @@ -174,7 +174,7 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe r.Err = err return } - _, r.Err = client.Post(baseURL(client), b, &r.Body, nil) + _, r.Err = client.Post(client.ServiceURL("l7policies"), b, &r.Body, nil) return } @@ -206,7 +206,7 @@ func (opts ListOpts) ToPolicyListQuery() (string, error) { } func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := baseURL(client) + url := client.ServiceURL("l7policies") if opts != nil { q, err := opts.ToPolicyListQuery() if err != nil { @@ -221,7 +221,7 @@ func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Page } func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("l7policies", id), &r.Body, nil) return } @@ -251,13 +251,13 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) r.Err = err return } - _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("l7policies", id), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 201}, }) return } func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, id), nil) + _, r.Err = client.Delete(client.ServiceURL("l7policies", id), nil) return } diff --git a/openstack/elb/v3/policies/urls.go b/openstack/elb/v3/policies/urls.go deleted file mode 100644 index e61ae8d52..000000000 --- a/openstack/elb/v3/policies/urls.go +++ /dev/null @@ -1,17 +0,0 @@ -package policies - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -const ( - basePath = "l7policies" -) - -func baseURL(client *golangsdk.ServiceClient) string { - return client.ServiceURL(basePath) -} - -func resourceURL(client *golangsdk.ServiceClient, id string) string { - return client.ServiceURL(basePath, id) -} diff --git a/openstack/elb/v3/pools/requests.go b/openstack/elb/v3/pools/requests.go index 8425dc2be..7f1381ad7 100644 --- a/openstack/elb/v3/pools/requests.go +++ b/openstack/elb/v3/pools/requests.go @@ -47,7 +47,7 @@ func (opts ListOpts) ToPoolListQuery() (string, error) { // Default policy settings return only those pools that are owned by the // tenant who submits the request, unless an admin user submits the request. func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := rootURL(client) + url := client.ServiceURL("pools") if opts != nil { query, err := opts.ToPoolListQuery() if err != nil { @@ -154,13 +154,13 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe r.Err = err return } - _, r.Err = client.Post(rootURL(client), b, &r.Body, nil) + _, r.Err = client.Post(client.ServiceURL("pools"), b, &r.Body, nil) return } // Get retrieves a particular pool based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("pools", id), &r.Body, nil) return } @@ -221,7 +221,7 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) r.Err = err return } - _, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("pools", id), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) return @@ -229,6 +229,6 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) // Delete will permanently delete a particular pool based on its unique ID. func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, id), nil) + _, r.Err = client.Delete(client.ServiceURL("pools", id), nil) return } diff --git a/openstack/elb/v3/pools/urls.go b/openstack/elb/v3/pools/urls.go deleted file mode 100644 index d5eae9abe..000000000 --- a/openstack/elb/v3/pools/urls.go +++ /dev/null @@ -1,15 +0,0 @@ -package pools - -import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - -const ( - resourcePath = "pools" -) - -func rootURL(client *golangsdk.ServiceClient) string { - return client.ServiceURL(resourcePath) -} - -func resourceURL(client *golangsdk.ServiceClient, poolID string) string { - return client.ServiceURL(resourcePath, poolID) -} diff --git a/openstack/elb/v3/rules/requests.go b/openstack/elb/v3/rules/requests.go index 2b01cb2e7..6ae92a76c 100644 --- a/openstack/elb/v3/rules/requests.go +++ b/openstack/elb/v3/rules/requests.go @@ -73,12 +73,12 @@ func Create(client *golangsdk.ServiceClient, policyID string, opts CreateOptsBui r.Err = err return } - _, r.Err = client.Post(baseURL(client, policyID), b, &r.Body, nil) + _, r.Err = client.Post(client.ServiceURL("l7policies", policyID, "rules"), b, &r.Body, nil) return } func Get(client *golangsdk.ServiceClient, policyID, id string) (r GetResult) { - _, r.Err = client.Get(resourceURL(client, policyID, id), &r.Body, nil) + _, r.Err = client.Get(client.ServiceURL("l7policies", policyID, "rules", id), &r.Body, nil) return } @@ -102,7 +102,7 @@ func Update(client *golangsdk.ServiceClient, policyID, id string, opts UpdateOpt r.Err = err return } - _, r.Err = client.Put(resourceURL(client, policyID, id), b, &r.Body, &golangsdk.RequestOpts{ + _, r.Err = client.Put(client.ServiceURL("l7policies", policyID, "rules", id), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 201}, }) return @@ -124,7 +124,7 @@ type ListOpts struct { } func List(client *golangsdk.ServiceClient, policyID string, opts ListOptsBuilder) pagination.Pager { - url := baseURL(client, policyID) + url := client.ServiceURL("l7policies", policyID, "rules") if opts != nil { q, err := opts.ToRuleListQuery() @@ -140,6 +140,6 @@ func List(client *golangsdk.ServiceClient, policyID string, opts ListOptsBuilder } func Delete(client *golangsdk.ServiceClient, policyID, id string) (r DeleteResult) { - _, r.Err = client.Delete(resourceURL(client, policyID, id), nil) + _, r.Err = client.Delete(client.ServiceURL("l7policies", policyID, "rules", id), nil) return } diff --git a/openstack/elb/v3/rules/urls.go b/openstack/elb/v3/rules/urls.go deleted file mode 100644 index 05be98068..000000000 --- a/openstack/elb/v3/rules/urls.go +++ /dev/null @@ -1,18 +0,0 @@ -package rules - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -const ( - policyBasePath = "l7policies" - ruleBasePath = "rules" -) - -func baseURL(client *golangsdk.ServiceClient, policyID string) string { - return client.ServiceURL(policyBasePath, policyID, ruleBasePath) -} - -func resourceURL(client *golangsdk.ServiceClient, policyID, id string) string { - return client.ServiceURL(policyBasePath, policyID, ruleBasePath, id) -} From 0d151a8dc98d155c0df9d02535ad02ff2b296ebf Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 01:48:40 +0200 Subject: [PATCH 02/54] Move --- openstack/elb/v3/flavors/Get.go | 11 + .../elb/v3/flavors/{requests.go => List.go} | 8 +- openstack/elb/v3/listeners/Create.go | 117 ++++++++ openstack/elb/v3/listeners/Delete.go | 9 + openstack/elb/v3/listeners/Get.go | 9 + openstack/elb/v3/listeners/List.go | 54 ++++ openstack/elb/v3/listeners/Update.go | 95 +++++++ openstack/elb/v3/listeners/requests.go | 269 ------------------ openstack/elb/v3/loadbalancers/Create.go | 90 ++++++ openstack/elb/v3/loadbalancers/Delete.go | 10 + openstack/elb/v3/loadbalancers/Get.go | 9 + openstack/elb/v3/loadbalancers/GetStatuses.go | 9 + openstack/elb/v3/loadbalancers/List.go | 51 ++++ openstack/elb/v3/loadbalancers/Update.go | 69 +++++ openstack/elb/v3/loadbalancers/requests.go | 220 -------------- openstack/elb/v3/members/Create.go | 61 ++++ openstack/elb/v3/members/Delete.go | 12 + openstack/elb/v3/members/Get.go | 9 + openstack/elb/v3/members/List.go | 61 ++++ openstack/elb/v3/members/Update.go | 44 +++ openstack/elb/v3/members/requests.go | 173 ----------- openstack/elb/v3/monitors/Create.go | 89 ++++++ openstack/elb/v3/monitors/Delete.go | 9 + openstack/elb/v3/monitors/Get.go | 9 + openstack/elb/v3/monitors/List.go | 67 +++++ openstack/elb/v3/monitors/Update.go | 76 +++++ openstack/elb/v3/monitors/requests.go | 237 --------------- openstack/elb/v3/policies/Create.go | 89 ++++++ openstack/elb/v3/policies/Delete.go | 8 + openstack/elb/v3/policies/Get.go | 8 + openstack/elb/v3/policies/List.go | 48 ++++ openstack/elb/v3/policies/Update.go | 35 +++ openstack/elb/v3/policies/requests.go | 169 ----------- openstack/elb/v3/pools/Create.go | 78 +++++ openstack/elb/v3/pools/Delete.go | 9 + openstack/elb/v3/pools/Get.go | 9 + openstack/elb/v3/pools/List.go | 61 ++++ openstack/elb/v3/pools/Update.go | 66 +++++ openstack/elb/v3/pools/requests.go | 210 -------------- openstack/elb/v3/rules/Create.go | 55 ++++ openstack/elb/v3/rules/Delete.go | 8 + openstack/elb/v3/rules/Get.go | 8 + openstack/elb/v3/rules/List.go | 37 +++ openstack/elb/v3/rules/Update.go | 29 ++ openstack/elb/v3/rules/requests.go | 124 -------- 45 files changed, 1519 insertions(+), 1409 deletions(-) create mode 100644 openstack/elb/v3/flavors/Get.go rename openstack/elb/v3/flavors/{requests.go => List.go} (81%) create mode 100644 openstack/elb/v3/listeners/Create.go create mode 100644 openstack/elb/v3/listeners/Delete.go create mode 100644 openstack/elb/v3/listeners/Get.go create mode 100644 openstack/elb/v3/listeners/List.go create mode 100644 openstack/elb/v3/listeners/Update.go create mode 100644 openstack/elb/v3/loadbalancers/Create.go create mode 100644 openstack/elb/v3/loadbalancers/Delete.go create mode 100644 openstack/elb/v3/loadbalancers/Get.go create mode 100644 openstack/elb/v3/loadbalancers/GetStatuses.go create mode 100644 openstack/elb/v3/loadbalancers/List.go create mode 100644 openstack/elb/v3/loadbalancers/Update.go create mode 100644 openstack/elb/v3/members/Create.go create mode 100644 openstack/elb/v3/members/Delete.go create mode 100644 openstack/elb/v3/members/Get.go create mode 100644 openstack/elb/v3/members/List.go create mode 100644 openstack/elb/v3/members/Update.go delete mode 100644 openstack/elb/v3/members/requests.go create mode 100644 openstack/elb/v3/monitors/Create.go create mode 100644 openstack/elb/v3/monitors/Delete.go create mode 100644 openstack/elb/v3/monitors/Get.go create mode 100644 openstack/elb/v3/monitors/List.go create mode 100644 openstack/elb/v3/monitors/Update.go create mode 100644 openstack/elb/v3/policies/Create.go create mode 100644 openstack/elb/v3/policies/Delete.go create mode 100644 openstack/elb/v3/policies/Get.go create mode 100644 openstack/elb/v3/policies/List.go create mode 100644 openstack/elb/v3/policies/Update.go create mode 100644 openstack/elb/v3/pools/Create.go create mode 100644 openstack/elb/v3/pools/Delete.go create mode 100644 openstack/elb/v3/pools/Get.go create mode 100644 openstack/elb/v3/pools/List.go create mode 100644 openstack/elb/v3/pools/Update.go create mode 100644 openstack/elb/v3/rules/Create.go create mode 100644 openstack/elb/v3/rules/Delete.go create mode 100644 openstack/elb/v3/rules/Get.go create mode 100644 openstack/elb/v3/rules/List.go create mode 100644 openstack/elb/v3/rules/Update.go diff --git a/openstack/elb/v3/flavors/Get.go b/openstack/elb/v3/flavors/Get.go new file mode 100644 index 000000000..ec173980b --- /dev/null +++ b/openstack/elb/v3/flavors/Get.go @@ -0,0 +1,11 @@ +package flavors + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" +) + +// Get returns additional information about a Flavor, given its ID. +func Get(client *golangsdk.ServiceClient, flavorID string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("flavors", flavorID), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/flavors/requests.go b/openstack/elb/v3/flavors/List.go similarity index 81% rename from openstack/elb/v3/flavors/requests.go rename to openstack/elb/v3/flavors/List.go index 40d9fe767..435235462 100644 --- a/openstack/elb/v3/flavors/requests.go +++ b/openstack/elb/v3/flavors/List.go @@ -1,7 +1,7 @@ package flavors import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) @@ -47,9 +47,3 @@ func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Page return FlavorPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } - -// Get returns additional information about a Flavor, given its ID. -func Get(client *golangsdk.ServiceClient, flavorID string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("flavors", flavorID), &r.Body, nil) - return -} diff --git a/openstack/elb/v3/listeners/Create.go b/openstack/elb/v3/listeners/Create.go new file mode 100644 index 000000000..7852bb71e --- /dev/null +++ b/openstack/elb/v3/listeners/Create.go @@ -0,0 +1,117 @@ +package listeners + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToListenerCreateMap() (map[string]interface{}, error) +} + +// CreateOpts represents options for creating a listener. +type CreateOpts struct { + // The administrative state of the Listener. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // the ID of the CA certificate used by the listener. + CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"` + + // The ID of the default pool with which the Listener is associated. + DefaultPoolID string `json:"default_pool_id,omitempty"` + + // A reference to a Barbican container of TLS secrets. + DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` + + // Provides supplementary information about the Listener. + Description string `json:"description,omitempty"` + + // whether to use HTTP2. + Http2Enable *bool `json:"http2_enable,omitempty"` + + // The load balancer on which to provision this listener. + LoadbalancerID string `json:"loadbalancer_id" required:"true"` + + // Specifies the Listener name. + Name string `json:"name,omitempty"` + + // ProjectID is only required if the caller has an admin role and wants + // to create a pool for another project. + ProjectID string `json:"project_id,omitempty"` + + // The protocol - can either be TCP, HTTP or HTTPS. + Protocol Protocol `json:"protocol" required:"true"` + + // The port on which to listen for client traffic. + ProtocolPort int `json:"protocol_port" required:"true"` + + // A list of references to TLS secrets. + SniContainerRefs []string `json:"sni_container_refs,omitempty"` + + // Specifies how wildcard domain name matches with the SNI certificates used by the listener. + // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. + // The default value is wildcard. + SniMatchAlgo string `json:"sni_match_algo,omitempty"` + + // A list of Tags. + Tags []tags.ResourceTag `json:"tags,omitempty"` + + // Specifies the security policy used by the listener. + TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"` + + // Specifies the ID of the custom security policy. + // Note: + // This parameter is available only for HTTPS listeners added to a dedicated load balancer. + // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). + SecurityPolicy string `json:"security_policy_id,omitempty"` + + // Whether enable member retry + EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` + + // The keepalive timeout of the Listener. + KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` + + // The client timeout of the Listener. + ClientTimeout int `json:"client_timeout,omitempty"` + + // The member timeout of the Listener. + MemberTimeout int `json:"member_timeout,omitempty"` + + // The IpGroup of the Listener. + IpGroup *IpGroup `json:"ipgroup,omitempty"` + + // The http insert headers of the Listener. + InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` + + // Transparent client ip enable + TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` + + // Enhance L7policy enable + EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` +} + +// ToListenerCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "listener") +} + +// Create is an operation which provisions a new Listeners 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. +// +// Users with an admin role can create Listeners on behalf of other tenants by +// specifying a TenantID attribute different from their own. +func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToListenerCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("listeners"), b, &r.Body, nil) + return +} diff --git a/openstack/elb/v3/listeners/Delete.go b/openstack/elb/v3/listeners/Delete.go new file mode 100644 index 000000000..cf4cdb8ad --- /dev/null +++ b/openstack/elb/v3/listeners/Delete.go @@ -0,0 +1,9 @@ +package listeners + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Delete will permanently delete a particular Listeners based on its unique ID. +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("listeners", id), nil) + return +} diff --git a/openstack/elb/v3/listeners/Get.go b/openstack/elb/v3/listeners/Get.go new file mode 100644 index 000000000..d371f348e --- /dev/null +++ b/openstack/elb/v3/listeners/Get.go @@ -0,0 +1,9 @@ +package listeners + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Get retrieves a particular Listeners based on its unique ID. +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("listeners", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/listeners/List.go b/openstack/elb/v3/listeners/List.go new file mode 100644 index 000000000..c41e359ba --- /dev/null +++ b/openstack/elb/v3/listeners/List.go @@ -0,0 +1,54 @@ +package listeners + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +type ListOptsBuilder interface { + ToListenerListQuery() (string, error) +} + +type ListOpts struct { + Limit int `q:"limit"` + Marker string `q:"marker"` + PageReverse bool `q:"page_reverse"` + + ProtocolPort []int `q:"protocol_port"` + Protocol []Protocol `q:"protocol"` + Description []string `q:"description"` + DefaultTLSContainerRef []string `q:"default_tls_container_ref"` + ClientCATLSContainerRef []string `q:"client_ca_tls_container_ref"` + DefaultPoolID []string `q:"default_pool_id"` + ID []string `q:"id"` + Name []string `q:"name"` + LoadBalancerID []string `q:"loadbalancer_id"` + TLSCiphersPolicy []string `q:"tls_ciphers_policy"` + MemberAddress []string `q:"member_address"` + MemberDeviceID []string `q:"member_device_id"` + MemberTimeout []int `q:"member_timeout"` + ClientTimeout []int `q:"client_timeout"` + KeepAliveTimeout []int `q:"keepalive_timeout"` +} + +func (opts ListOpts) ToListenerListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return "", err + } + return q.String(), nil +} + +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("listeners") + if opts != nil { + q, err := opts.ToListenerListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += q + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return ListenerPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/listeners/Update.go b/openstack/elb/v3/listeners/Update.go new file mode 100644 index 000000000..38fa192be --- /dev/null +++ b/openstack/elb/v3/listeners/Update.go @@ -0,0 +1,95 @@ +package listeners + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToListenerUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts represents options for updating a Listener. +type UpdateOpts struct { + // The administrative state of the Listener. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // the ID of the CA certificate used by the listener. + CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"` + + // The ID of the default pool with which the Listener is associated. + DefaultPoolID string `json:"default_pool_id,omitempty"` + + // A reference to a container of TLS secrets. + DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"` + + // Provides supplementary information about the Listener. + Description *string `json:"description,omitempty"` + + // whether to use HTTP2. + Http2Enable *bool `json:"http2_enable,omitempty"` + + // Specifies the Listener name. + Name *string `json:"name,omitempty"` + + // A list of references to TLS secrets. + SniContainerRefs *[]string `json:"sni_container_refs,omitempty"` + + // Specifies how wildcard domain name matches with the SNI certificates used by the listener. + // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. + // The default value is wildcard. + SniMatchAlgo string `json:"sni_match_algo,omitempty"` + + // Specifies the security policy used by the listener. + TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"` + + // Specifies the ID of the custom security policy. + // Note: + // This parameter is available only for HTTPS listeners added to a dedicated load balancer. + // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). + SecurityPolicy string `json:"security_policy_id,omitempty"` + + // Whether enable member retry + EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` + + // The keepalive timeout of the Listener. + KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` + + // The client timeout of the Listener. + ClientTimeout int `json:"client_timeout,omitempty"` + + // The member timeout of the Listener. + MemberTimeout int `json:"member_timeout,omitempty"` + + // The IpGroup of the Listener. + IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"` + + // The http insert headers of the Listener. + InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` + + // Transparent client ip enable + TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` + + // Enhance L7policy enable + EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` +} + +// ToListenerUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "listener") +} + +// Update is an operation which modifies the attributes of the specified +// Listener. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToListenerUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("listeners", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} diff --git a/openstack/elb/v3/listeners/requests.go b/openstack/elb/v3/listeners/requests.go index 7126fa0b5..e68e8e2d1 100644 --- a/openstack/elb/v3/listeners/requests.go +++ b/openstack/elb/v3/listeners/requests.go @@ -1,11 +1,5 @@ package listeners -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - // Protocol represents a listener protocol. type Protocol string @@ -17,95 +11,6 @@ const ( ProtocolHTTPS Protocol = "HTTPS" ) -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToListenerCreateMap() (map[string]interface{}, error) -} - -// CreateOpts represents options for creating a listener. -type CreateOpts struct { - // The administrative state of the Listener. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // the ID of the CA certificate used by the listener. - CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"` - - // The ID of the default pool with which the Listener is associated. - DefaultPoolID string `json:"default_pool_id,omitempty"` - - // A reference to a Barbican container of TLS secrets. - DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` - - // Provides supplementary information about the Listener. - Description string `json:"description,omitempty"` - - // whether to use HTTP2. - Http2Enable *bool `json:"http2_enable,omitempty"` - - // The load balancer on which to provision this listener. - LoadbalancerID string `json:"loadbalancer_id" required:"true"` - - // Specifies the Listener name. - Name string `json:"name,omitempty"` - - // ProjectID is only required if the caller has an admin role and wants - // to create a pool for another project. - ProjectID string `json:"project_id,omitempty"` - - // The protocol - can either be TCP, HTTP or HTTPS. - Protocol Protocol `json:"protocol" required:"true"` - - // The port on which to listen for client traffic. - ProtocolPort int `json:"protocol_port" required:"true"` - - // A list of references to TLS secrets. - SniContainerRefs []string `json:"sni_container_refs,omitempty"` - - // Specifies how wildcard domain name matches with the SNI certificates used by the listener. - // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. - // The default value is wildcard. - SniMatchAlgo string `json:"sni_match_algo,omitempty"` - - // A list of Tags. - Tags []tags.ResourceTag `json:"tags,omitempty"` - - // Specifies the security policy used by the listener. - TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"` - - // Specifies the ID of the custom security policy. - // Note: - // This parameter is available only for HTTPS listeners added to a dedicated load balancer. - // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. - // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). - SecurityPolicy string `json:"security_policy_id,omitempty"` - - // Whether enable member retry - EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` - - // The keepalive timeout of the Listener. - KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` - - // The client timeout of the Listener. - ClientTimeout int `json:"client_timeout,omitempty"` - - // The member timeout of the Listener. - MemberTimeout int `json:"member_timeout,omitempty"` - - // The IpGroup of the Listener. - IpGroup *IpGroup `json:"ipgroup,omitempty"` - - // The http insert headers of the Listener. - InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` - - // Transparent client ip enable - TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` - - // Enhance L7policy enable - EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` -} - type IpGroup struct { IpGroupID string `json:"ipgroup_id" required:"true"` Enable *bool `json:"enable_ipgroup,omitempty"` @@ -119,181 +24,7 @@ type InsertHeaders struct { ForwardedHost *bool `json:"X-Forwarded-Host" required:"true"` } -// ToListenerCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "listener") -} - -// Create is an operation which provisions a new Listeners 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. -// -// Users with an admin role can create Listeners on behalf of other tenants by -// specifying a TenantID attribute different from their own. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToListenerCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("listeners"), b, &r.Body, nil) - return -} - -// Get retrieves a particular Listeners based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("listeners", id), &r.Body, nil) - return -} - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToListenerUpdateMap() (map[string]interface{}, error) -} - type IpGroupUpdate struct { IpGroupId string `json:"ipgroup_id,omitempty"` Type string `json:"type,omitempty"` } - -// UpdateOpts represents options for updating a Listener. -type UpdateOpts struct { - // The administrative state of the Listener. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // the ID of the CA certificate used by the listener. - CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"` - - // The ID of the default pool with which the Listener is associated. - DefaultPoolID string `json:"default_pool_id,omitempty"` - - // A reference to a container of TLS secrets. - DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"` - - // Provides supplementary information about the Listener. - Description *string `json:"description,omitempty"` - - // whether to use HTTP2. - Http2Enable *bool `json:"http2_enable,omitempty"` - - // Specifies the Listener name. - Name *string `json:"name,omitempty"` - - // A list of references to TLS secrets. - SniContainerRefs *[]string `json:"sni_container_refs,omitempty"` - - // Specifies how wildcard domain name matches with the SNI certificates used by the listener. - // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. - // The default value is wildcard. - SniMatchAlgo string `json:"sni_match_algo,omitempty"` - - // Specifies the security policy used by the listener. - TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"` - - // Specifies the ID of the custom security policy. - // Note: - // This parameter is available only for HTTPS listeners added to a dedicated load balancer. - // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. - // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). - SecurityPolicy string `json:"security_policy_id,omitempty"` - - // Whether enable member retry - EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` - - // The keepalive timeout of the Listener. - KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` - - // The client timeout of the Listener. - ClientTimeout int `json:"client_timeout,omitempty"` - - // The member timeout of the Listener. - MemberTimeout int `json:"member_timeout,omitempty"` - - // The IpGroup of the Listener. - IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"` - - // The http insert headers of the Listener. - InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` - - // Transparent client ip enable - TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` - - // Enhance L7policy enable - EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` -} - -// ToListenerUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "listener") -} - -// Update is an operation which modifies the attributes of the specified -// Listener. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToListenerUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(client.ServiceURL("listeners", id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 202}, - }) - return -} - -// Delete will permanently delete a particular Listeners based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("listeners", id), nil) - return -} - -type ListOptsBuilder interface { - ToListenerListQuery() (string, error) -} - -type ListOpts struct { - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` - - ProtocolPort []int `q:"protocol_port"` - Protocol []Protocol `q:"protocol"` - Description []string `q:"description"` - DefaultTLSContainerRef []string `q:"default_tls_container_ref"` - ClientCATLSContainerRef []string `q:"client_ca_tls_container_ref"` - DefaultPoolID []string `q:"default_pool_id"` - ID []string `q:"id"` - Name []string `q:"name"` - LoadBalancerID []string `q:"loadbalancer_id"` - TLSCiphersPolicy []string `q:"tls_ciphers_policy"` - MemberAddress []string `q:"member_address"` - MemberDeviceID []string `q:"member_device_id"` - MemberTimeout []int `q:"member_timeout"` - ClientTimeout []int `q:"client_timeout"` - KeepAliveTimeout []int `q:"keepalive_timeout"` -} - -func (opts ListOpts) ToListenerListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), nil -} - -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("listeners") - if opts != nil { - q, err := opts.ToListenerListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += q - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return ListenerPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} diff --git a/openstack/elb/v3/loadbalancers/Create.go b/openstack/elb/v3/loadbalancers/Create.go new file mode 100644 index 000000000..a8fe5fc86 --- /dev/null +++ b/openstack/elb/v3/loadbalancers/Create.go @@ -0,0 +1,90 @@ +package loadbalancers + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" +) + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToLoadBalancerCreateMap() (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 Loadbalancer. Does not have to be unique. + Name string `json:"name,omitempty"` + + // Human-readable description for the Loadbalancer. + Description string `json:"description,omitempty"` + + // The IP address of the Loadbalancer. + VipAddress string `json:"vip_address,omitempty"` + + // The network on which to allocate the Loadbalancer's address. + VipSubnetCidrID string `json:"vip_subnet_cidr_id,omitempty"` + + // The V6 network on which to allocate the Loadbalancer's address. + IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id,omitempty"` + + // The UUID of a l4 flavor. + L4Flavor string `json:"l4_flavor_id,omitempty"` + + // Guaranteed. + Guaranteed *bool `json:"guaranteed,omitempty"` + + // The VPC ID. + VpcID string `json:"vpc_id,omitempty"` + + // Availability Zone List. + AvailabilityZoneList []string `json:"availability_zone_list" required:"true"` + + // The tags of the Loadbalancer. + Tags []tags.ResourceTag `json:"tags,omitempty"` + + // The administrative state of the Loadbalancer. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // The UUID of a l7 flavor. + L7Flavor string `json:"l7_flavor_id,omitempty"` + + // IPv6 Bandwidth. + IPV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` + + // Public IP IDs. + PublicIpIDs []string `json:"publicip_ids,omitempty"` + + // Public IP. + PublicIp *PublicIp `json:"publicip,omitempty"` + + // ELB VirSubnet IDs. + ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"` + + // IP Target Enable. + IpTargetEnable *bool `json:"ip_target_enable,omitempty"` + + // Specifies whether to enable deletion protection for the load balancer. + DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` +} + +// ToLoadBalancerCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "loadbalancer") +} + +// Create is an operation which provisions a new loadbalancer 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(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToLoadBalancerCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("loadbalancers"), b, &r.Body, nil) + return +} diff --git a/openstack/elb/v3/loadbalancers/Delete.go b/openstack/elb/v3/loadbalancers/Delete.go new file mode 100644 index 000000000..ce9706ed3 --- /dev/null +++ b/openstack/elb/v3/loadbalancers/Delete.go @@ -0,0 +1,10 @@ +package loadbalancers + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Delete will permanently delete a particular LoadBalancer based on its +// unique ID. +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("loadbalancers", id), nil) + return +} diff --git a/openstack/elb/v3/loadbalancers/Get.go b/openstack/elb/v3/loadbalancers/Get.go new file mode 100644 index 000000000..e413f35a7 --- /dev/null +++ b/openstack/elb/v3/loadbalancers/Get.go @@ -0,0 +1,9 @@ +package loadbalancers + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Get retrieves a particular Loadbalancer based on its unique ID. +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("loadbalancers", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/loadbalancers/GetStatuses.go b/openstack/elb/v3/loadbalancers/GetStatuses.go new file mode 100644 index 000000000..1faf465d8 --- /dev/null +++ b/openstack/elb/v3/loadbalancers/GetStatuses.go @@ -0,0 +1,9 @@ +package loadbalancers + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// GetStatuses will return the status of a particular LoadBalancer. +func GetStatuses(client *golangsdk.ServiceClient, id string) (r GetStatusesResult) { + _, r.Err = client.Get(client.ServiceURL("loadbalancers", id, "statuses"), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/loadbalancers/List.go b/openstack/elb/v3/loadbalancers/List.go new file mode 100644 index 000000000..0b3d72df2 --- /dev/null +++ b/openstack/elb/v3/loadbalancers/List.go @@ -0,0 +1,51 @@ +package loadbalancers + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToLoadbalancerListQuery() (string, error) +} + +type ListOpts struct { + ID []string `q:"id"` + Name []string `q:"name"` + Description []string `q:"description"` + ProvisioningStatus []string `q:"provisioning_status"` + OperatingStatus []string `q:"operating_status"` + VpcID []string `q:"vpc_id"` + VipPortID []string `q:"vip_port_id"` + VipAddress []string `q:"vip_address"` + VipSubnetCidrID []string `q:"vip_subnet_cidr_id"` + L4FlavorID []string `q:"l4_flavor_id"` + L4ScaleFlavorID []string `q:"l4_scale_flavor_id"` + AvailabilityZoneList []string `q:"availability_zone_list"` + L7FlavorID []string `q:"l7_flavor_id"` + L7ScaleFlavorID []string `q:"l7_scale_flavor_id"` + Limit int `q:"limit"` + Marker string `q:"marker"` +} + +// ToLoadbalancerListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToLoadbalancerListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + return q.String(), err +} + +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("loadbalancers") + if opts != nil { + query, err := opts.ToLoadbalancerListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return LoadbalancerPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/loadbalancers/Update.go b/openstack/elb/v3/loadbalancers/Update.go new file mode 100644 index 000000000..6b956710a --- /dev/null +++ b/openstack/elb/v3/loadbalancers/Update.go @@ -0,0 +1,69 @@ +package loadbalancers + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToLoadBalancerUpdateMap() (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 Loadbalancer. Does not have to be unique. + Name string `json:"name,omitempty"` + + // Human-readable description for the Loadbalancer. + Description *string `json:"description,omitempty"` + + // The administrative state of the Loadbalancer. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // The IP address of the Loadbalancer. + VipAddress string `json:"vip_address,omitempty"` + + // The network on which to allocate the Loadbalancer's address. + VipSubnetCidrID *string `json:"vip_subnet_cidr_id,omitempty"` + + // The V6 network on which to allocate the Loadbalancer's address. + IpV6VipSubnetID *string `json:"ipv6_vip_virsubnet_id,omitempty"` + + // The UUID of a l4 flavor. + L4Flavor string `json:"l4_flavor_id,omitempty"` + + // The UUID of a l7 flavor. + L7Flavor string `json:"l7_flavor_id,omitempty"` + + // IPv6 Bandwidth. + IpV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` + + // ELB VirSubnet IDs. + ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"` + + // IP Target Enable. + IpTargetEnable *bool `json:"ip_target_enable,omitempty"` + + // Specifies whether to enable deletion protection for the load balancer. + DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` +} + +// ToLoadBalancerUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "loadbalancer") +} + +// Update is an operation which modifies the attributes of the specified +// LoadBalancer. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { + b, err := opts.ToLoadBalancerUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("loadbalancers", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} diff --git a/openstack/elb/v3/loadbalancers/requests.go b/openstack/elb/v3/loadbalancers/requests.go index 94a46e751..e391319e3 100644 --- a/openstack/elb/v3/loadbalancers/requests.go +++ b/openstack/elb/v3/loadbalancers/requests.go @@ -1,121 +1,5 @@ package loadbalancers -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToLoadbalancerListQuery() (string, error) -} - -type ListOpts struct { - ID []string `q:"id"` - Name []string `q:"name"` - Description []string `q:"description"` - ProvisioningStatus []string `q:"provisioning_status"` - OperatingStatus []string `q:"operating_status"` - VpcID []string `q:"vpc_id"` - VipPortID []string `q:"vip_port_id"` - VipAddress []string `q:"vip_address"` - VipSubnetCidrID []string `q:"vip_subnet_cidr_id"` - L4FlavorID []string `q:"l4_flavor_id"` - L4ScaleFlavorID []string `q:"l4_scale_flavor_id"` - AvailabilityZoneList []string `q:"availability_zone_list"` - L7FlavorID []string `q:"l7_flavor_id"` - L7ScaleFlavorID []string `q:"l7_scale_flavor_id"` - Limit int `q:"limit"` - Marker string `q:"marker"` -} - -// ToLoadbalancerListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToLoadbalancerListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - return q.String(), err -} - -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("loadbalancers") - if opts != nil { - query, err := opts.ToLoadbalancerListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return LoadbalancerPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} - -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToLoadBalancerCreateMap() (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 Loadbalancer. Does not have to be unique. - Name string `json:"name,omitempty"` - - // Human-readable description for the Loadbalancer. - Description string `json:"description,omitempty"` - - // The IP address of the Loadbalancer. - VipAddress string `json:"vip_address,omitempty"` - - // The network on which to allocate the Loadbalancer's address. - VipSubnetCidrID string `json:"vip_subnet_cidr_id,omitempty"` - - // The V6 network on which to allocate the Loadbalancer's address. - IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id,omitempty"` - - // The UUID of a l4 flavor. - L4Flavor string `json:"l4_flavor_id,omitempty"` - - // Guaranteed. - Guaranteed *bool `json:"guaranteed,omitempty"` - - // The VPC ID. - VpcID string `json:"vpc_id,omitempty"` - - // Availability Zone List. - AvailabilityZoneList []string `json:"availability_zone_list" required:"true"` - - // The tags of the Loadbalancer. - Tags []tags.ResourceTag `json:"tags,omitempty"` - - // The administrative state of the Loadbalancer. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The UUID of a l7 flavor. - L7Flavor string `json:"l7_flavor_id,omitempty"` - - // IPv6 Bandwidth. - IPV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` - - // Public IP IDs. - PublicIpIDs []string `json:"publicip_ids,omitempty"` - - // Public IP. - PublicIp *PublicIp `json:"publicip,omitempty"` - - // ELB VirSubnet IDs. - ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"` - - // IP Target Enable. - IpTargetEnable *bool `json:"ip_target_enable,omitempty"` - - // Specifies whether to enable deletion protection for the load balancer. - DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` -} - type BandwidthRef struct { // Share Bandwidth ID ID string `json:"id" required:"true"` @@ -151,107 +35,3 @@ type Bandwidth struct { // Share Type ShareType string `json:"share_type" required:"true"` } - -// ToLoadBalancerCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "loadbalancer") -} - -// Create is an operation which provisions a new loadbalancer 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(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToLoadBalancerCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("loadbalancers"), b, &r.Body, nil) - return -} - -// Get retrieves a particular Loadbalancer based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("loadbalancers", id), &r.Body, nil) - return -} - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToLoadBalancerUpdateMap() (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 Loadbalancer. Does not have to be unique. - Name string `json:"name,omitempty"` - - // Human-readable description for the Loadbalancer. - Description *string `json:"description,omitempty"` - - // The administrative state of the Loadbalancer. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The IP address of the Loadbalancer. - VipAddress string `json:"vip_address,omitempty"` - - // The network on which to allocate the Loadbalancer's address. - VipSubnetCidrID *string `json:"vip_subnet_cidr_id,omitempty"` - - // The V6 network on which to allocate the Loadbalancer's address. - IpV6VipSubnetID *string `json:"ipv6_vip_virsubnet_id,omitempty"` - - // The UUID of a l4 flavor. - L4Flavor string `json:"l4_flavor_id,omitempty"` - - // The UUID of a l7 flavor. - L7Flavor string `json:"l7_flavor_id,omitempty"` - - // IPv6 Bandwidth. - IpV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` - - // ELB VirSubnet IDs. - ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"` - - // IP Target Enable. - IpTargetEnable *bool `json:"ip_target_enable,omitempty"` - - // Specifies whether to enable deletion protection for the load balancer. - DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` -} - -// ToLoadBalancerUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "loadbalancer") -} - -// Update is an operation which modifies the attributes of the specified -// LoadBalancer. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { - b, err := opts.ToLoadBalancerUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(client.ServiceURL("loadbalancers", id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 202}, - }) - return -} - -// Delete will permanently delete a particular LoadBalancer based on its -// unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("loadbalancers", id), nil) - return -} - -// GetStatuses will return the status of a particular LoadBalancer. -func GetStatuses(client *golangsdk.ServiceClient, id string) (r GetStatusesResult) { - _, r.Err = client.Get(client.ServiceURL("loadbalancers", id, "statuses"), &r.Body, nil) - return -} diff --git a/openstack/elb/v3/members/Create.go b/openstack/elb/v3/members/Create.go new file mode 100644 index 000000000..e0259b76e --- /dev/null +++ b/openstack/elb/v3/members/Create.go @@ -0,0 +1,61 @@ +package members + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToMemberCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options' struct used in this package's CreateMember +// operation. +type CreateOpts struct { + // The IP address of the member to receive traffic from the load balancer. + Address string `json:"address" required:"true"` + + // The port on which to listen for client traffic. + ProtocolPort int `json:"protocol_port" required:"true"` + + // Name of the Member. + Name string `json:"name,omitempty"` + + // ProjectID is the UUID of the project who owns the Member. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // Specifies the weight of the backend server. + // + // Requests are routed to backend servers in the same backend server group based on their weights. + // + // If the weight is 0, the backend server will not accept new requests. + // + // This parameter is invalid when lb_algorithm is set to SOURCE_IP for the backend server group that contains the backend server. + Weight *int `json:"weight,omitempty"` + + // If you omit this parameter, LBaaS uses the vip_subnet_id parameter value + // for the subnet UUID. + SubnetID string `json:"subnet_cidr_id,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToMemberCreateMap builds a request body from CreateOptsBuilder. +func (opts CreateOpts) ToMemberCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "member") +} + +// Create will create and associate a Member with a particular Pool. +func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToMemberCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("pools", poolID, "members"), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{201}, + }) + return +} diff --git a/openstack/elb/v3/members/Delete.go b/openstack/elb/v3/members/Delete.go new file mode 100644 index 000000000..5003e36cc --- /dev/null +++ b/openstack/elb/v3/members/Delete.go @@ -0,0 +1,12 @@ +package members + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" +) + +// Delete will remove and disassociate a Member from a particular +// Pool. +func Delete(client *golangsdk.ServiceClient, poolID string, memberID string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("pools", poolID, "members", memberID), nil) + return +} diff --git a/openstack/elb/v3/members/Get.go b/openstack/elb/v3/members/Get.go new file mode 100644 index 000000000..48acf3c6a --- /dev/null +++ b/openstack/elb/v3/members/Get.go @@ -0,0 +1,9 @@ +package members + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Get retrieves a particular Pool Member based on its unique ID. +func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("pools", poolID, "members", memberID), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/members/List.go b/openstack/elb/v3/members/List.go new file mode 100644 index 000000000..e4a4a0794 --- /dev/null +++ b/openstack/elb/v3/members/List.go @@ -0,0 +1,61 @@ +package members + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToMembersListQuery() (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 Member attributes you want to see returned. SortKey allows +// you to sort by a particular Member attribute. SortDir sets the direction, +// and is either `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + Name string `q:"name"` + Weight int `q:"weight"` + AdminStateUp *bool `q:"admin_state_up"` + SubnetID string `q:"subnet_sidr_id"` + Address string `q:"address"` + ProtocolPort int `q:"protocol_port"` + ID string `q:"id"` + OperatingStatus string `q:"operating_status"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToMembersListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToMembersListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return "", err + } + return q.String(), err +} + +// List returns a Pager which allows you to iterate over a collection of +// members. It accepts a ListOptsBuilder, which allows you to filter and +// sort the returned collection for greater efficiency. +// +// Default policy settings return only those members that are owned by the +// tenant who submits the request, unless an admin user submits the request. +func List(client *golangsdk.ServiceClient, poolID string, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("pools", poolID, "members") + if opts != nil { + query, err := opts.ToMembersListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return MemberPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/members/Update.go b/openstack/elb/v3/members/Update.go new file mode 100644 index 000000000..2fdb6ccc6 --- /dev/null +++ b/openstack/elb/v3/members/Update.go @@ -0,0 +1,44 @@ +package members + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// List request. +type UpdateOptsBuilder interface { + ToMemberUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options' struct used in this package's Update +// operation. +type UpdateOpts struct { + // Name of the Member. + Name *string `json:"name,omitempty"` + + // A positive integer value that indicates the relative portion of traffic + // that this member should receive from the pool. For example, a member with + // a weight of 10 receives five times as much traffic as a member with a + // weight of 2. + Weight *int `json:"weight,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` +} + +// ToMemberUpdateMap builds a request body from UpdateOptsBuilder. +func (opts UpdateOpts) ToMemberUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "member") +} + +// Update allows Member to be updated. +func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToMemberUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("pools", poolID, "members", memberID), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201, 202}, + }) + return +} diff --git a/openstack/elb/v3/members/requests.go b/openstack/elb/v3/members/requests.go deleted file mode 100644 index 965e96326..000000000 --- a/openstack/elb/v3/members/requests.go +++ /dev/null @@ -1,173 +0,0 @@ -package members - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToMembersListQuery() (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 Member attributes you want to see returned. SortKey allows -// you to sort by a particular Member attribute. SortDir sets the direction, -// and is either `asc' or `desc'. Marker and Limit are used for pagination. -type ListOpts struct { - Name string `q:"name"` - Weight int `q:"weight"` - AdminStateUp *bool `q:"admin_state_up"` - SubnetID string `q:"subnet_sidr_id"` - Address string `q:"address"` - ProtocolPort int `q:"protocol_port"` - ID string `q:"id"` - OperatingStatus string `q:"operating_status"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` -} - -// ToMembersListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToMembersListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), err -} - -// List returns a Pager which allows you to iterate over a collection of -// members. It accepts a ListOptsBuilder, which allows you to filter and -// sort the returned collection for greater efficiency. -// -// Default policy settings return only those members that are owned by the -// tenant who submits the request, unless an admin user submits the request. -func List(client *golangsdk.ServiceClient, poolID string, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("pools", poolID, "members") - if opts != nil { - query, err := opts.ToMembersListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return MemberPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} - -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToMemberCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's CreateMember -// operation. -type CreateOpts struct { - // The IP address of the member to receive traffic from the load balancer. - Address string `json:"address" required:"true"` - - // The port on which to listen for client traffic. - ProtocolPort int `json:"protocol_port" required:"true"` - - // Name of the Member. - Name string `json:"name,omitempty"` - - // ProjectID is the UUID of the project who owns the Member. - // Only administrative users can specify a project UUID other than their own. - ProjectID string `json:"project_id,omitempty"` - - // Specifies the weight of the backend server. - // - // Requests are routed to backend servers in the same backend server group based on their weights. - // - // If the weight is 0, the backend server will not accept new requests. - // - // This parameter is invalid when lb_algorithm is set to SOURCE_IP for the backend server group that contains the backend server. - Weight *int `json:"weight,omitempty"` - - // If you omit this parameter, LBaaS uses the vip_subnet_id parameter value - // for the subnet UUID. - SubnetID string `json:"subnet_cidr_id,omitempty"` - - // The administrative state of the Pool. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` -} - -// ToMemberCreateMap builds a request body from CreateOptsBuilder. -func (opts CreateOpts) ToMemberCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "member") -} - -// Create will create and associate a Member with a particular Pool. -func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToMemberCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("pools", poolID, "members"), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{201}, - }) - return -} - -// Get retrieves a particular Pool Member based on its unique ID. -func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("pools", poolID, "members", memberID), &r.Body, nil) - return -} - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// List request. -type UpdateOptsBuilder interface { - ToMemberUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts is the common options' struct used in this package's Update -// operation. -type UpdateOpts struct { - // Name of the Member. - Name *string `json:"name,omitempty"` - - // A positive integer value that indicates the relative portion of traffic - // that this member should receive from the pool. For example, a member with - // a weight of 10 receives five times as much traffic as a member with a - // weight of 2. - Weight *int `json:"weight,omitempty"` - - // The administrative state of the Pool. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` -} - -// ToMemberUpdateMap builds a request body from UpdateOptsBuilder. -func (opts UpdateOpts) ToMemberUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "member") -} - -// Update allows Member to be updated. -func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToMemberUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(client.ServiceURL("pools", poolID, "members", memberID), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 201, 202}, - }) - return -} - -// Delete will remove and disassociate a Member from a particular -// Pool. -func Delete(client *golangsdk.ServiceClient, poolID string, memberID string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("pools", poolID, "members", memberID), nil) - return -} diff --git a/openstack/elb/v3/monitors/Create.go b/openstack/elb/v3/monitors/Create.go new file mode 100644 index 000000000..88dbe429e --- /dev/null +++ b/openstack/elb/v3/monitors/Create.go @@ -0,0 +1,89 @@ +package monitors + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// CreateOptsBuilder allows extensions to add additional parameters to the +// List request. +type CreateOptsBuilder interface { + ToMonitorCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options' struct used in this package's Create +// operation. +type CreateOpts struct { + // The Pool to Monitor. + PoolID string `json:"pool_id" required:"true"` + + // Specifies the health check protocol. + // + // The value can be TCP, UDP_CONNECT, HTTP, HTTPS, or PING. + Type Type `json:"type" required:"true"` + + // The time, in seconds, between sending probes to members. + Delay int `json:"delay" required:"true"` + + // Specifies the maximum time required for waiting for a response from the health check, in seconds. + // It is recommended that you set the value less than that of parameter delay. + Timeout int `json:"timeout" required:"true"` + + // Specifies the number of consecutive health checks when the health check result of a backend server changes + // from OFFLINE to ONLINE. The value ranges from 1 to 10. + MaxRetries int `json:"max_retries" required:"true"` + + // Specifies the number of consecutive health checks when the health check result of a backend server changes + // from ONLINE to OFFLINE. + MaxRetriesDown int `json:"max_retries_down,omitempty"` + + // Specifies the HTTP request path for the health check. + // The value must start with a slash (/), and the default value is /. This parameter is available only when type is set to HTTP. + URLPath string `json:"url_path,omitempty"` + + // Specifies the domain name that HTTP requests are sent to during the health check. + // This parameter is available only when type is set to HTTP. + DomainName string `json:"domain_name,omitempty"` + + // The HTTP method used for requests by the Monitor. If this attribute + // is not specified, it defaults to "GET". + HTTPMethod string `json:"http_method,omitempty"` + + // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify + // a single status like "200", or a range like "200-202". + ExpectedCodes string `json:"expected_codes,omitempty"` + + // ProjectID is the UUID of the project who owns the Monitor. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // The Name of the Monitor. + Name string `json:"name,omitempty"` + + // The administrative state of the Monitor. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // The Port of the Monitor. + MonitorPort int `json:"monitor_port,omitempty"` +} + +// ToMonitorCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToMonitorCreateMap() (map[string]interface{}, error) { + b, err := golangsdk.BuildRequestBody(opts, "healthmonitor") + if err != nil { + return nil, err + } + + return b, nil +} + +// Create is an operation which provisions a new Health Monitor. There are +// different types of Monitor you can provision: PING, TCP or HTTP(S). Below +// are examples of how to create each one. +func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToMonitorCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("healthmonitors"), b, &r.Body, nil) + return +} diff --git a/openstack/elb/v3/monitors/Delete.go b/openstack/elb/v3/monitors/Delete.go new file mode 100644 index 000000000..ef12edfb1 --- /dev/null +++ b/openstack/elb/v3/monitors/Delete.go @@ -0,0 +1,9 @@ +package monitors + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Delete will permanently delete a particular Monitor based on its unique ID. +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("healthmonitors", id), nil) + return +} diff --git a/openstack/elb/v3/monitors/Get.go b/openstack/elb/v3/monitors/Get.go new file mode 100644 index 000000000..dc624134b --- /dev/null +++ b/openstack/elb/v3/monitors/Get.go @@ -0,0 +1,9 @@ +package monitors + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Get retrieves a particular Health Monitor based on its unique ID. +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("healthmonitors", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/monitors/List.go b/openstack/elb/v3/monitors/List.go new file mode 100644 index 000000000..826f01563 --- /dev/null +++ b/openstack/elb/v3/monitors/List.go @@ -0,0 +1,67 @@ +package monitors + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToMonitorListQuery() (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 Monitor attributes you want to see returned. SortKey allows you to +// sort by a particular Monitor attribute. SortDir sets the direction, and is +// either `asc' or `desc'. Marker and Limit are used for pagination. +type ListOpts struct { + ID string `q:"id"` + Name string `q:"name"` + TenantID string `q:"tenant_id"` + ProjectID string `q:"project_id"` + PoolID string `q:"pool_id"` + Type string `q:"type"` + Delay int `q:"delay"` + Timeout int `q:"timeout"` + MaxRetries int `q:"max_retries"` + HTTPMethod string `q:"http_method"` + URLPath string `q:"url_path"` + ExpectedCodes string `q:"expected_codes"` + AdminStateUp *bool `q:"admin_state_up"` + Status string `q:"status"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToMonitorListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToMonitorListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return "", err + } + return q.String(), nil +} + +// List returns a Pager which allows you to iterate over a collection of +// health monitors. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +// +// Default policy settings return only those health monitors that are owned by the +// tenant who submits the request, unless an admin user submits the request. +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("healthmonitors") + if opts != nil { + query, err := opts.ToMonitorListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return MonitorPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/monitors/Update.go b/openstack/elb/v3/monitors/Update.go new file mode 100644 index 000000000..2d40e5bae --- /dev/null +++ b/openstack/elb/v3/monitors/Update.go @@ -0,0 +1,76 @@ +package monitors + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToMonitorUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options' struct used in this package's Update +// operation. +type UpdateOpts struct { + // The time, in seconds, between sending probes to members. + Delay int `json:"delay,omitempty"` + + // Maximum number of seconds for a Monitor to wait for a ping reply + // before it times out. The value must be less than the delay value. + Timeout int `json:"timeout,omitempty"` + + // Number of permissible ping failures before changing the member's + // status to INACTIVE. Must be a number between 1 and 10. + MaxRetries int `json:"max_retries,omitempty"` + + MaxRetriesDown int `json:"max_retries_down,omitempty"` + + // URI path that will be accessed if Monitor type is HTTP or HTTPS. + // Required for HTTP(S) types. + URLPath string `json:"url_path,omitempty"` + + // Domain Name. + DomainName string `json:"domain_name,omitempty"` + + // The HTTP method used for requests by the Monitor. If this attribute + // is not specified, it defaults to "GET". Required for HTTP(S) types. + HTTPMethod string `json:"http_method,omitempty"` + + // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify + // a single status like "200", or a range like "200-202". Required for HTTP(S) + // types. + ExpectedCodes string `json:"expected_codes,omitempty"` + + // The Name of the Monitor. + Name string `json:"name,omitempty"` + + // The administrative state of the Monitor. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // The Port of the Monitor. + MonitorPort int `json:"monitor_port,omitempty"` + + // The type of probe, which is PING, TCP, HTTP, or HTTPS, that is + // sent by the load balancer to verify the member state. + Type string `json:"type,omitempty"` +} + +// Update is an operation which modifies the attributes of the specified +// Monitor. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToMonitorUpdateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Put(client.ServiceURL("healthmonitors", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 202}, + }) + return +} + +// ToMonitorUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToMonitorUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "healthmonitor") +} diff --git a/openstack/elb/v3/monitors/requests.go b/openstack/elb/v3/monitors/requests.go index 72136002a..505a2f77e 100644 --- a/openstack/elb/v3/monitors/requests.go +++ b/openstack/elb/v3/monitors/requests.go @@ -1,71 +1,5 @@ package monitors -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToMonitorListQuery() (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 Monitor attributes you want to see returned. SortKey allows you to -// sort by a particular Monitor attribute. SortDir sets the direction, and is -// either `asc' or `desc'. Marker and Limit are used for pagination. -type ListOpts struct { - ID string `q:"id"` - Name string `q:"name"` - TenantID string `q:"tenant_id"` - ProjectID string `q:"project_id"` - PoolID string `q:"pool_id"` - Type string `q:"type"` - Delay int `q:"delay"` - Timeout int `q:"timeout"` - MaxRetries int `q:"max_retries"` - HTTPMethod string `q:"http_method"` - URLPath string `q:"url_path"` - ExpectedCodes string `q:"expected_codes"` - AdminStateUp *bool `q:"admin_state_up"` - Status string `q:"status"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` -} - -// ToMonitorListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToMonitorListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), nil -} - -// List returns a Pager which allows you to iterate over a collection of -// health monitors. It accepts a ListOpts struct, which allows you to filter and sort -// the returned collection for greater efficiency. -// -// Default policy settings return only those health monitors that are owned by the -// tenant who submits the request, unless an admin user submits the request. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("healthmonitors") - if opts != nil { - query, err := opts.ToMonitorListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return MonitorPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} - type Type string // Constants that represent approved monitoring types. @@ -75,174 +9,3 @@ const ( TypeHTTP Type = "HTTP" TypeHTTPS Type = "HTTPS" ) - -// CreateOptsBuilder allows extensions to add additional parameters to the -// List request. -type CreateOptsBuilder interface { - ToMonitorCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's Create -// operation. -type CreateOpts struct { - // The Pool to Monitor. - PoolID string `json:"pool_id" required:"true"` - - // Specifies the health check protocol. - // - // The value can be TCP, UDP_CONNECT, HTTP, HTTPS, or PING. - Type Type `json:"type" required:"true"` - - // The time, in seconds, between sending probes to members. - Delay int `json:"delay" required:"true"` - - // Specifies the maximum time required for waiting for a response from the health check, in seconds. - // It is recommended that you set the value less than that of parameter delay. - Timeout int `json:"timeout" required:"true"` - - // Specifies the number of consecutive health checks when the health check result of a backend server changes - // from OFFLINE to ONLINE. The value ranges from 1 to 10. - MaxRetries int `json:"max_retries" required:"true"` - - // Specifies the number of consecutive health checks when the health check result of a backend server changes - // from ONLINE to OFFLINE. - MaxRetriesDown int `json:"max_retries_down,omitempty"` - - // Specifies the HTTP request path for the health check. - // The value must start with a slash (/), and the default value is /. This parameter is available only when type is set to HTTP. - URLPath string `json:"url_path,omitempty"` - - // Specifies the domain name that HTTP requests are sent to during the health check. - // This parameter is available only when type is set to HTTP. - DomainName string `json:"domain_name,omitempty"` - - // The HTTP method used for requests by the Monitor. If this attribute - // is not specified, it defaults to "GET". - HTTPMethod string `json:"http_method,omitempty"` - - // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify - // a single status like "200", or a range like "200-202". - ExpectedCodes string `json:"expected_codes,omitempty"` - - // ProjectID is the UUID of the project who owns the Monitor. - // Only administrative users can specify a project UUID other than their own. - ProjectID string `json:"project_id,omitempty"` - - // The Name of the Monitor. - Name string `json:"name,omitempty"` - - // The administrative state of the Monitor. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The Port of the Monitor. - MonitorPort int `json:"monitor_port,omitempty"` -} - -// ToMonitorCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToMonitorCreateMap() (map[string]interface{}, error) { - b, err := golangsdk.BuildRequestBody(opts, "healthmonitor") - if err != nil { - return nil, err - } - - return b, nil -} - -// Create is an operation which provisions a new Health Monitor. There are -// different types of Monitor you can provision: PING, TCP or HTTP(S). Below -// are examples of how to create each one. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToMonitorCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("healthmonitors"), b, &r.Body, nil) - return -} - -// Get retrieves a particular Health Monitor based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("healthmonitors", id), &r.Body, nil) - return -} - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToMonitorUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts is the common options' struct used in this package's Update -// operation. -type UpdateOpts struct { - // The time, in seconds, between sending probes to members. - Delay int `json:"delay,omitempty"` - - // Maximum number of seconds for a Monitor to wait for a ping reply - // before it times out. The value must be less than the delay value. - Timeout int `json:"timeout,omitempty"` - - // Number of permissible ping failures before changing the member's - // status to INACTIVE. Must be a number between 1 and 10. - MaxRetries int `json:"max_retries,omitempty"` - - MaxRetriesDown int `json:"max_retries_down,omitempty"` - - // URI path that will be accessed if Monitor type is HTTP or HTTPS. - // Required for HTTP(S) types. - URLPath string `json:"url_path,omitempty"` - - // Domain Name. - DomainName string `json:"domain_name,omitempty"` - - // The HTTP method used for requests by the Monitor. If this attribute - // is not specified, it defaults to "GET". Required for HTTP(S) types. - HTTPMethod string `json:"http_method,omitempty"` - - // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify - // a single status like "200", or a range like "200-202". Required for HTTP(S) - // types. - ExpectedCodes string `json:"expected_codes,omitempty"` - - // The Name of the Monitor. - Name string `json:"name,omitempty"` - - // The administrative state of the Monitor. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The Port of the Monitor. - MonitorPort int `json:"monitor_port,omitempty"` - - // The type of probe, which is PING, TCP, HTTP, or HTTPS, that is - // sent by the load balancer to verify the member state. - Type string `json:"type,omitempty"` -} - -// ToMonitorUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToMonitorUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "healthmonitor") -} - -// Update is an operation which modifies the attributes of the specified -// Monitor. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToMonitorUpdateMap() - if err != nil { - r.Err = err - return - } - - _, r.Err = client.Put(client.ServiceURL("healthmonitors", id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 202}, - }) - return -} - -// Delete will permanently delete a particular Monitor based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("healthmonitors", id), nil) - return -} diff --git a/openstack/elb/v3/policies/Create.go b/openstack/elb/v3/policies/Create.go new file mode 100644 index 000000000..7c8f7ef83 --- /dev/null +++ b/openstack/elb/v3/policies/Create.go @@ -0,0 +1,89 @@ +package policies + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/rules" +) + +type CreateOpts struct { + // Specifies where requests will be forwarded. The value can be one of the following: + // + // REDIRECT_TO_POOL: Requests will be forwarded to another backend server group. + // REDIRECT_TO_LISTENER: Requests will be redirected to an HTTPS listener. + Action Action `json:"action" required:"true"` + + // Specifies the conditions contained in a forwarding rule. + // This parameter will take effect when enhance_l7policy_enable is set to true. + // If conditions is specified, key and value will not take effect, + // and the value of this parameter will contain all conditions configured for the forwarding rule. + // The keys in the list must be the same, whereas each value must be unique. + Conditions []rules.Condition `json:"conditions,omitempty"` + + // Provides supplementary information about the forwarding policy. + Description string `json:"description,omitempty"` + + // Specifies the configuration of the page that will be returned. + // This parameter will take effect when + FixedResponseConfig *FixedResponseOptions `json:"fixed_response_config,omitempty"` + + // Specifies the ID of the listener to which the forwarding policy is added. + ListenerID string `json:"listener_id" required:"true"` + + // Specifies the forwarding policy name. + Name string `json:"name,omitempty"` + + // Specifies the forwarding policy priority. The value cannot be updated. + Position int `json:"position,omitempty"` + + // Specifies the forwarding policy priority. The value cannot be updated. + Priority int `json:"priority,omitempty"` + + // Specifies the ID of the project where the forwarding policy is used. + ProjectID string `json:"project_id,omitempty"` + + // Specifies the ID of the listener to which requests are redirected. + // This parameter is mandatory when action is set to REDIRECT_TO_LISTENER. + RedirectListenerID string `json:"redirect_listener_id,omitempty"` + + // Specifies the ID of the backend server group that requests are forwarded to. + // + // This parameter is valid and mandatory only when action is set to REDIRECT_TO_POOL. + // The specified backend server group cannot be the default one associated with the listener, + // or any backend server group associated with the forwarding policies of other listeners. + RedirectPoolID string `json:"redirect_pool_id,omitempty"` + + // Specifies the URL to which requests are forwarded. + // + // Format: protocol://host:port/path?query + RedirectUrl string `json:"redirect_url,omitempty"` + + // Specifies the URL to which requests are forwarded. + // This parameter is mandatory when action is set to REDIRECT_TO_URL. + // It cannot be specified if the value of action is not REDIRECT_TO_URL. + RedirectUrlConfig *RedirectUrlOptions `json:"redirect_url_config,omitempty"` + + // Lists the forwarding rules in the forwarding policy. + // The list can contain a maximum of 10 forwarding rules (if conditions is specified, a condition is considered as a rule). + Rules []Rule `json:"rules,omitempty"` + + // Specifies the configuration of the backend server group that the requests are forwarded to. This parameter is valid only when action is set to REDIRECT_TO_POOL. + RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` +} + +type CreateOptsBuilder interface { + ToPolicyCreateMap() (map[string]interface{}, error) +} + +func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "l7policy") +} + +func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPolicyCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("l7policies"), b, &r.Body, nil) + return +} diff --git a/openstack/elb/v3/policies/Delete.go b/openstack/elb/v3/policies/Delete.go new file mode 100644 index 000000000..672d2a4b6 --- /dev/null +++ b/openstack/elb/v3/policies/Delete.go @@ -0,0 +1,8 @@ +package policies + +import "github.com/opentelekomcloud/gophertelekomcloud" + +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("l7policies", id), nil) + return +} diff --git a/openstack/elb/v3/policies/Get.go b/openstack/elb/v3/policies/Get.go new file mode 100644 index 000000000..9af14abba --- /dev/null +++ b/openstack/elb/v3/policies/Get.go @@ -0,0 +1,8 @@ +package policies + +import "github.com/opentelekomcloud/gophertelekomcloud" + +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("l7policies", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/policies/List.go b/openstack/elb/v3/policies/List.go new file mode 100644 index 000000000..4839b7690 --- /dev/null +++ b/openstack/elb/v3/policies/List.go @@ -0,0 +1,48 @@ +package policies + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +type ListOptsBuilder interface { + ToPolicyListQuery() (string, error) +} + +type ListOpts struct { + Marker string `q:"marker"` + Limit int `q:"limit"` + PageReverse bool `q:"page_reverse"` + ID []string `q:"id"` + Name []string `q:"name"` + Description []string `q:"description"` + ListenerID []string `q:"listener_id"` + Action []string `q:"action"` + RedirectPoolID []string `q:"redirect_pool_id"` + RedirectListenerID []string `q:"redirect_listener_id"` + ProvisioningStatus []string `q:"provisioning_status"` + DisplayAllRules bool `q:"display_all_rules"` +} + +func (opts ListOpts) ToPolicyListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return "", err + } + return q.String(), nil +} + +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("l7policies") + if opts != nil { + q, err := opts.ToPolicyListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += q + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return PolicyPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/policies/Update.go b/openstack/elb/v3/policies/Update.go new file mode 100644 index 000000000..231f4f8ca --- /dev/null +++ b/openstack/elb/v3/policies/Update.go @@ -0,0 +1,35 @@ +package policies + +import "github.com/opentelekomcloud/gophertelekomcloud" + +type UpdateOpts struct { + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + RedirectListenerID string `json:"redirect_listener_id,omitempty"` + RedirectPoolID string `json:"redirect_pool_id,omitempty"` + Rules []Rule `json:"rules,omitempty"` + RedirectUrlConfig *RedirectUrlOptions `json:"redirect_url_config,omitempty"` + FixedResponseConfig *FixedResponseOptions `json:"fixed_response_config,omitempty"` + Priority int `json:"priority,omitempty"` + RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` +} + +type UpdateOptsBuilder interface { + ToPolicyUpdateMap() (map[string]interface{}, error) +} + +func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "l7policy") +} + +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPolicyUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("l7policies", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} diff --git a/openstack/elb/v3/policies/requests.go b/openstack/elb/v3/policies/requests.go index 64da02c85..a4c408d02 100644 --- a/openstack/elb/v3/policies/requests.go +++ b/openstack/elb/v3/policies/requests.go @@ -1,9 +1,7 @@ package policies import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/rules" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type Action string @@ -94,170 +92,3 @@ type RedirectUrlOptions struct { // The value can be 301, 302, 303, 307, or 308. StatusCode string `json:"status_code" required:"true"` } - -type CreateOpts struct { - // Specifies where requests will be forwarded. The value can be one of the following: - // - // REDIRECT_TO_POOL: Requests will be forwarded to another backend server group. - // REDIRECT_TO_LISTENER: Requests will be redirected to an HTTPS listener. - Action Action `json:"action" required:"true"` - - // Specifies the conditions contained in a forwarding rule. - // This parameter will take effect when enhance_l7policy_enable is set to true. - // If conditions is specified, key and value will not take effect, - // and the value of this parameter will contain all conditions configured for the forwarding rule. - // The keys in the list must be the same, whereas each value must be unique. - Conditions []rules.Condition `json:"conditions,omitempty"` - - // Provides supplementary information about the forwarding policy. - Description string `json:"description,omitempty"` - - // Specifies the configuration of the page that will be returned. - // This parameter will take effect when - FixedResponseConfig *FixedResponseOptions `json:"fixed_response_config,omitempty"` - - // Specifies the ID of the listener to which the forwarding policy is added. - ListenerID string `json:"listener_id" required:"true"` - - // Specifies the forwarding policy name. - Name string `json:"name,omitempty"` - - // Specifies the forwarding policy priority. The value cannot be updated. - Position int `json:"position,omitempty"` - - // Specifies the forwarding policy priority. The value cannot be updated. - Priority int `json:"priority,omitempty"` - - // Specifies the ID of the project where the forwarding policy is used. - ProjectID string `json:"project_id,omitempty"` - - // Specifies the ID of the listener to which requests are redirected. - // This parameter is mandatory when action is set to REDIRECT_TO_LISTENER. - RedirectListenerID string `json:"redirect_listener_id,omitempty"` - - // Specifies the ID of the backend server group that requests are forwarded to. - // - // This parameter is valid and mandatory only when action is set to REDIRECT_TO_POOL. - // The specified backend server group cannot be the default one associated with the listener, - // or any backend server group associated with the forwarding policies of other listeners. - RedirectPoolID string `json:"redirect_pool_id,omitempty"` - - // Specifies the URL to which requests are forwarded. - // - // Format: protocol://host:port/path?query - RedirectUrl string `json:"redirect_url,omitempty"` - - // Specifies the URL to which requests are forwarded. - // This parameter is mandatory when action is set to REDIRECT_TO_URL. - // It cannot be specified if the value of action is not REDIRECT_TO_URL. - RedirectUrlConfig *RedirectUrlOptions `json:"redirect_url_config,omitempty"` - - // Lists the forwarding rules in the forwarding policy. - // The list can contain a maximum of 10 forwarding rules (if conditions is specified, a condition is considered as a rule). - Rules []Rule `json:"rules,omitempty"` - - // Specifies the configuration of the backend server group that the requests are forwarded to. This parameter is valid only when action is set to REDIRECT_TO_POOL. - RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` -} - -type CreateOptsBuilder interface { - ToPolicyCreateMap() (map[string]interface{}, error) -} - -func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "l7policy") -} - -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToPolicyCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("l7policies"), b, &r.Body, nil) - return -} - -type ListOptsBuilder interface { - ToPolicyListQuery() (string, error) -} - -type ListOpts struct { - Marker string `q:"marker"` - Limit int `q:"limit"` - PageReverse bool `q:"page_reverse"` - ID []string `q:"id"` - Name []string `q:"name"` - Description []string `q:"description"` - ListenerID []string `q:"listener_id"` - Action []string `q:"action"` - RedirectPoolID []string `q:"redirect_pool_id"` - RedirectListenerID []string `q:"redirect_listener_id"` - ProvisioningStatus []string `q:"provisioning_status"` - DisplayAllRules bool `q:"display_all_rules"` -} - -func (opts ListOpts) ToPolicyListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), nil -} - -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("l7policies") - if opts != nil { - q, err := opts.ToPolicyListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += q - } - - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return PolicyPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} - -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("l7policies", id), &r.Body, nil) - return -} - -type UpdateOpts struct { - Name *string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - RedirectListenerID string `json:"redirect_listener_id,omitempty"` - RedirectPoolID string `json:"redirect_pool_id,omitempty"` - Rules []Rule `json:"rules,omitempty"` - RedirectUrlConfig *RedirectUrlOptions `json:"redirect_url_config,omitempty"` - FixedResponseConfig *FixedResponseOptions `json:"fixed_response_config,omitempty"` - Priority int `json:"priority,omitempty"` - RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` -} - -type UpdateOptsBuilder interface { - ToPolicyUpdateMap() (map[string]interface{}, error) -} - -func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "l7policy") -} - -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToPolicyUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(client.ServiceURL("l7policies", id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 201}, - }) - return -} - -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("l7policies", id), nil) - return -} diff --git a/openstack/elb/v3/pools/Create.go b/openstack/elb/v3/pools/Create.go new file mode 100644 index 000000000..712b1e160 --- /dev/null +++ b/openstack/elb/v3/pools/Create.go @@ -0,0 +1,78 @@ +package pools + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// CreateOptsBuilder allows extensions to add additional parameters to the +// Create request. +type CreateOptsBuilder interface { + ToPoolCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options' struct used in this package's Create +// operation. +type CreateOpts struct { + // The algorithm used to distribute load between the members of the pool. + LBMethod string `json:"lb_algorithm" required:"true"` + + // The protocol used by the pool members, you can use either + // ProtocolTCP, ProtocolHTTP, or ProtocolHTTPS. + Protocol string `json:"protocol" required:"true"` + + // The Loadbalancer on which the members of the pool will be associated with. + // Note: one of LoadbalancerID or ListenerID must be provided. + LoadbalancerID string `json:"loadbalancer_id,omitempty"` + + // The Listener on which the members of the pool will be associated with. + // Note: one of LoadbalancerID or ListenerID must be provided. + ListenerID string `json:"listener_id,omitempty"` + + // ProjectID is the UUID of the project who owns the Pool. + // Only administrative users can specify a project UUID other than their own. + ProjectID string `json:"project_id,omitempty"` + + // Name of the pool. + Name string `json:"name,omitempty"` + + // Human-readable description for the pool. + Description string `json:"description,omitempty"` + + // Persistence is the session persistence of the pool. + // Omit this field to prevent session persistence. + Persistence *SessionPersistence `json:"session_persistence,omitempty"` + + SlowStart *SlowStart `json:"slow_start,omitempty"` + + // The administrative state of the Pool. A valid value is true (UP) + // or false (DOWN). + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // Specifies whether to enable deletion protection for the pool. + DeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` + + // Specifies the ID of the VPC where the backend server group works. + VpcId string `json:"vpc_id,omitempty"` + + // Specifies the type of the backend server group. + // Values: + // instance: Any type of backend servers can be added. vpc_id is mandatory. + // ip: Only cross-VPC backend servers can be added. vpc_id cannot be specified. + // "": Any type of backend servers can be added. + Type string `json:"type,omitempty"` +} + +// ToPoolCreateMap builds a request body from CreateOpts. +func (opts CreateOpts) ToPoolCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "pool") +} + +// Create accepts a CreateOpts struct and uses the values to create a new +// load balancer pool. +func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToPoolCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("pools"), b, &r.Body, nil) + return +} diff --git a/openstack/elb/v3/pools/Delete.go b/openstack/elb/v3/pools/Delete.go new file mode 100644 index 000000000..572f6151c --- /dev/null +++ b/openstack/elb/v3/pools/Delete.go @@ -0,0 +1,9 @@ +package pools + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Delete will permanently delete a particular pool based on its unique ID. +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("pools", id), nil) + return +} diff --git a/openstack/elb/v3/pools/Get.go b/openstack/elb/v3/pools/Get.go new file mode 100644 index 000000000..1d5a7709a --- /dev/null +++ b/openstack/elb/v3/pools/Get.go @@ -0,0 +1,9 @@ +package pools + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// Get retrieves a particular pool based on its unique ID. +func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("pools", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/pools/List.go b/openstack/elb/v3/pools/List.go new file mode 100644 index 000000000..ad88caa8f --- /dev/null +++ b/openstack/elb/v3/pools/List.go @@ -0,0 +1,61 @@ +package pools + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +// ListOptsBuilder allows extensions to add additional parameters to the +// List request. +type ListOptsBuilder interface { + ToPoolListQuery() (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 Pool attributes you want to see returned. SortKey allows you to +// sort by a particular Pool attribute. SortDir sets the direction, and is +// either `asc` or `desc`. Marker and Limit are used for pagination. +type ListOpts struct { + Description []string `q:"description"` + HealthMonitorID []string `q:"healthmonitor_id"` + LBMethod []string `q:"lb_algorithm"` + Protocol []string `q:"protocol"` + AdminStateUp *bool `q:"admin_state_up"` + Name []string `q:"name"` + ID []string `q:"id"` + LoadbalancerID []string `q:"loadbalancer_id"` + Limit int `q:"limit"` + Marker string `q:"marker"` + SortKey string `q:"sort_key"` + SortDir string `q:"sort_dir"` +} + +// ToPoolListQuery formats a ListOpts into a query string. +func (opts ListOpts) ToPoolListQuery() (string, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return "", err + } + return q.String(), nil +} + +// List returns a Pager which allows you to iterate over a collection of +// pools. It accepts a ListOpts struct, which allows you to filter and sort +// the returned collection for greater efficiency. +// +// Default policy settings return only those pools that are owned by the +// tenant who submits the request, unless an admin user submits the request. +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("pools") + if opts != nil { + query, err := opts.ToPoolListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += query + } + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return PoolPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/pools/Update.go b/openstack/elb/v3/pools/Update.go new file mode 100644 index 000000000..532b5d27d --- /dev/null +++ b/openstack/elb/v3/pools/Update.go @@ -0,0 +1,66 @@ +package pools + +import "github.com/opentelekomcloud/gophertelekomcloud" + +// UpdateOptsBuilder allows extensions to add additional parameters to the +// Update request. +type UpdateOptsBuilder interface { + ToPoolUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options' struct used in this package's Update +// operation. +type UpdateOpts struct { + // Name of the pool. + Name *string `json:"name,omitempty"` + + // Human-readable description for the pool. + Description *string `json:"description,omitempty"` + + // The algorithm used to distribute load between the members of the pool. The + // current specification supports LBMethodRoundRobin, LBMethodLeastConnections + // and LBMethodSourceIp as valid values for this attribute. + LBMethod string `json:"lb_algorithm,omitempty"` + + // Specifies whether to enable sticky sessions. + Persistence *SessionPersistence `json:"session_persistence,omitempty"` + + // The administrative state of the Pool. The value can only be updated to true. + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + + // Specifies whether to enable slow start. + // This parameter is unsupported. Please do not use it. + SlowStart *SlowStart `json:"slow_start,omitempty"` + + // Specifies whether to enable deletion protection for the load balancer. + DeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` + + // Specifies the ID of the VPC where the backend server group works. + VpcId string `json:"vpc_id,omitempty"` + + // Specifies the type of the backend server group. + // Values: + // instance: Any type of backend servers can be added. vpc_id is mandatory. + // ip: Only cross-VPC backend servers can be added. vpc_id cannot be specified. + // "": Any type of backend servers can be added. + Type string `json:"type,omitempty"` +} + +// ToPoolUpdateMap builds a request body from UpdateOpts. +func (opts UpdateOpts) ToPoolUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "pool") +} + +// Update allows pools to be updated. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToPoolUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("pools", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + return +} diff --git a/openstack/elb/v3/pools/requests.go b/openstack/elb/v3/pools/requests.go index 7f1381ad7..fab4ab2cd 100644 --- a/openstack/elb/v3/pools/requests.go +++ b/openstack/elb/v3/pools/requests.go @@ -1,123 +1,5 @@ package pools -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToPoolListQuery() (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 Pool attributes you want to see returned. SortKey allows you to -// sort by a particular Pool attribute. SortDir sets the direction, and is -// either `asc` or `desc`. Marker and Limit are used for pagination. -type ListOpts struct { - Description []string `q:"description"` - HealthMonitorID []string `q:"healthmonitor_id"` - LBMethod []string `q:"lb_algorithm"` - Protocol []string `q:"protocol"` - AdminStateUp *bool `q:"admin_state_up"` - Name []string `q:"name"` - ID []string `q:"id"` - LoadbalancerID []string `q:"loadbalancer_id"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` -} - -// ToPoolListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToPoolListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), nil -} - -// List returns a Pager which allows you to iterate over a collection of -// pools. It accepts a ListOpts struct, which allows you to filter and sort -// the returned collection for greater efficiency. -// -// Default policy settings return only those pools that are owned by the -// tenant who submits the request, unless an admin user submits the request. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("pools") - if opts != nil { - query, err := opts.ToPoolListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return PoolPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} - -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToPoolCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's Create -// operation. -type CreateOpts struct { - // The algorithm used to distribute load between the members of the pool. - LBMethod string `json:"lb_algorithm" required:"true"` - - // The protocol used by the pool members, you can use either - // ProtocolTCP, ProtocolHTTP, or ProtocolHTTPS. - Protocol string `json:"protocol" required:"true"` - - // The Loadbalancer on which the members of the pool will be associated with. - // Note: one of LoadbalancerID or ListenerID must be provided. - LoadbalancerID string `json:"loadbalancer_id,omitempty"` - - // The Listener on which the members of the pool will be associated with. - // Note: one of LoadbalancerID or ListenerID must be provided. - ListenerID string `json:"listener_id,omitempty"` - - // ProjectID is the UUID of the project who owns the Pool. - // Only administrative users can specify a project UUID other than their own. - ProjectID string `json:"project_id,omitempty"` - - // Name of the pool. - Name string `json:"name,omitempty"` - - // Human-readable description for the pool. - Description string `json:"description,omitempty"` - - // Persistence is the session persistence of the pool. - // Omit this field to prevent session persistence. - Persistence *SessionPersistence `json:"session_persistence,omitempty"` - - SlowStart *SlowStart `json:"slow_start,omitempty"` - - // The administrative state of the Pool. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // Specifies whether to enable deletion protection for the pool. - DeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` - - // Specifies the ID of the VPC where the backend server group works. - VpcId string `json:"vpc_id,omitempty"` - - // Specifies the type of the backend server group. - // Values: - // instance: Any type of backend servers can be added. vpc_id is mandatory. - // ip: Only cross-VPC backend servers can be added. vpc_id cannot be specified. - // "": Any type of backend servers can be added. - Type string `json:"type,omitempty"` -} - // SessionPersistence represents the session persistence feature of the load // balancing service. It attempts to force connections or requests in the same // session to be processed by the same member as long as it is active. Three @@ -140,95 +22,3 @@ type SlowStart struct { // Specifies the slow start Duration, in seconds. Duration int `json:"duration" required:"true"` } - -// ToPoolCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToPoolCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "pool") -} - -// Create accepts a CreateOpts struct and uses the values to create a new -// load balancer pool. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToPoolCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("pools"), b, &r.Body, nil) - return -} - -// Get retrieves a particular pool based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("pools", id), &r.Body, nil) - return -} - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToPoolUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts is the common options' struct used in this package's Update -// operation. -type UpdateOpts struct { - // Name of the pool. - Name *string `json:"name,omitempty"` - - // Human-readable description for the pool. - Description *string `json:"description,omitempty"` - - // The algorithm used to distribute load between the members of the pool. The - // current specification supports LBMethodRoundRobin, LBMethodLeastConnections - // and LBMethodSourceIp as valid values for this attribute. - LBMethod string `json:"lb_algorithm,omitempty"` - - // Specifies whether to enable sticky sessions. - Persistence *SessionPersistence `json:"session_persistence,omitempty"` - - // The administrative state of the Pool. The value can only be updated to true. - // This parameter is unsupported. Please do not use it. - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // Specifies whether to enable slow start. - // This parameter is unsupported. Please do not use it. - SlowStart *SlowStart `json:"slow_start,omitempty"` - - // Specifies whether to enable deletion protection for the load balancer. - DeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` - - // Specifies the ID of the VPC where the backend server group works. - VpcId string `json:"vpc_id,omitempty"` - - // Specifies the type of the backend server group. - // Values: - // instance: Any type of backend servers can be added. vpc_id is mandatory. - // ip: Only cross-VPC backend servers can be added. vpc_id cannot be specified. - // "": Any type of backend servers can be added. - Type string `json:"type,omitempty"` -} - -// ToPoolUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToPoolUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "pool") -} - -// Update allows pools to be updated. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToPoolUpdateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(client.ServiceURL("pools", id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - -// Delete will permanently delete a particular pool based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("pools", id), nil) - return -} diff --git a/openstack/elb/v3/rules/Create.go b/openstack/elb/v3/rules/Create.go new file mode 100644 index 000000000..1d099d212 --- /dev/null +++ b/openstack/elb/v3/rules/Create.go @@ -0,0 +1,55 @@ +package rules + +import "github.com/opentelekomcloud/gophertelekomcloud" + +type CreateOpts struct { + // Specifies the conditions contained in a forwarding rule. + // This parameter will take effect when enhance_l7policy_enable is set to true. + // If conditions is specified, key and value will not take effect, + // and the value of this parameter will contain all conditions configured for the forwarding rule. + // The keys in the list must be the same, whereas each value must be unique. + Conditions []Condition `json:"conditions,omitempty"` + // Specifies the match content. The value can be one of the following: + // + // HOST_NAME: A domain name will be used for matching. + // PATH: A URL will be used for matching. + // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. + Type RuleType `json:"type" required:"true"` + + // Specifies how requests are matched and forwarded. + // + // If type is set to HOST_NAME, this parameter can only be set to EQUAL_TO. Asterisks (*) can be used as wildcard characters. + // If type is set to PATH, this parameter can be set to REGEX, STARTS_WITH, or EQUAL_TO. + CompareType CompareType `json:"compare_type" required:"true"` + + // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. + // + // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must + // start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost + // label of the domain name. + // + // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and + // can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + Value string `json:"value" required:"true"` + + // Specifies the project ID. + ProjectID string `json:"project_id,omitempty"` +} + +type CreateOptsBuilder interface { + ToRuleCreateMap() (map[string]interface{}, error) +} + +func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "rule") +} + +func Create(client *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToRuleCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(client.ServiceURL("l7policies", policyID, "rules"), b, &r.Body, nil) + return +} diff --git a/openstack/elb/v3/rules/Delete.go b/openstack/elb/v3/rules/Delete.go new file mode 100644 index 000000000..8018c553f --- /dev/null +++ b/openstack/elb/v3/rules/Delete.go @@ -0,0 +1,8 @@ +package rules + +import "github.com/opentelekomcloud/gophertelekomcloud" + +func Delete(client *golangsdk.ServiceClient, policyID, id string) (r DeleteResult) { + _, r.Err = client.Delete(client.ServiceURL("l7policies", policyID, "rules", id), nil) + return +} diff --git a/openstack/elb/v3/rules/Get.go b/openstack/elb/v3/rules/Get.go new file mode 100644 index 000000000..624cc004e --- /dev/null +++ b/openstack/elb/v3/rules/Get.go @@ -0,0 +1,8 @@ +package rules + +import "github.com/opentelekomcloud/gophertelekomcloud" + +func Get(client *golangsdk.ServiceClient, policyID, id string) (r GetResult) { + _, r.Err = client.Get(client.ServiceURL("l7policies", policyID, "rules", id), &r.Body, nil) + return +} diff --git a/openstack/elb/v3/rules/List.go b/openstack/elb/v3/rules/List.go new file mode 100644 index 000000000..5bebfc0c5 --- /dev/null +++ b/openstack/elb/v3/rules/List.go @@ -0,0 +1,37 @@ +package rules + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" +) + +type ListOptsBuilder interface { + ToRuleListQuery() (string, error) +} + +type ListOpts struct { + ID []string `q:"id"` + CompareType []CompareType `q:"compare_type"` + Value []string `q:"value"` + Type []RuleType `q:"type"` + + Limit int `q:"limit"` + Marker string `q:"marker"` + PageReverse bool `q:"page_reverse"` +} + +func List(client *golangsdk.ServiceClient, policyID string, opts ListOptsBuilder) pagination.Pager { + url := client.ServiceURL("l7policies", policyID, "rules") + + if opts != nil { + q, err := opts.ToRuleListQuery() + if err != nil { + return pagination.Pager{Err: err} + } + url += q + } + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return RulePage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} diff --git a/openstack/elb/v3/rules/Update.go b/openstack/elb/v3/rules/Update.go new file mode 100644 index 000000000..0f8663cd8 --- /dev/null +++ b/openstack/elb/v3/rules/Update.go @@ -0,0 +1,29 @@ +package rules + +import "github.com/opentelekomcloud/gophertelekomcloud" + +type UpdateOptsBuilder interface { + ToUpdateRuleMap() (map[string]interface{}, error) +} + +type UpdateOpts struct { + CompareType CompareType `json:"compare_type,omitempty"` + Value string `json:"value,omitempty"` + Conditions []Condition `json:"conditions,omitempty"` +} + +func (opts UpdateOpts) ToUpdateRuleMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "rule") +} + +func Update(client *golangsdk.ServiceClient, policyID, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToUpdateRuleMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(client.ServiceURL("l7policies", policyID, "rules", id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} diff --git a/openstack/elb/v3/rules/requests.go b/openstack/elb/v3/rules/requests.go index 6ae92a76c..7319e4c79 100644 --- a/openstack/elb/v3/rules/requests.go +++ b/openstack/elb/v3/rules/requests.go @@ -1,10 +1,5 @@ package rules -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - type RuleType string type CompareType string @@ -24,122 +19,3 @@ type Condition struct { // Specifies the value of the match item. Value string `json:"value" required:"true"` } - -type CreateOpts struct { - // Specifies the conditions contained in a forwarding rule. - // This parameter will take effect when enhance_l7policy_enable is set to true. - // If conditions is specified, key and value will not take effect, - // and the value of this parameter will contain all conditions configured for the forwarding rule. - // The keys in the list must be the same, whereas each value must be unique. - Conditions []Condition `json:"conditions,omitempty"` - // Specifies the match content. The value can be one of the following: - // - // HOST_NAME: A domain name will be used for matching. - // PATH: A URL will be used for matching. - // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. - Type RuleType `json:"type" required:"true"` - - // Specifies how requests are matched and forwarded. - // - // If type is set to HOST_NAME, this parameter can only be set to EQUAL_TO. Asterisks (*) can be used as wildcard characters. - // If type is set to PATH, this parameter can be set to REGEX, STARTS_WITH, or EQUAL_TO. - CompareType CompareType `json:"compare_type" required:"true"` - - // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. - // - // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must - // start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost - // label of the domain name. - // - // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and - // can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} - Value string `json:"value" required:"true"` - - // Specifies the project ID. - ProjectID string `json:"project_id,omitempty"` -} - -type CreateOptsBuilder interface { - ToRuleCreateMap() (map[string]interface{}, error) -} - -func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "rule") -} - -func Create(client *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToRuleCreateMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Post(client.ServiceURL("l7policies", policyID, "rules"), b, &r.Body, nil) - return -} - -func Get(client *golangsdk.ServiceClient, policyID, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("l7policies", policyID, "rules", id), &r.Body, nil) - return -} - -type UpdateOptsBuilder interface { - ToUpdateRuleMap() (map[string]interface{}, error) -} - -type UpdateOpts struct { - CompareType CompareType `json:"compare_type,omitempty"` - Value string `json:"value,omitempty"` - Conditions []Condition `json:"conditions,omitempty"` -} - -func (opts UpdateOpts) ToUpdateRuleMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "rule") -} - -func Update(client *golangsdk.ServiceClient, policyID, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToUpdateRuleMap() - if err != nil { - r.Err = err - return - } - _, r.Err = client.Put(client.ServiceURL("l7policies", policyID, "rules", id), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 201}, - }) - return -} - -type ListOptsBuilder interface { - ToRuleListQuery() (string, error) -} - -type ListOpts struct { - ID []string `q:"id"` - CompareType []CompareType `q:"compare_type"` - Value []string `q:"value"` - Type []RuleType `q:"type"` - - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` -} - -func List(client *golangsdk.ServiceClient, policyID string, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("l7policies", policyID, "rules") - - if opts != nil { - q, err := opts.ToRuleListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += q - } - - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return RulePage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) -} - -func Delete(client *golangsdk.ServiceClient, policyID, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("l7policies", policyID, "rules", id), nil) - return -} From 0e367a6115ada7209d3951df9ea998614c1de746 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 02:08:04 +0200 Subject: [PATCH 03/54] CreateOpts --- openstack/elb/v3/certificates/Create.go | 55 ++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/openstack/elb/v3/certificates/Create.go b/openstack/elb/v3/certificates/Create.go index ad1371527..f58c910b6 100644 --- a/openstack/elb/v3/certificates/Create.go +++ b/openstack/elb/v3/certificates/Create.go @@ -10,15 +10,56 @@ type CreateOptsBuilder interface { ToCertificateCreateMap() (map[string]interface{}, error) } -// CreateOpts is the common options' struct used in this package's Create -// operation. type CreateOpts struct { - Name string `json:"name,omitempty"` + // Specifies the certificate name. Only letters, digits, underscores, and hyphens are allowed. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Provides supplementary information about the certificate. + // + // Minimum: 0 + // Maximum: 255 Description string `json:"description,omitempty"` - Type string `json:"type,omitempty"` - Domain string `json:"domain,omitempty"` - PrivateKey string `json:"private_key,omitempty"` + // Specifies the certificate type. + // + // The value can be server or client. server indicates server certificates, and client indicates CA certificates. The default value is server. + Type string `json:"type,omitempty"` + // Specifies the domain names used by the server certificate. + // + // This parameter will take effect only when type is set to server, and its default value is "". + // + // This parameter will not take effect even if it is passed and type is set to client. However, domain names will still be verified. + // + // Note: + // + // The value can contain 0 to 1024 characters and consists of multiple common domain names or wildcard domain names separated by commas. A maximum of 30 domain names are allowed. + // + // A common domain name consists of several labels separated by periods (.). Each label can contain a maximum of 63 characters, including letters, digits, and hyphens (-), and must start and end with a letter or digit. Example: www.test.com + // + // A wildcard domain name is a domain name starts with an asterisk (*). Example: *.test.com + Domain string `json:"domain,omitempty"` + // + // Specifies the private key of the server certificate. The value must be PEM encoded. + // + // This parameter will be ignored if type is set to client. A CA server can still be created and used normally. This parameter will be left blank even if you enter a private key that is not PEM encoded. + // + // This parameter is valid and mandatory only when type is set to server. If you enter an invalid private key, an error is returned. + PrivateKey string `json:"private_key,omitempty"` + // Specifies the private key of the certificate. The value must be PEM encoded. Certificate string `json:"certificate" required:"true"` + // Specifies the administrative status of the certificate. + // + // This parameter is unsupported. Please do not use it. + // + // Default: true + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies the ID of the project where the certificate is used. + // + // Minimum: 1 + // Maximum: 32 + ProjectId string `json:"project_id,omitempty"` } // ToCertificateCreateMap casts a CreateOpts struct to a map. @@ -39,6 +80,8 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe r.Err = err return } + + // POST /v3/{project_id}/elb/certificates _, r.Err = client.Post(client.ServiceURL("certificates"), b, &r.Body, &golangsdk.RequestOpts{ OkCodes: []int{200, 201}, }) From eb224cdd28b805fe3c56d0dd5b891930bd3d6766 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:33:11 +0200 Subject: [PATCH 04/54] Create --- openstack/elb/v3/certificates/Create.go | 40 +++++++++++++----------- openstack/elb/v3/certificates/Get.go | 27 ++++++++++++++++ openstack/elb/v3/certificates/results.go | 15 --------- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/openstack/elb/v3/certificates/Create.go b/openstack/elb/v3/certificates/Create.go index f58c910b6..99a6bf501 100644 --- a/openstack/elb/v3/certificates/Create.go +++ b/openstack/elb/v3/certificates/Create.go @@ -1,14 +1,12 @@ package certificates -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "net/http" -// CreateOptsBuilder is the interface options structs have to satisfy in order -// to be used in the main Create operation in this package. Since many -// extensions decorate or modify the common logic, it is useful for them to -// satisfy a basic interface in order for them to be used. -type CreateOptsBuilder interface { - ToCertificateCreateMap() (map[string]interface{}, error) -} + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) type CreateOpts struct { // Specifies the certificate name. Only letters, digits, underscores, and hyphens are allowed. @@ -62,11 +60,6 @@ type CreateOpts struct { ProjectId string `json:"project_id,omitempty"` } -// ToCertificateCreateMap casts a CreateOpts struct to a map. -func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "certificate") -} - // Create is an operation which provisions a new loadbalancer based on the // configuration defined in the CreateOpts struct. Once the request is // validated and progress has started on the provisioning process, a @@ -74,16 +67,25 @@ func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) // // Users with an admin role can create loadbalancers on behalf of other tenants by // specifying a TenantID attribute different from their own. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToCertificateCreateMap() +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Certificate, error) { + b, err := build.RequestBody(opts, "certificate") if err != nil { - r.Err = err - return + return nil, err } // POST /v3/{project_id}/elb/certificates - _, r.Err = client.Post(client.ServiceURL("certificates"), b, &r.Body, &golangsdk.RequestOpts{ + raw, err := client.Post(client.ServiceURL("certificates"), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 201}, }) - return + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*Certificate, error) { + if err != nil { + return nil, err + } + + var res Certificate + err = extract.IntoStructPtr(raw.Body, &res, "certificate") + return &res, nil } diff --git a/openstack/elb/v3/certificates/Get.go b/openstack/elb/v3/certificates/Get.go index 67cea98e3..bd8ac746e 100644 --- a/openstack/elb/v3/certificates/Get.go +++ b/openstack/elb/v3/certificates/Get.go @@ -9,3 +9,30 @@ func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { _, r.Err = client.Get(client.ServiceURL("certificates", id), &r.Body, nil) return } + +type Certificate struct { + // + ID string `json:"id"` + // + ProjectID string `json:"project_id"` + // + Name string `json:"name"` + // + Description string `json:"description"` + // + Type string `json:"type"` + // + Domain string `json:"domain"` + // + PrivateKey string `json:"private_key"` + // + Certificate string `json:"certificate"` + // + AdminStateUp bool `json:"admin_state_up"` + // + CreatedAt string `json:"created_at"` + // + UpdatedAt string `json:"updated_at"` + // + ExpireTime string `json:"expire_time"` +} diff --git a/openstack/elb/v3/certificates/results.go b/openstack/elb/v3/certificates/results.go index cf5f75e35..94a08cab7 100644 --- a/openstack/elb/v3/certificates/results.go +++ b/openstack/elb/v3/certificates/results.go @@ -5,21 +5,6 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -type Certificate struct { - ID string `json:"id"` - ProjectID string `json:"project_id"` - Name string `json:"name"` - Description string `json:"description"` - Type string `json:"type"` - Domain string `json:"domain"` - PrivateKey string `json:"private_key"` - Certificate string `json:"certificate"` - AdminStateUp bool `json:"admin_state_up"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` - ExpireTime string `json:"expire_time"` -} - // CertificatePage is the page returned by a pager when traversing over a // collection of certificates. type CertificatePage struct { From 38eb8314e19bc5775b23bec0115093bbf83855dd Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:01:53 +0200 Subject: [PATCH 05/54] Get --- openstack/elb/v3/certificates/Get.go | 52 ++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/openstack/elb/v3/certificates/Get.go b/openstack/elb/v3/certificates/Get.go index bd8ac746e..e4bd1a5ee 100644 --- a/openstack/elb/v3/certificates/Get.go +++ b/openstack/elb/v3/certificates/Get.go @@ -4,35 +4,65 @@ import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" ) -// Get retrieves a particular Loadbalancer based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("certificates", id), &r.Body, nil) - return +// Get retrieves a particular Load balancer based on its unique ID. +func Get(client *golangsdk.ServiceClient, id string) (*Certificate, error) { + raw, err := client.Get(client.ServiceURL("certificates", id), nil, nil) + return extra(err, raw) } type Certificate struct { - // + // Specifies a certificate ID ID string `json:"id"` - // + // Specifies the project ID. ProjectID string `json:"project_id"` + // Specifies the certificate name. + // + // Minimum: 1 // + // Maximum: 255 Name string `json:"name"` + // Provides supplementary information about the certificate. // - Description string `json:"description"` + // Minimum: 1 // + // Maximum: 255 + Description string `json:"description"` + // Specifies the certificate type. The value can be server or client. server indicates server certificates, and client indicates CA certificates. The default value is server. Type string `json:"type"` + // Specifies the domain names used by the server certificate. + // + // This parameter will take effect only when type is set to server, and its default value is "". + // + // This parameter will not take effect even if it is passed and type is set to client. However, domain names will still be verified. + // + // Note: + // + // The value can contain 0 to 1024 characters and consists of multiple common domain names or wildcard domain names separated by commas. A maximum of 30 domain names are allowed. // + // A common domain name consists of several labels separated by periods (.). Each label can contain a maximum of 63 characters, including letters, digits, and hyphens (-), and must start and end with a letter or digit. Example: www.test.com + // + // A wildcard domain name is a domain name starts with an asterisk (*). Example: *.test.com + // + // Minimum: 1 + // + // Maximum: 1024 Domain string `json:"domain"` + // Specifies the private key of the server certificate. The value must be PEM encoded. // - PrivateKey string `json:"private_key"` + // This parameter will be ignored if type is set to client. A CA server can still be created and used normally. This parameter will be left blank even if you enter a private key that is not PEM encoded. // + // This parameter is valid and mandatory only when type is set to server. If you enter an invalid private key, an error is returned. + PrivateKey string `json:"private_key"` + // Specifies the private key of the certificate. The value must be PEM encoded. Certificate string `json:"certificate"` + // Specifies the administrative status of the certificate. // + // This parameter is unsupported. Please do not use it. AdminStateUp bool `json:"admin_state_up"` - // + // Specifies the time when the certificate was created. CreatedAt string `json:"created_at"` - // + // Specifies the time when the certificate was updated. UpdatedAt string `json:"updated_at"` - // + // Specifies the time when the certificate expires. ExpireTime string `json:"expire_time"` } From 40727def8152478dccd9639435efb799c1717813 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:03:38 +0200 Subject: [PATCH 06/54] Delete --- openstack/elb/v3/certificates/Delete.go | 5 +++-- openstack/elb/v3/certificates/Get.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/openstack/elb/v3/certificates/Delete.go b/openstack/elb/v3/certificates/Delete.go index 2654a3048..e30c917fc 100644 --- a/openstack/elb/v3/certificates/Delete.go +++ b/openstack/elb/v3/certificates/Delete.go @@ -3,7 +3,8 @@ package certificates import "github.com/opentelekomcloud/gophertelekomcloud" // Delete will permanently delete a particular Certificate based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("certificates", id), nil) +func Delete(client *golangsdk.ServiceClient, id string) (err error) { + // DELETE /v3/{project_id}/elb/certificates/{certificate_id} + _, err = client.Delete(client.ServiceURL("certificates", id), nil) return } diff --git a/openstack/elb/v3/certificates/Get.go b/openstack/elb/v3/certificates/Get.go index e4bd1a5ee..784b4a275 100644 --- a/openstack/elb/v3/certificates/Get.go +++ b/openstack/elb/v3/certificates/Get.go @@ -6,6 +6,7 @@ import ( // Get retrieves a particular Load balancer based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (*Certificate, error) { + // GET /v3/{project_id}/elb/certificates/{certificate_id} raw, err := client.Get(client.ServiceURL("certificates", id), nil, nil) return extra(err, raw) } From 56484908b488cc6d7be9b1d87122f6b86d184b66 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:49:02 +0200 Subject: [PATCH 07/54] List --- openstack/elb/v3/certificates/List.go | 91 ++++++++++++++++-------- openstack/elb/v3/certificates/results.go | 19 ----- 2 files changed, 63 insertions(+), 47 deletions(-) diff --git a/openstack/elb/v3/certificates/List.go b/openstack/elb/v3/certificates/List.go index ba6671f51..70700aae6 100644 --- a/openstack/elb/v3/certificates/List.go +++ b/openstack/elb/v3/certificates/List.go @@ -2,43 +2,78 @@ package certificates import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToCertificateListQuery() (string, error) -} - type ListOpts struct { - ID []string `q:"id"` - Name []string `q:"name"` + // Specifies a certificate ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + ID []string `q:"id"` + // Specifies the certificate name. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Provides supplementary information about the certificate. + // + // Multiple descriptions can be queried in the format of description=xxx&description=xxx. Description []string `q:"description"` - Type []string `q:"type"` - Domain []string `q:"domain"` + // Specifies the certificate type. + // + // The value can be server or client. server indicates server certificates, and client indicates CA certificates. + // + // Multiple types can be queried in the format of type=xxx&type=xxx. + Type []string `q:"type"` + // Specifies the domain names used by the server certificate. This parameter is available only when type is set to server. + // + // Multiple domain names can be queried in the format of domain=xxx&domain=xxx. + Domain []string `q:"domain"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + Limit int `q:"limit"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the page direction. The value can be true or false, and the default value is false. The last page in the list requested with page_reverse set to false will not contain the "next" link, and the last page in the list requested with page_reverse set to true will not contain the "previous" link. This parameter must be used together with limit. + PageReverse bool `q:"page_reverse"` +} - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} + } + // GET /v3/{project_id}/elb/certificates + return pagination.NewPager(client, client.ServiceURL("certificates")+query.String(), func(r pagination.PageResult) pagination.Page { + return CertificatePage{pagination.LinkedPageBase{PageResult: r}} + }) } -// ToCertificateListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToCertificateListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - return q.String(), err +// CertificatePage is the page returned by a pager when traversing over a +// collection of certificates. +type CertificatePage struct { + pagination.LinkedPageBase } -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("certificates") - if opts != nil { - query, err := opts.ToCertificateListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query +// ExtractCertificates accepts a Page struct, specifically a CertificatePage struct, +// and extracts the elements into a slice of Certificate structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractCertificates(r pagination.Page) ([]Certificate, error) { + var res []Certificate + err := extract.IntoSlicePtr(r.(CertificatePage).BodyReader(), &res, "certificates") + if err != nil { + return nil, err } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return CertificatePage{pagination.SinglePageBase(r)} - }) + return res, nil } diff --git a/openstack/elb/v3/certificates/results.go b/openstack/elb/v3/certificates/results.go index 94a08cab7..f50137333 100644 --- a/openstack/elb/v3/certificates/results.go +++ b/openstack/elb/v3/certificates/results.go @@ -2,27 +2,8 @@ package certificates import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// CertificatePage is the page returned by a pager when traversing over a -// collection of certificates. -type CertificatePage struct { - pagination.SinglePageBase -} - -// ExtractCertificates accepts a Page struct, specifically a CertificatePage struct, -// and extracts the elements into a slice of Certificate structs. In other words, -// a generic collection is mapped into a relevant slice. -func ExtractCertificates(r pagination.Page) ([]Certificate, error) { - var s []Certificate - err := (r.(CertificatePage)).ExtractIntoSlicePtr(&s, "certificates") - if err != nil { - return nil, err - } - return s, nil -} - type commonResult struct { golangsdk.Result } From a321d88084b617b620550fa4318b44a0a37f7ffc Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:51:54 +0200 Subject: [PATCH 08/54] Update --- openstack/elb/v3/certificates/Update.go | 73 ++++++++++++++++--------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/openstack/elb/v3/certificates/Update.go b/openstack/elb/v3/certificates/Update.go index db18b6ba4..74193b46a 100644 --- a/openstack/elb/v3/certificates/Update.go +++ b/openstack/elb/v3/certificates/Update.go @@ -1,39 +1,62 @@ package certificates -import "github.com/opentelekomcloud/gophertelekomcloud" - -// UpdateOptsBuilder is the interface options structs have to satisfy in order -// to be used in the main Update operation in this package. Since many -// extensions decorate or modify the common logic, it is useful for them to -// satisfy a basic interface in order for them to be used. -type UpdateOptsBuilder interface { - ToCertificateUpdateMap() (map[string]interface{}, error) -} +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) // UpdateOpts is the common options' struct used in this package's Update // operation. type UpdateOpts struct { - Name string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - Domain string `json:"domain,omitempty"` - PrivateKey string `json:"private_key,omitempty"` - Certificate string `json:"certificate,omitempty"` -} - -// ToCertificateUpdateMap casts a UpdateOpts struct to a map. -func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "certificate") + // Specifies the certificate name. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Provides supplementary information about the certificate. + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Specifies the domain names used by the server certificate. + // + // This parameter will take effect only when type is set to server, and its default value is "". + // + // This parameter will not take effect even if it is passed and type is set to client. However, domain names will still be verified. + // + // Note: + // + // The value can contain 0 to 1024 characters and consists of multiple common domain names or wildcard domain names separated by commas. A maximum of 30 domain names are allowed. + // + // A common domain name consists of several labels separated by periods (.). Each label can contain a maximum of 63 characters, including letters, digits, and hyphens (-), and must start and end with a letter or digit. Example: www.test.com + // + // A wildcard domain name is a domain name starts with an asterisk (*). Example: *.test.com + // + // Minimum: 0 + // + // Maximum: 1024 + Domain string `json:"domain,omitempty"` + // Specifies the private key of the server certificate. The value must be PEM encoded. + // + // This parameter will be ignored if type is set to client. A CA server can still be created and used normally. This parameter will be left blank even if you enter a private key that is not PEM encoded. + // + // This parameter is valid and mandatory only when type is set to server. If you enter an invalid private key, an error is returned. + PrivateKey string `json:"private_key,omitempty"` + // Specifies the private key of the certificate. The value must be PEM encoded. + Certificate string `json:"certificate,omitempty"` } // Update is an operation which modifies the attributes of the specified Certificate. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { - b, err := opts.ToCertificateUpdateMap() +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*Certificate, error) { + b, err := build.RequestBody(opts, "certificate") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("certificates", id), b, &r.Body, &golangsdk.RequestOpts{ + + raw, err := client.Put(client.ServiceURL("certificates", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) - return + return extra(err, raw) } From 28858f5bb55158fbea9b920d048161d2153164c4 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 18:30:20 +0200 Subject: [PATCH 09/54] Get --- openstack/elb/v3/certificates/Update.go | 2 +- openstack/elb/v3/certificates/results.go | 36 ------------------------ openstack/elb/v3/flavors/Get.go | 14 +++++++-- openstack/elb/v3/flavors/results.go | 14 --------- 4 files changed, 12 insertions(+), 54 deletions(-) delete mode 100644 openstack/elb/v3/certificates/results.go diff --git a/openstack/elb/v3/certificates/Update.go b/openstack/elb/v3/certificates/Update.go index 74193b46a..09a11fa45 100644 --- a/openstack/elb/v3/certificates/Update.go +++ b/openstack/elb/v3/certificates/Update.go @@ -54,7 +54,7 @@ func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*Certi if err != nil { return nil, err } - + // PUT /v3/{project_id}/elb/loadbalancers/{loadbalancer_id} raw, err := client.Put(client.ServiceURL("certificates", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) diff --git a/openstack/elb/v3/certificates/results.go b/openstack/elb/v3/certificates/results.go deleted file mode 100644 index f50137333..000000000 --- a/openstack/elb/v3/certificates/results.go +++ /dev/null @@ -1,36 +0,0 @@ -package certificates - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -type commonResult struct { - golangsdk.Result -} - -func (r commonResult) Extract() (*Certificate, error) { - s := new(Certificate) - err := r.ExtractIntoStructPtr(s, "certificate") - if err != nil { - return nil, err - } - return s, nil -} - -type CreateResult struct { - commonResult -} - -// GetResult represents the result of a get operation. -type GetResult struct { - commonResult -} - -type UpdateResult struct { - commonResult -} - -// DeleteResult represents the result of a delete operation. -type DeleteResult struct { - golangsdk.ErrResult -} diff --git a/openstack/elb/v3/flavors/Get.go b/openstack/elb/v3/flavors/Get.go index ec173980b..dde0b6b0a 100644 --- a/openstack/elb/v3/flavors/Get.go +++ b/openstack/elb/v3/flavors/Get.go @@ -2,10 +2,18 @@ package flavors import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) // Get returns additional information about a Flavor, given its ID. -func Get(client *golangsdk.ServiceClient, flavorID string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("flavors", flavorID), &r.Body, nil) - return +func Get(client *golangsdk.ServiceClient, flavorID string) (*Flavor, error) { + // GET /v3/{project_id}/elb/flavors/{flavor_id} + raw, err := client.Get(client.ServiceURL("flavors", flavorID), nil, nil) + if err != nil { + return nil, err + } + + var res Flavor + err = extract.IntoStructPtr(raw.Body, &res, "flavor") + return &res, err } diff --git a/openstack/elb/v3/flavors/results.go b/openstack/elb/v3/flavors/results.go index 8fb9fc0f9..72c749d4f 100644 --- a/openstack/elb/v3/flavors/results.go +++ b/openstack/elb/v3/flavors/results.go @@ -1,7 +1,6 @@ package flavors import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) @@ -68,16 +67,3 @@ func ExtractFlavors(r pagination.Page) ([]Flavor, error) { } return s, nil } - -type GetResult struct { - golangsdk.Result -} - -func (r GetResult) Extract() (*Flavor, error) { - s := new(Flavor) - err := r.ExtractIntoStructPtr(s, "flavor") - if err != nil { - return nil, err - } - return s, nil -} From 1039d1eaa55b76480fdf1c2dcd78efe2b4e31f2d Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 18:38:35 +0200 Subject: [PATCH 10/54] List --- openstack/elb/v3/certificates/Create.go | 2 +- openstack/elb/v3/certificates/List.go | 9 +-- openstack/elb/v3/flavors/Get.go | 30 ++++++++++ openstack/elb/v3/flavors/List.go | 80 +++++++++++++++++-------- openstack/elb/v3/flavors/results.go | 68 --------------------- 5 files changed, 89 insertions(+), 100 deletions(-) diff --git a/openstack/elb/v3/certificates/Create.go b/openstack/elb/v3/certificates/Create.go index 99a6bf501..98a903b27 100644 --- a/openstack/elb/v3/certificates/Create.go +++ b/openstack/elb/v3/certificates/Create.go @@ -87,5 +87,5 @@ func extra(err error, raw *http.Response) (*Certificate, error) { var res Certificate err = extract.IntoStructPtr(raw.Body, &res, "certificate") - return &res, nil + return &res, err } diff --git a/openstack/elb/v3/certificates/List.go b/openstack/elb/v3/certificates/List.go index 70700aae6..1f98b39d9 100644 --- a/openstack/elb/v3/certificates/List.go +++ b/openstack/elb/v3/certificates/List.go @@ -56,14 +56,14 @@ func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { } // GET /v3/{project_id}/elb/certificates return pagination.NewPager(client, client.ServiceURL("certificates")+query.String(), func(r pagination.PageResult) pagination.Page { - return CertificatePage{pagination.LinkedPageBase{PageResult: r}} + return CertificatePage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } // CertificatePage is the page returned by a pager when traversing over a // collection of certificates. type CertificatePage struct { - pagination.LinkedPageBase + pagination.PageWithInfo } // ExtractCertificates accepts a Page struct, specifically a CertificatePage struct, @@ -72,8 +72,5 @@ type CertificatePage struct { func ExtractCertificates(r pagination.Page) ([]Certificate, error) { var res []Certificate err := extract.IntoSlicePtr(r.(CertificatePage).BodyReader(), &res, "certificates") - if err != nil { - return nil, err - } - return res, nil + return res, err } diff --git a/openstack/elb/v3/flavors/Get.go b/openstack/elb/v3/flavors/Get.go index dde0b6b0a..9dca65c47 100644 --- a/openstack/elb/v3/flavors/Get.go +++ b/openstack/elb/v3/flavors/Get.go @@ -17,3 +17,33 @@ func Get(client *golangsdk.ServiceClient, flavorID string) (*Flavor, error) { err = extract.IntoStructPtr(raw.Body, &res, "flavor") return &res, err } + +type Flavor struct { + // Specifies the ID of the flavor. + ID string `json:"id"` + // Specifies the info of the flavor. + Info FlavorInfo `json:"info"` + // Specifies the name of the flavor. + Name string `json:"name"` + // Specifies whether shared. + Shared bool `json:"shared"` + // Specifies the type of the flavor. + Type string `json:"type"` + // Specifies whether sold out. + SoldOut bool `json:"flavor_sold_out"` +} + +type FlavorInfo struct { + // Specifies the connection + Connection int `json:"connection"` + // Specifies the cps. + Cps int `json:"cps"` + // Specifies the qps + Qps int `json:"qps"` + // Specifies the https_cps + HttpsCps int `json:"https_cps"` + // Specifies the lcu + Lcu int `json:"lcu"` + // Specifies the bandwidth + Bandwidth int `json:"bandwidth"` +} diff --git a/openstack/elb/v3/flavors/List.go b/openstack/elb/v3/flavors/List.go index 435235462..b01ef0aa7 100644 --- a/openstack/elb/v3/flavors/List.go +++ b/openstack/elb/v3/flavors/List.go @@ -2,48 +2,78 @@ package flavors import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToFlavorListMap() (string, error) -} - // ListOpts allows the filtering and sorting of paginated collections through the API. type ListOpts struct { // Specifies the id. ID []string `q:"id"` // Specifies the name. Name []string `q:"name"` - // Specifies whether shared. + // Specifies whether the flavor is available to all users. + // + // true indicates that the flavor is available to all users. + // + // false indicates that the flavor is available only to a specific user. Shared *bool `q:"shared"` // Specifies the type. Type []string `q:"type"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + Limit *int `q:"limit"` + // Specifies the page direction. + // + // The value can be true or false, and the default value is false. + // + // The last page in the list requested with page_reverse set to false will not contain the "next" link, and the last page in the list requested with page_reverse set to true will not contain the "previous" link. + // + // This parameter must be used together with limit. + PageReverse *bool `q:"page_reverse"` } -// ToFlavorListMap formats a ListOpts into a query string. -func (opts ListOpts) ToFlavorListMap() (string, error) { - s, err := golangsdk.BuildQueryString(opts) +// List returns a Pager which allows you to iterate over a collection of flavors. +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { + queryString, err := golangsdk.BuildQueryString(opts) if err != nil { - return "", err + return pagination.Pager{Err: err} } - return s.String(), err -} -// List returns a Pager which allows you to iterate over a collection of -// flavors. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("flavors") - if opts != nil { - queryString, err := opts.ToFlavorListMap() - if err != nil { - return pagination.Pager{Err: err} - } - url += queryString - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return pagination.NewPager(client, client.ServiceURL("flavors")+queryString.String(), func(r pagination.PageResult) pagination.Page { return FlavorPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +// FlavorPage is the page returned by a pager when traversing over a collection of flavor. +type FlavorPage struct { + pagination.PageWithInfo +} + +// IsEmpty checks whether a FlavorsPage struct is empty. +func (r FlavorPage) IsEmpty() (bool, error) { + is, err := ExtractFlavors(r) + return len(is) == 0, err +} + +// ExtractFlavors accepts a Page struct, specifically a FlavorsPage struct, +// and extracts the elements into a slice of flavor structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractFlavors(r pagination.Page) ([]Flavor, error) { + var res []Flavor + err := extract.IntoSlicePtr(r.(FlavorPage).BodyReader(), &res, "flavors") + return res, err +} diff --git a/openstack/elb/v3/flavors/results.go b/openstack/elb/v3/flavors/results.go index 72c749d4f..f6e0d7d92 100644 --- a/openstack/elb/v3/flavors/results.go +++ b/openstack/elb/v3/flavors/results.go @@ -1,69 +1 @@ package flavors - -import ( - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -type Flavor struct { - // Specifies the ID of the flavor. - ID string `json:"id"` - - // Specifies the info of the flavor. - Info FlavorInfo `json:"info"` - - // Specifies the name of the flavor. - Name string `json:"name"` - - // Specifies whether shared. - Shared bool `json:"shared"` - - // Specifies the type of the flavor. - Type string `json:"type"` - - // Specifies whether sold out. - SoldOut bool `json:"flavor_sold_out"` -} - -type FlavorInfo struct { - // Specifies the connection - Connection int `json:"connection"` - - // Specifies the cps. - Cps int `json:"cps"` - - // Specifies the qps - Qps int `json:"qps"` - - // Specifies the https_cps - HttpsCps int `json:"https_cps"` - - // Specifies the lcu - Lcu int `json:"lcu"` - - // Specifies the bandwidth - Bandwidth int `json:"bandwidth"` -} - -// FlavorPage is the page returned by a pager when traversing over a -// collection of flavor. -type FlavorPage struct { - pagination.PageWithInfo -} - -// IsEmpty checks whether a FlavorsPage struct is empty. -func (r FlavorPage) IsEmpty() (bool, error) { - is, err := ExtractFlavors(r) - return len(is) == 0, err -} - -// ExtractFlavors accepts a Page struct, specifically a FlavorsPage struct, -// and extracts the elements into a slice of flavor structs. In other words, -// a generic collection is mapped into a relevant slice. -func ExtractFlavors(r pagination.Page) ([]Flavor, error) { - var s []Flavor - err := (r.(FlavorPage)).ExtractIntoSlicePtr(&s, "flavors") - if err != nil { - return nil, err - } - return s, nil -} From 4eef8135858c68b1c12857a1544f9896bbc07d81 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 18:48:14 +0200 Subject: [PATCH 11/54] Create --- openstack/elb/v3/flavors/List.go | 2 +- openstack/elb/v3/ipgroups/Create.go | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/openstack/elb/v3/flavors/List.go b/openstack/elb/v3/flavors/List.go index b01ef0aa7..b8bbce0ad 100644 --- a/openstack/elb/v3/flavors/List.go +++ b/openstack/elb/v3/flavors/List.go @@ -52,7 +52,7 @@ func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { if err != nil { return pagination.Pager{Err: err} } - + // GET /v3/{project_id}/elb/flavors return pagination.NewPager(client, client.ServiceURL("flavors")+queryString.String(), func(r pagination.PageResult) pagination.Page { return FlavorPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) diff --git a/openstack/elb/v3/ipgroups/Create.go b/openstack/elb/v3/ipgroups/Create.go index ef32c03e0..a7e7acf55 100644 --- a/openstack/elb/v3/ipgroups/Create.go +++ b/openstack/elb/v3/ipgroups/Create.go @@ -2,21 +2,18 @@ package ipgroups import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -// CreateOpts is the common options' struct used in this package's Create -// operation. +// CreateOpts is the common options' struct used in this package's Create operation. type CreateOpts struct { // Specifies the IP address group name. Name string `json:"name,omitempty"` - // Provides supplementary information about the IP address group. Description string `json:"description,omitempty"` - // Specifies the project ID of the IP address group. ProjectId string `json:"project_id,omitempty"` - // Specifies the IP addresses or CIDR blocks in the IP address group. [] indicates any IP address. IpList []IpGroupOption `json:"ip_list,omitempty"` } @@ -24,7 +21,6 @@ type CreateOpts struct { type IpGroupOption struct { // Specifies the IP addresses in the IP address group. Ip string `json:"ip" required:"true"` - // Provides remarks about the IP address group. Description string `json:"description"` } @@ -48,13 +44,12 @@ type DataStore struct { // validated and progress has started on the provisioning process, a // IpGroup will be returned. func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*IpGroup, error) { - b, err := golangsdk.BuildRequestBody(opts, "ipgroup") + b, err := build.RequestBody(opts, "ipgroup") if err != nil { return nil, err } - raw, err := c.Post(c.ServiceURL("ipgroups"), b, nil, &golangsdk.RequestOpts{ - OkCodes: []int{201}, - }) + + raw, err := c.Post(c.ServiceURL("ipgroups"), b, nil, nil) if err != nil { return nil, err } From 092f723e0e016713c858a83a99f4c2b7f5a46448 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 19:00:15 +0200 Subject: [PATCH 12/54] List --- acceptance/openstack/elb/v3/ipgroups_test.go | 40 ++++---- openstack/elb/v3/flavors/List.go | 1 + openstack/elb/v3/flavors/results.go | 1 - openstack/elb/v3/ipgroups/Get.go | 31 +++++++ openstack/elb/v3/ipgroups/List.go | 98 +++++++++++--------- 5 files changed, 105 insertions(+), 66 deletions(-) delete mode 100644 openstack/elb/v3/flavors/results.go diff --git a/acceptance/openstack/elb/v3/ipgroups_test.go b/acceptance/openstack/elb/v3/ipgroups_test.go index 7bd40aa65..9eb328707 100644 --- a/acceptance/openstack/elb/v3/ipgroups_test.go +++ b/acceptance/openstack/elb/v3/ipgroups_test.go @@ -15,8 +15,9 @@ func TestIpGroupList(t *testing.T) { client, err := clients.NewElbV3Client() th.AssertNoErr(t, err) - listOpts := ipgroups.ListOpts{} - ipgroupsList, err := ipgroups.List(client, listOpts) + ipgroupsLists, err := ipgroups.List(client, ipgroups.ListOpts{}).AllPages() + th.AssertNoErr(t, err) + ipgroupsList, err := ipgroups.ExtractIpGroups(ipgroupsLists) th.AssertNoErr(t, err) for _, gr := range ipgroupsList { @@ -31,18 +32,15 @@ func TestIpGroupsLifecycle(t *testing.T) { loadbalancerID := createLoadBalancer(t, client) defer deleteLoadbalancer(t, client, loadbalancerID) - ipGroupOpts := ipgroups.IpGroupOption{ - Ip: "192.168.10.10", - Description: "first", - } - ipGroupName := tools.RandomString("create-ip-group-", 3) - createOpts := ipgroups.CreateOpts{ - Description: "some interesting description", - Name: ipGroupName, - IpList: []ipgroups.IpGroupOption{ipGroupOpts}, - } t.Logf("Attempting to create ELBv3 IpGroup") - ipGroup, err := ipgroups.Create(client, createOpts) + ipGroup, err := ipgroups.Create(client, ipgroups.CreateOpts{ + Description: "some interesting description", + Name: tools.RandomString("create-ip-group-", 3), + IpList: []ipgroups.IpGroupOption{ipgroups.IpGroupOption{ + Ip: "192.168.10.10", + Description: "first", + }}, + }) th.AssertNoErr(t, err) t.Cleanup(func() { @@ -52,9 +50,8 @@ func TestIpGroupsLifecycle(t *testing.T) { }) t.Logf("Attempting to update ELBv3 IpGroup: %s", ipGroup.ID) - ipGroupNameUpdate := tools.RandomString("update-ip-group-", 3) - updateOpts := ipgroups.UpdateOpts{ - Name: ipGroupNameUpdate, + err = ipgroups.Update(client, ipGroup.ID, ipgroups.UpdateOpts{ + Name: tools.RandomString("update-ip-group-", 3), IpList: []ipgroups.IpGroupOption{ { Ip: "192.168.10.12", @@ -65,18 +62,19 @@ func TestIpGroupsLifecycle(t *testing.T) { Description: "fourth", }, }, - } - err = ipgroups.Update(client, ipGroup.ID, updateOpts) + }) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 ipGroup: %s", ipGroup.ID) updatedIpGroup, err := ipgroups.Get(client, ipGroup.ID) th.AssertNoErr(t, err) - th.AssertEquals(t, ipGroupNameUpdate, updatedIpGroup.Name) + th.AssertEquals(t, tools.RandomString("update-ip-group-", 3), updatedIpGroup.Name) - listOpts := ipgroups.ListOpts{} - ipGroupsSlice, err := ipgroups.List(client, listOpts) + ipGroupsSlices, err := ipgroups.List(client, ipgroups.ListOpts{}).AllPages() th.AssertNoErr(t, err) + ipGroupsSlice, err := ipgroups.ExtractIpGroups(ipGroupsSlices) + th.AssertNoErr(t, err) + th.AssertEquals(t, 1, len(ipGroupsSlice)) th.AssertDeepEquals(t, *updatedIpGroup, ipGroupsSlice[0]) diff --git a/openstack/elb/v3/flavors/List.go b/openstack/elb/v3/flavors/List.go index b8bbce0ad..4e0a9533f 100644 --- a/openstack/elb/v3/flavors/List.go +++ b/openstack/elb/v3/flavors/List.go @@ -52,6 +52,7 @@ func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { if err != nil { return pagination.Pager{Err: err} } + // GET /v3/{project_id}/elb/flavors return pagination.NewPager(client, client.ServiceURL("flavors")+queryString.String(), func(r pagination.PageResult) pagination.Page { return FlavorPage{PageWithInfo: pagination.NewPageWithInfo(r)} diff --git a/openstack/elb/v3/flavors/results.go b/openstack/elb/v3/flavors/results.go deleted file mode 100644 index f6e0d7d92..000000000 --- a/openstack/elb/v3/flavors/results.go +++ /dev/null @@ -1 +0,0 @@ -package flavors diff --git a/openstack/elb/v3/ipgroups/Get.go b/openstack/elb/v3/ipgroups/Get.go index 061743936..01ee660f1 100644 --- a/openstack/elb/v3/ipgroups/Get.go +++ b/openstack/elb/v3/ipgroups/Get.go @@ -3,6 +3,7 @@ package ipgroups import ( "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" ) // Get retrieves a particular Configuration based on its unique ID. @@ -16,3 +17,33 @@ func Get(client *golangsdk.ServiceClient, id string) (*IpGroup, error) { err = extract.IntoStructPtr(raw.Body, &res, "ipgroup") return &res, err } + +// IpGroup The IP address can contain IP addresses or CIDR blocks. +// 0.0.0.0 will be considered the same as 0.0.0.0/32. If you enter both 0.0.0.0 and 0.0.0.0/32, +// only one will be kept. 0:0:0:0:0:0:0:1 will be considered the same as ::1 and ::1/128. +// If you enter 0:0:0:0:0:0:0:1, ::1 and ::1/128, only one will be kept. +type IpGroup struct { + // The unique ID for the IpGroup. + ID string `json:"id"` + // Specifies the IP address group name. + Name string `json:"name"` + // Provides remarks about the IP address group. + Description string `json:"description"` + // Specifies the project ID of the IP address group. + ProjectId string `json:"project_id"` + // Specifies the IP addresses or CIDR blocks in the IP address group. [] indicates any IP address. + IpList []IpInfo `json:"ip_list"` + // Lists the IDs of listeners with which the IP address group is associated. + Listeners []structs.ResourceRef `json:"listeners"` + // Specifies the time when the IP address group was created. + CreatedAt string `json:"created_at"` + // Specifies the time when the IP address group was updated. + UpdatedAt string `json:"updated_at"` +} + +type IpInfo struct { + // Specifies the IP addresses in the IP address group. + Ip string `json:"ip"` + // Provides remarks about the IP address group. + Description string `json:"description"` +} diff --git a/openstack/elb/v3/ipgroups/List.go b/openstack/elb/v3/ipgroups/List.go index ea17aec1c..dded9b026 100644 --- a/openstack/elb/v3/ipgroups/List.go +++ b/openstack/elb/v3/ipgroups/List.go @@ -3,64 +3,74 @@ package ipgroups import ( "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" - "github.com/opentelekomcloud/gophertelekomcloud/openstack" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type ListOpts struct { - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` - - ID []string `q:"id"` - Name []string `q:"name"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit int `q:"limit"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse bool `q:"page_reverse"` + // Specifies the ID of the IP address group. + ID []string `q:"id"` + // Specifies the name of the IP address group. + Name []string `q:"name"` + // Provides supplementary information about the IP address group. Description []string `q:"description"` - IpList []string `q:"ip_list"` + // Lists the IP addresses in the IP address group. Multiple IP addresses are separated with commas. + IpList []string `q:"ip_list"` } // List is used to obtain the parameter ipGroup list -func List(client *golangsdk.ServiceClient, opts ListOpts) ([]IpGroup, error) { +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { q, err := golangsdk.BuildQueryString(opts) if err != nil { - return nil, err + return pagination.Pager{Err: err} } // GET https://{Endpoint}/v3/{project_id}/backups - raw, err := client.Get(client.ServiceURL("ipgroups")+q.String(), nil, openstack.StdRequestOpts()) - if err != nil { - return nil, err - } + return pagination.NewPager(client, client.ServiceURL("ipgroups")+q.String(), func(r pagination.PageResult) pagination.Page { + return IpGroupPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} - var res []IpGroup - err = extract.IntoSlicePtr(raw.Body, &res, "ipgroups") - return res, err +type IpGroupPage struct { + pagination.PageWithInfo } -// IpGroup The IP address can contain IP addresses or CIDR blocks. -// 0.0.0.0 will be considered the same as 0.0.0.0/32. If you enter both 0.0.0.0 and 0.0.0.0/32, -// only one will be kept. 0:0:0:0:0:0:0:1 will be considered the same as ::1 and ::1/128. -// If you enter 0:0:0:0:0:0:0:1, ::1 and ::1/128, only one will be kept. -type IpGroup struct { - // The unique ID for the IpGroup. - ID string `json:"id"` - // Specifies the IP address group name. - Name string `json:"name"` - // Provides remarks about the IP address group. - Description string `json:"description"` - // Specifies the project ID of the IP address group. - ProjectId string `json:"project_id"` - // Specifies the IP addresses or CIDR blocks in the IP address group. [] indicates any IP address. - IpList []IpInfo `json:"ip_list"` - // Lists the IDs of listeners with which the IP address group is associated. - Listeners []structs.ResourceRef `json:"listeners"` - // Specifies the time when the IP address group was created. - CreatedAt string `json:"created_at"` - // Specifies the time when the IP address group was updated. - UpdatedAt string `json:"updated_at"` +func (r IpGroupPage) IsEmpty() (bool, error) { + is, err := ExtractIpGroups(r) + return len(is) == 0, err } -type IpInfo struct { - // Specifies the IP addresses in the IP address group. - Ip string `json:"ip"` - // Provides remarks about the IP address group. - Description string `json:"description"` + +func ExtractIpGroups(r pagination.Page) ([]IpGroup, error) { + var res []IpGroup + err := extract.IntoSlicePtr(r.(IpGroupPage).BodyReader(), &res, "ipgroups") + return res, err } From db36ee3843b5326fdd8bd89b36e62adb85f7f930 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 19:40:35 +0200 Subject: [PATCH 13/54] UpdateIpList --- openstack/elb/v3/ipgroups/Update.go | 4 ++-- openstack/elb/v3/ipgroups/UpdateIpList.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openstack/elb/v3/ipgroups/Update.go b/openstack/elb/v3/ipgroups/Update.go index 9df256315..18b8d03e3 100644 --- a/openstack/elb/v3/ipgroups/Update.go +++ b/openstack/elb/v3/ipgroups/Update.go @@ -15,14 +15,14 @@ type UpdateOpts struct { IpList []IpGroupOption `json:"ip_list,omitempty"` } -// Update is an operation which modifies the attributes of the specified -// IpGroup. +// Update is an operation which modifies the attributes of the specified IpGroup. func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (err error) { b, err := build.RequestBody(opts, "ipgroup") if err != nil { return } + // PUT /v3/{project_id}/elb/ipgroups/{ipgroup_id} _, err = c.Put(c.ServiceURL("ipgroups", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) diff --git a/openstack/elb/v3/ipgroups/UpdateIpList.go b/openstack/elb/v3/ipgroups/UpdateIpList.go index 91bcfbe1c..cac57b8a4 100644 --- a/openstack/elb/v3/ipgroups/UpdateIpList.go +++ b/openstack/elb/v3/ipgroups/UpdateIpList.go @@ -12,8 +12,9 @@ func UpdateIpList(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (*IpGr if err != nil { return nil, err } - url := c.ServiceURL("ipgroups", id, "iplist", "create-or-update") - raw, err := c.Post(url, b, nil, &golangsdk.RequestOpts{ + + // POST /v3/{project_id}/elb/ipgroups/{ipgroup_id}/iplist/create-or-update + raw, err := c.Post(c.ServiceURL("ipgroups", id, "iplist", "create-or-update"), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) if err != nil { From 610639af816711ecc1579a8006e0bc2b7abaa611 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 19:46:00 +0200 Subject: [PATCH 14/54] ipgroups --- acceptance/openstack/elb/v3/ipgroups_test.go | 2 +- openstack/elb/v3/ipgroups/Create.go | 7 +++++++ openstack/elb/v3/ipgroups/Delete.go | 1 + openstack/elb/v3/ipgroups/DeleteIpsFromList.go | 14 ++++---------- openstack/elb/v3/ipgroups/Get.go | 10 ++-------- openstack/elb/v3/ipgroups/Update.go | 8 ++++---- openstack/elb/v3/ipgroups/UpdateIpList.go | 9 +-------- 7 files changed, 20 insertions(+), 31 deletions(-) diff --git a/acceptance/openstack/elb/v3/ipgroups_test.go b/acceptance/openstack/elb/v3/ipgroups_test.go index 9eb328707..806f00282 100644 --- a/acceptance/openstack/elb/v3/ipgroups_test.go +++ b/acceptance/openstack/elb/v3/ipgroups_test.go @@ -50,7 +50,7 @@ func TestIpGroupsLifecycle(t *testing.T) { }) t.Logf("Attempting to update ELBv3 IpGroup: %s", ipGroup.ID) - err = ipgroups.Update(client, ipGroup.ID, ipgroups.UpdateOpts{ + _, err = ipgroups.Update(client, ipGroup.ID, ipgroups.UpdateOpts{ Name: tools.RandomString("update-ip-group-", 3), IpList: []ipgroups.IpGroupOption{ { diff --git a/openstack/elb/v3/ipgroups/Create.go b/openstack/elb/v3/ipgroups/Create.go index a7e7acf55..4e4aabecb 100644 --- a/openstack/elb/v3/ipgroups/Create.go +++ b/openstack/elb/v3/ipgroups/Create.go @@ -1,6 +1,8 @@ package ipgroups import ( + "net/http" + "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/build" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" @@ -49,7 +51,12 @@ func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*IpGroup, error) { return nil, err } + // POST /v3/{project_id}/elb/ipgroups raw, err := c.Post(c.ServiceURL("ipgroups"), b, nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*IpGroup, error) { if err != nil { return nil, err } diff --git a/openstack/elb/v3/ipgroups/Delete.go b/openstack/elb/v3/ipgroups/Delete.go index 5e3bebbad..5a5d9b34f 100644 --- a/openstack/elb/v3/ipgroups/Delete.go +++ b/openstack/elb/v3/ipgroups/Delete.go @@ -7,6 +7,7 @@ import ( // Delete will permanently delete a particular IpGroup based on its // unique ID. func Delete(c *golangsdk.ServiceClient, id string) (err error) { + // DELETE /v3/{project_id}/elb/ipgroups/{ipgroup_id} _, err = c.Delete(c.ServiceURL("ipgroups", id), nil) return } diff --git a/openstack/elb/v3/ipgroups/DeleteIpsFromList.go b/openstack/elb/v3/ipgroups/DeleteIpsFromList.go index 0424898f0..be6113d01 100644 --- a/openstack/elb/v3/ipgroups/DeleteIpsFromList.go +++ b/openstack/elb/v3/ipgroups/DeleteIpsFromList.go @@ -3,7 +3,6 @@ package ipgroups import ( "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/build" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) // DeleteIpFromList is used to create or update the ip list of specific ip group. @@ -12,17 +11,12 @@ func DeleteIpFromList(c *golangsdk.ServiceClient, id string, opts BatchDeleteOpt if err != nil { return nil, err } - url := c.ServiceURL("ipgroups", id, "iplist", "batch-delete") - raw, err := c.Post(url, b, nil, &golangsdk.RequestOpts{ + + // POST /v3/{project_id}/elb/ipgroups/{ipgroup_id}/iplist/batch-delete + raw, err := c.Post(c.ServiceURL("ipgroups", id, "iplist", "batch-delete"), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) - if err != nil { - return nil, err - } - - var res IpGroup - err = extract.IntoStructPtr(raw.Body, &res, "ipgroup") - return &res, err + return extra(err, raw) } // BatchDeleteOpts contains all the values needed to perform BatchDelete on the IP address group. diff --git a/openstack/elb/v3/ipgroups/Get.go b/openstack/elb/v3/ipgroups/Get.go index 01ee660f1..474118aea 100644 --- a/openstack/elb/v3/ipgroups/Get.go +++ b/openstack/elb/v3/ipgroups/Get.go @@ -2,20 +2,14 @@ package ipgroups import ( "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" ) // Get retrieves a particular Configuration based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (*IpGroup, error) { + // GET /v3/{project_id}/elb/ipgroups/{ipgroup_id} raw, err := client.Get(client.ServiceURL("ipgroups", id), nil, nil) - if err != nil { - return nil, err - } - - var res IpGroup - err = extract.IntoStructPtr(raw.Body, &res, "ipgroup") - return &res, err + return extra(err, raw) } // IpGroup The IP address can contain IP addresses or CIDR blocks. diff --git a/openstack/elb/v3/ipgroups/Update.go b/openstack/elb/v3/ipgroups/Update.go index 18b8d03e3..11701443a 100644 --- a/openstack/elb/v3/ipgroups/Update.go +++ b/openstack/elb/v3/ipgroups/Update.go @@ -16,16 +16,16 @@ type UpdateOpts struct { } // Update is an operation which modifies the attributes of the specified IpGroup. -func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (err error) { +func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (*IpGroup, error) { b, err := build.RequestBody(opts, "ipgroup") if err != nil { - return + return nil, err } // PUT /v3/{project_id}/elb/ipgroups/{ipgroup_id} - _, err = c.Put(c.ServiceURL("ipgroups", id), b, nil, &golangsdk.RequestOpts{ + raw, err := c.Put(c.ServiceURL("ipgroups", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) - return + return extra(err, raw) } diff --git a/openstack/elb/v3/ipgroups/UpdateIpList.go b/openstack/elb/v3/ipgroups/UpdateIpList.go index cac57b8a4..a56f70d64 100644 --- a/openstack/elb/v3/ipgroups/UpdateIpList.go +++ b/openstack/elb/v3/ipgroups/UpdateIpList.go @@ -3,7 +3,6 @@ package ipgroups import ( "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/build" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) // UpdateIpList is used to create or update the ip list of specific ip group. @@ -17,11 +16,5 @@ func UpdateIpList(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (*IpGr raw, err := c.Post(c.ServiceURL("ipgroups", id, "iplist", "create-or-update"), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) - if err != nil { - return nil, err - } - - var res IpGroup - err = extract.IntoStructPtr(raw.Body, &res, "ipgroup") - return &res, err + return extra(err, raw) } From 64a7228fb858cbbf7e27e0a50849ffa53f74b8da Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 14 Apr 2023 20:04:26 +0200 Subject: [PATCH 15/54] Create --- openstack/elb/v3/listeners/Create.go | 311 ++++++++++++++++++++----- openstack/elb/v3/listeners/Get.go | 70 +++++- openstack/elb/v3/listeners/Update.go | 25 +- openstack/elb/v3/listeners/requests.go | 30 --- openstack/elb/v3/listeners/results.go | 92 -------- 5 files changed, 326 insertions(+), 202 deletions(-) delete mode 100644 openstack/elb/v3/listeners/requests.go diff --git a/openstack/elb/v3/listeners/Create.go b/openstack/elb/v3/listeners/Create.go index 7852bb71e..758d76be6 100644 --- a/openstack/elb/v3/listeners/Create.go +++ b/openstack/elb/v3/listeners/Create.go @@ -1,102 +1,280 @@ package listeners import ( + "net/http" + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" ) -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToListenerCreateMap() (map[string]interface{}, error) -} - // CreateOpts represents options for creating a listener. type CreateOpts struct { - // The administrative state of the Listener. A valid value is true (UP) - // or false (DOWN). + // Specifies the administrative status of the listener. The value can only be true. + // + // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // the ID of the CA certificate used by the listener. + // Specifies the ID of the CA certificate used by the listener. This parameter is available only when type is set to client. + // + // Minimum: 1 + // + // Maximum: 128 CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"` - - // The ID of the default pool with which the Listener is associated. + // Specifies the ID of the default backend server group. If there is no matched forwarding policy, requests will be forwarded to the default backend server for processing. + // + // Minimum: 1 + // + // Maximum: 36 DefaultPoolID string `json:"default_pool_id,omitempty"` - - // A reference to a Barbican container of TLS secrets. + // Specifies the ID of the server certificate used by the listener. This parameter is available only when the listener's protocol is HTTPS and type is set to server. + // + // Minimum: 1 + // + // Maximum: 128 DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` - - // Provides supplementary information about the Listener. + // Provides supplementary information about the listener. + // + // Minimum: 0 + // + // Maximum: 255 Description string `json:"description,omitempty"` - - // whether to use HTTP2. + // Specifies whether to use HTTP/2 if you want the clients to use HTTP/2 to communicate with the load balancer. However, connections between the load balancer and backend servers still use HTTP/1.x by default. + // + // This parameter is available only for HTTPS listeners. If you configure this parameter for listeners with other protocols, it will not take effect. Http2Enable *bool `json:"http2_enable,omitempty"` - - // The load balancer on which to provision this listener. + // Specifies the ID of the load balancer that the listener is added to. Note: A listener can be added to only one load balancer. + // + // Minimum: 1 + // + // Maximum: 36 LoadbalancerID string `json:"loadbalancer_id" required:"true"` - - // Specifies the Listener name. + // Specifies the listener name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // ProjectID is only required if the caller has an admin role and wants - // to create a pool for another project. + // Specifies the project ID. + // + // Minimum: 1 + // + // Maximum: 32 ProjectID string `json:"project_id,omitempty"` - - // The protocol - can either be TCP, HTTP or HTTPS. - Protocol Protocol `json:"protocol" required:"true"` - - // The port on which to listen for client traffic. + // Specifies the protocol used by the listener. + // + // The value can be TCP, HTTP, UDP, HTTPS, or TERMINATED_HTTPS. + // + // Note: + // + // Protocol used by HTTPS listeners added to a shared load balancer can only be set to TERMINATED_HTTPS. If HTTPS is passed, the value will be automatically changed to TERMINATED_HTTPS. + // + // Protocol used by HTTPS listeners added to a dedicated load balancer can only be set to HTTPS. If TERMINATED_HTTPS is passed, the value will be automatically changed to HTTPS. + Protocol string `json:"protocol" required:"true"` + // Specifies the protocol used by the listener. + // + // The value can be TCP, HTTP, UDP, HTTPS, or TERMINATED_HTTPS. + // + // Note: + // + // Protocol used by HTTPS listeners added to a shared load balancer can only be set to TERMINATED_HTTPS. If HTTPS is passed, the value will be automatically changed to TERMINATED_HTTPS. + // + // Protocol used by HTTPS listeners added to a dedicated load balancer can only be set to HTTPS. If TERMINATED_HTTPS is passed, the value will be automatically changed to HTTPS. + // + // Minimum: 1 + // + // Maximum: 65535 ProtocolPort int `json:"protocol_port" required:"true"` - - // A list of references to TLS secrets. + // Specifies the IDs of SNI certificates (server certificates with domain names) used by the listener. + // + // Note: + // + // The domain names of all SNI certificates must be unique. + // + // The total number of domain names of all SNI certificates cannot exceed 30. SniContainerRefs []string `json:"sni_container_refs,omitempty"` - // Specifies how wildcard domain name matches with the SNI certificates used by the listener. + // // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. + // // The default value is wildcard. SniMatchAlgo string `json:"sni_match_algo,omitempty"` - // A list of Tags. Tags []tags.ResourceTag `json:"tags,omitempty"` - // Specifies the security policy used by the listener. + // + // Values: tls-1-0-inherit,tls-1-0, tls-1-1, tls-1-2,tls-1-2-strict, tls-1-2-fs, tls-1-0-with-1-3, tls-1-2-fs-with-1-3, hybrid-policy-1-0, and tls-1-0 (default). + // + // Note: + // + // This parameter will take effect only for HTTPS listeners added to a dedicated load balancer. + // + // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // + // The priority of the encryption suite from high to low is: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"` - // Specifies the ID of the custom security policy. + // // Note: + // // This parameter is available only for HTTPS listeners added to a dedicated load balancer. + // // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). + // + // Minimum: 1 + // + // Maximum: 36 SecurityPolicy string `json:"security_policy_id,omitempty"` - - // Whether enable member retry + // Specifies whether to enable health check retries for backend servers. The value can be true (enable health check retries) or false (disable health check retries). The default value is true. Note: + // + // If a shared load balancer is associated, this parameter is available only when protocol is set to HTTP or TERMINATED_HTTPS. + // + // If a dedicated load balancer is associated, this parameter is available only when protocol is set to HTTP, or HTTPS. EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` - - // The keepalive timeout of the Listener. + // Specifies the idle timeout duration, in seconds. If there are no requests reaching the load balancer after the idle timeout duration elapses, the load balancer will disconnect the connection with the client and establish a new connection when there is a new request. + // + // For TCP listeners, the value ranges from 10 to 4000, and the default value is 300. + // + // For HTTP and HTTPS listeners, the value ranges from 1 to 4000, and the default value is 60. + // + // For UDP listeners, this parameter does not take effect. KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` - - // The client timeout of the Listener. + // Specifies the timeout duration for waiting for a response from a client, in seconds. There are two situations: + // + // If the client fails to send a request header to the load balancer within the timeout duration, the request will be interrupted. + // + // If the interval between two consecutive request bodies reaching the load balancer is greater than the timeout duration, the connection will be disconnected. + // + // The value ranges from 1 to 300, and the default value is 60. + // + // This parameter is available only for HTTP and HTTPS listeners. + // + // Minimum: 1 + // + // Maximum: 300 + // + // Default: 60 ClientTimeout int `json:"client_timeout,omitempty"` - - // The member timeout of the Listener. + // Specifies the timeout duration for waiting for a response from a backend server, in seconds. If the backend server fails to respond after the timeout duration elapses, the load balancer will stop waiting and return HTTP 504 Gateway Timeout to the client. + // + // The value ranges from 1 to 300, and the default value is 60. + // + // This parameter is available only for HTTP and HTTPS listeners. + // + // Minimum: 1 + // + // Maximum: 300 + // + // Default: 60 MemberTimeout int `json:"member_timeout,omitempty"` - - // The IpGroup of the Listener. + // Specifies the IP address group associated with the listener. IpGroup *IpGroup `json:"ipgroup,omitempty"` - - // The http insert headers of the Listener. + // Specifies the HTTP header fields that can transmit required information to backend servers. For example, the X-Forwarded-ELB-IP header field can transmit the EIP of the load balancer to backend servers. InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` - - // Transparent client ip enable + // Specifies whether to pass source IP addresses of the clients to backend servers. + // + // TCP or UDP listeners of shared load balancers: The value can be true or false, and the default value is false if this parameter is not passed. + // + // HTTP or HTTPS listeners of shared load balancers: The value can only be true, and the default value is true if this parameter is not passed. + // + // All listeners of dedicated load balancers: The value can only be true, and the default value is true if this parameter is not passed. + // + // Note: + // + // If this function is enabled, the load balancer communicates with backend servers using their real IP addresses. Ensure that security group rules and access control policies are correctly configured. + // + // If this function is enabled, a server cannot serve as both a backend server and a client. + // + // If this function is enabled, backend server specifications cannot be changed. TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` - - // Enhance L7policy enable + // Specifies whether to enable advanced forwarding. If advanced forwarding is enabled, more flexible forwarding policies and rules are supported. The value can be true (enable advanced forwarding) or false (disable advanced forwarding), and the default value is false. + // + // The following scenarios are supported: + // + // action can be set to REDIRECT_TO_URL (requests will be redirected to another URL) or Fixed_RESPONSE (a fixed response body will be returned to clients). + // + // Parameters priority, redirect_url_config, and fixed_response_config can be specified in a forwarding policy. + // + // Parameter type can be set to METHOD, HEADER, QUERY_STRING, or SOURCE_IP for a forwarding rule. + // + // If type is set to HOST_NAME for a forwarding rule, the value parameter of the forwarding rule supports wildcard asterisks (*). + // + // The conditions parameter can be specified for forwarding rules. This parameter is not available in eu-nl region. Please do not use it. EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` + // Specifies the QUIC configuration for the current listener. This parameter is valid only when protocol is set to HTTPS. + // + // For a TCP/UDP/HTTP/QUIC listener, if this parameter is not left blank, an error will be reported. + // + // Note + // + // The client sends a normal HTTP request that contains information indicating that the QUIC protocol is supported. + // + // If QUIC upgrade is enabled for the listeners, QUIC port and version information will be added to the response header. + // + // When the client sends both HTTPS and QUIC requests to the server, if the QUIC request is successfully sent, QUIC protocol will be used for subsequent communications. + // + // QUIC protocol is not supported. + QuicConfig QuicConfigOption `json:"quic_config,omitempty"` } -// ToListenerCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "listener") +type IpGroup struct { + // Specifies the ID of the IP address group associated with the listener. + // + // If ip_list is set to an empty array [] and type to whitelist, no IP addresses are allowed to access the listener. + // + // If ip_list is set to an empty array [] and type to blacklist, any IP address is allowed to access the listener. + // + // Minimum: 1 + // + // Maximum: 36 + IpGroupID string `json:"ipgroup_id" required:"true"` + // Specifies whether to enable access control. + // + // true (default): Access control will be enabled. + // + // false: Access control will be disabled. + Enable *bool `json:"enable_ipgroup,omitempty"` + // Specifies how access to the listener is controlled. + // + // white (default): A whitelist will be configured. Only IP addresses in the whitelist can access the listener. + // + // black: A blacklist will be configured. IP addresses in the blacklist are not allowed to access the listener. + Type string `json:"type,omitempty"` +} + +type InsertHeaders struct { + // Specifies whether to transparently transmit the load balancer EIP to backend servers. If X-Forwarded-ELB-IP is set to true, the load balancer EIP will be stored in the HTTP header and passed to backend servers. + // + // Default: false + ForwardedELBIP *bool `json:"X-Forwarded-ELB-IP,omitempty"` + // Specifies whether to transparently transmit the listening port of the load balancer to backend servers. If X-Forwarded-Port is set to true, the listening port of the load balancer will be stored in the HTTP header and passed to backend servers. + // + // Default: false + ForwardedPort *bool `json:"X-Forwarded-Port,omitempty"` + // Specifies whether to transparently transmit the source port of the client to backend servers. If X-Forwarded-For-Port is set to true, the source port of the client will be stored in the HTTP header and passed to backend servers. + // + // Default: false + ForwardedForPort *bool `json:"X-Forwarded-For-Port,omitempty"` + // Specifies whether to rewrite the X-Forwarded-Host header. If X-Forwarded-Host is set to true, X-Forwarded-Host in the request header from the clients can be set to Host in the request header sent from the load balancer to backend servers. + // + // Default: true + ForwardedHost *bool `json:"X-Forwarded-Host" required:"true"` +} + +type QuicConfigOption struct { + // Specifies the ID of the QUIC listener. Specifies the specified listener. The specified quic_listener_id must exist. The listener protocol must be QUIC and cannot be set to null, otherwise, it will conflict with enable_quic_upgrade. + // + // QUIC protocol is not supported. + QuicListenerId string `json:"quic_listener_id" required:"true"` + // + // Specifies whether to enable QUIC upgrade. True: QUIC upgrade is enabled. False (default): QUIC upgrade is disabled. HTTPS listeners can be upgraded to QUIC listeners. + // + // QUIC protocol is not supported. + // + // Default: false + EnableQuicUpgrade *bool `json:"enable_quic_upgrade,omitempty"` } // Create is an operation which provisions a new Listeners based on the @@ -106,12 +284,23 @@ func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { // // Users with an admin role can create Listeners on behalf of other tenants by // specifying a TenantID attribute different from their own. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToListenerCreateMap() +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Listener, error) { + b, err := build.RequestBody(opts, "listener") + if err != nil { + return nil, err + } + + // POST /v3/{project_id}/elb/listeners + raw, err := client.Post(client.ServiceURL("listeners"), b, nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*Listener, error) { if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("listeners"), b, &r.Body, nil) - return + + var res Listener + err = extract.IntoStructPtr(raw.Body, &res, "listener") + return &res, err } diff --git a/openstack/elb/v3/listeners/Get.go b/openstack/elb/v3/listeners/Get.go index d371f348e..0c8411e81 100644 --- a/openstack/elb/v3/listeners/Get.go +++ b/openstack/elb/v3/listeners/Get.go @@ -1,9 +1,77 @@ package listeners -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" +) // Get retrieves a particular Listeners based on its unique ID. func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { _, r.Err = client.Get(client.ServiceURL("listeners", id), &r.Body, nil) return } + +// Listener is the primary load balancing configuration object that specifies +// the loadbalancer and port on which client traffic is received, as well +// as other details such as the load balancing method to be use, protocol, etc. +type Listener struct { + // The unique ID for the Listener. + ID string `json:"id"` + // The administrative state of the Listener. A valid value is true (UP) or false (DOWN). + AdminStateUp bool `json:"admin_state_up"` + // The ID of the CA certificate used by the listener. + CAContainerRef string `json:"client_ca_tls_container_ref"` + // The maximum number of connections allowed for the Loadbalancer. + // Default is -1, meaning no limit. + ConnectionLimit int `json:"connection_limit"` + // Specifies the time when the listener was created. + CreatedAt string `json:"created_at"` + // Specifies the time when the listener was updated. + UpdatedAt string `json:"updated_at"` + // The UUID of default pool. Must have compatible protocol with listener. + DefaultPoolID string `json:"default_pool_id"` + // A reference to a Barbican container of TLS secrets. + DefaultTlsContainerRef string `json:"default_tls_container_ref"` + // Provides supplementary information about the Listener. + Description string `json:"description"` + // whether to use HTTP2. + Http2Enable bool `json:"http2_enable"` + // A list of load balancer IDs. + Loadbalancers []structs.ResourceRef `json:"loadbalancers"` + // Specifies the Listener Name. + Name string `json:"name"` + // Specifies the ProjectID where the listener is used. + ProjectID string `json:"project_id"` + // The protocol to loadbalancer. A valid value is TCP, HTTP, or HTTPS. + Protocol string `json:"protocol"` + // The port on which to listen to client traffic that is associated with the + // Loadbalancer. A valid value is from 0 to 65535. + ProtocolPort int `json:"protocol_port"` + // The list of references to TLS secrets. + SniContainerRefs []string `json:"sni_container_refs"` + // SNI certificates wildcard. + SniMatchAlgo string `json:"sni_match_algo"` + // Lists the Tags. + Tags []tags.ResourceTag `json:"tags"` + // Specifies the security policy used by the listener. + TlsCiphersPolicy string `json:"tls_ciphers_policy"` + // + SecurityPolicy string `json:"security_policy_id"` + // Whether enable member retry + EnableMemberRetry bool `json:"enable_member_retry"` + // The keepalive timeout of the Listener. + KeepAliveTimeout int `json:"keepalive_timeout"` + // The client timeout of the Listener. + ClientTimeout int `json:"client_timeout"` + // The member timeout of the Listener. + MemberTimeout int `json:"member_timeout"` + // The ipgroup of the Listener. + IpGroup IpGroup `json:"ipgroup"` + // The http insert headers of the Listener. + InsertHeaders InsertHeaders `json:"insert_headers"` + // Transparent client ip enable + TransparentClientIP bool `json:"transparent_client_ip_enable"` + // Enhance L7policy enable + EnhanceL7policy bool `json:"enhance_l7policy_enable"` +} diff --git a/openstack/elb/v3/listeners/Update.go b/openstack/elb/v3/listeners/Update.go index 38fa192be..295156c81 100644 --- a/openstack/elb/v3/listeners/Update.go +++ b/openstack/elb/v3/listeners/Update.go @@ -13,68 +13,57 @@ type UpdateOpts struct { // The administrative state of the Listener. A valid value is true (UP) // or false (DOWN). AdminStateUp *bool `json:"admin_state_up,omitempty"` - // the ID of the CA certificate used by the listener. CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"` - // The ID of the default pool with which the Listener is associated. DefaultPoolID string `json:"default_pool_id,omitempty"` - // A reference to a container of TLS secrets. DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"` - // Provides supplementary information about the Listener. Description *string `json:"description,omitempty"` - // whether to use HTTP2. Http2Enable *bool `json:"http2_enable,omitempty"` - // Specifies the Listener name. Name *string `json:"name,omitempty"` - // A list of references to TLS secrets. SniContainerRefs *[]string `json:"sni_container_refs,omitempty"` - // Specifies how wildcard domain name matches with the SNI certificates used by the listener. // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. // The default value is wildcard. SniMatchAlgo string `json:"sni_match_algo,omitempty"` - // Specifies the security policy used by the listener. TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"` - // Specifies the ID of the custom security policy. // Note: // This parameter is available only for HTTPS listeners added to a dedicated load balancer. // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). SecurityPolicy string `json:"security_policy_id,omitempty"` - // Whether enable member retry EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` - // The keepalive timeout of the Listener. KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` - // The client timeout of the Listener. ClientTimeout int `json:"client_timeout,omitempty"` - // The member timeout of the Listener. MemberTimeout int `json:"member_timeout,omitempty"` - // The IpGroup of the Listener. IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"` - // The http insert headers of the Listener. InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` - // Transparent client ip enable TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` - // Enhance L7policy enable EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` } +type IpGroupUpdate struct { + // + IpGroupId string `json:"ipgroup_id,omitempty"` + // + Type string `json:"type,omitempty"` +} + // ToListenerUpdateMap builds a request body from UpdateOpts. func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { return golangsdk.BuildRequestBody(opts, "listener") diff --git a/openstack/elb/v3/listeners/requests.go b/openstack/elb/v3/listeners/requests.go deleted file mode 100644 index e68e8e2d1..000000000 --- a/openstack/elb/v3/listeners/requests.go +++ /dev/null @@ -1,30 +0,0 @@ -package listeners - -// Protocol represents a listener protocol. -type Protocol string - -// Supported attributes for create/update operations. -const ( - ProtocolTCP Protocol = "TCP" - ProtocolUDP Protocol = "UDP" - ProtocolHTTP Protocol = "HTTP" - ProtocolHTTPS Protocol = "HTTPS" -) - -type IpGroup struct { - IpGroupID string `json:"ipgroup_id" required:"true"` - Enable *bool `json:"enable_ipgroup,omitempty"` - Type string `json:"type,omitempty"` -} - -type InsertHeaders struct { - ForwardedELBIP *bool `json:"X-Forwarded-ELB-IP,omitempty"` - ForwardedPort *bool `json:"X-Forwarded-Port,omitempty"` - ForwardedForPort *bool `json:"X-Forwarded-For-Port,omitempty"` - ForwardedHost *bool `json:"X-Forwarded-Host" required:"true"` -} - -type IpGroupUpdate struct { - IpGroupId string `json:"ipgroup_id,omitempty"` - Type string `json:"type,omitempty"` -} diff --git a/openstack/elb/v3/listeners/results.go b/openstack/elb/v3/listeners/results.go index 5d2430ce3..818f47f67 100644 --- a/openstack/elb/v3/listeners/results.go +++ b/openstack/elb/v3/listeners/results.go @@ -2,101 +2,9 @@ package listeners import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// Listener is the primary load balancing configuration object that specifies -// the loadbalancer and port on which client traffic is received, as well -// as other details such as the load balancing method to be use, protocol, etc. -type Listener struct { - // The unique ID for the Listener. - ID string `json:"id"` - - // The administrative state of the Listener. A valid value is true (UP) or false (DOWN). - AdminStateUp bool `json:"admin_state_up"` - - // The ID of the CA certificate used by the listener. - CAContainerRef string `json:"client_ca_tls_container_ref"` - - // The maximum number of connections allowed for the Loadbalancer. - // Default is -1, meaning no limit. - ConnectionLimit int `json:"connection_limit"` - - // Specifies the time when the listener was created. - CreatedAt string `json:"created_at"` - - // Specifies the time when the listener was updated. - UpdatedAt string `json:"updated_at"` - - // The UUID of default pool. Must have compatible protocol with listener. - DefaultPoolID string `json:"default_pool_id"` - - // A reference to a Barbican container of TLS secrets. - DefaultTlsContainerRef string `json:"default_tls_container_ref"` - - // Provides supplementary information about the Listener. - Description string `json:"description"` - - // whether to use HTTP2. - Http2Enable bool `json:"http2_enable"` - - // A list of load balancer IDs. - Loadbalancers []structs.ResourceRef `json:"loadbalancers"` - - // Specifies the Listener Name. - Name string `json:"name"` - - // Specifies the ProjectID where the listener is used. - ProjectID string `json:"project_id"` - - // The protocol to loadbalancer. A valid value is TCP, HTTP, or HTTPS. - Protocol string `json:"protocol"` - - // The port on which to listen to client traffic that is associated with the - // Loadbalancer. A valid value is from 0 to 65535. - ProtocolPort int `json:"protocol_port"` - - // The list of references to TLS secrets. - SniContainerRefs []string `json:"sni_container_refs"` - - // SNI certificates wildcard. - SniMatchAlgo string `json:"sni_match_algo"` - - // Lists the Tags. - Tags []tags.ResourceTag `json:"tags"` - - // Specifies the security policy used by the listener. - TlsCiphersPolicy string `json:"tls_ciphers_policy"` - - SecurityPolicy string `json:"security_policy_id"` - - // Whether enable member retry - EnableMemberRetry bool `json:"enable_member_retry"` - - // The keepalive timeout of the Listener. - KeepAliveTimeout int `json:"keepalive_timeout"` - - // The client timeout of the Listener. - ClientTimeout int `json:"client_timeout"` - - // The member timeout of the Listener. - MemberTimeout int `json:"member_timeout"` - - // The ipgroup of the Listener. - IpGroup IpGroup `json:"ipgroup"` - - // The http insert headers of the Listener. - InsertHeaders InsertHeaders `json:"insert_headers"` - - // Transparent client ip enable - TransparentClientIP bool `json:"transparent_client_ip_enable"` - - // Enhance L7policy enable - EnhanceL7policy bool `json:"enhance_l7policy_enable"` -} - type commonResult struct { golangsdk.Result } From 45851b80c88ee08bb77a2a78555d72d4e6183f77 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 11:01:06 +0200 Subject: [PATCH 16/54] Delete --- openstack/elb/v3/listeners/Delete.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openstack/elb/v3/listeners/Delete.go b/openstack/elb/v3/listeners/Delete.go index cf4cdb8ad..4cfecfabf 100644 --- a/openstack/elb/v3/listeners/Delete.go +++ b/openstack/elb/v3/listeners/Delete.go @@ -3,7 +3,7 @@ package listeners import "github.com/opentelekomcloud/gophertelekomcloud" // Delete will permanently delete a particular Listeners based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("listeners", id), nil) +func Delete(client *golangsdk.ServiceClient, id string) (err error) { + _, err = client.Delete(client.ServiceURL("listeners", id), nil) return } From 29422be13cfca4d54cafeec6569737496068f238 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 11:08:52 +0200 Subject: [PATCH 17/54] Get --- openstack/elb/v3/listeners/Delete.go | 1 + openstack/elb/v3/listeners/Get.go | 155 ++++++++++++++++++++++----- 2 files changed, 131 insertions(+), 25 deletions(-) diff --git a/openstack/elb/v3/listeners/Delete.go b/openstack/elb/v3/listeners/Delete.go index 4cfecfabf..edb0030ef 100644 --- a/openstack/elb/v3/listeners/Delete.go +++ b/openstack/elb/v3/listeners/Delete.go @@ -4,6 +4,7 @@ import "github.com/opentelekomcloud/gophertelekomcloud" // Delete will permanently delete a particular Listeners based on its unique ID. func Delete(client *golangsdk.ServiceClient, id string) (err error) { + // DELETE /v3/{project_id}/elb/listeners/{listener_id} _, err = client.Delete(client.ServiceURL("listeners", id), nil) return } diff --git a/openstack/elb/v3/listeners/Get.go b/openstack/elb/v3/listeners/Get.go index 0c8411e81..0594beb44 100644 --- a/openstack/elb/v3/listeners/Get.go +++ b/openstack/elb/v3/listeners/Get.go @@ -7,71 +7,176 @@ import ( ) // Get retrieves a particular Listeners based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("listeners", id), &r.Body, nil) - return +func Get(client *golangsdk.ServiceClient, id string) (*Listener, error) { + // GET /v3/{project_id}/elb/listeners/{listener_id} + raw, err := client.Get(client.ServiceURL("listeners", id), nil, nil) + return extra(err, raw) } // Listener is the primary load balancing configuration object that specifies // the loadbalancer and port on which client traffic is received, as well // as other details such as the load balancing method to be use, protocol, etc. type Listener struct { - // The unique ID for the Listener. + // Specifies the listener ID. ID string `json:"id"` - // The administrative state of the Listener. A valid value is true (UP) or false (DOWN). + // Specifies the administrative status of the listener. The value can only be true. + // This parameter is unsupported. Please do not use it. AdminStateUp bool `json:"admin_state_up"` - // The ID of the CA certificate used by the listener. + // Specifies the ID of the CA certificate used by the listener. This parameter is available only when type is set to client. CAContainerRef string `json:"client_ca_tls_container_ref"` - // The maximum number of connections allowed for the Loadbalancer. - // Default is -1, meaning no limit. + // Specifies the maximum number of connections that the load balancer can establish with backend servers. The value -1 indicates that the number of connections is not limited. + // + // This parameter is unsupported. Please do not use it. ConnectionLimit int `json:"connection_limit"` - // Specifies the time when the listener was created. + // Specifies the time when the listener was created, in the format of yyyy-MM-dd''T''HH:mm:ss''Z'', for example, 2021-07-30T12:03:44Z. CreatedAt string `json:"created_at"` // Specifies the time when the listener was updated. UpdatedAt string `json:"updated_at"` - // The UUID of default pool. Must have compatible protocol with listener. + // Specifies the ID of the default backend server group. If there is no matched forwarding policy, requests are forwarded to the default backend server. DefaultPoolID string `json:"default_pool_id"` - // A reference to a Barbican container of TLS secrets. + // Specifies the ID of the server certificate used by the listener. DefaultTlsContainerRef string `json:"default_tls_container_ref"` - // Provides supplementary information about the Listener. + // Provides supplementary information about the listener. Description string `json:"description"` - // whether to use HTTP2. + // Specifies whether to use HTTP/2 if you want the clients to use HTTP/2 to communicate with the load balancer. However, connections between the load balancer and backend servers still use HTTP/1.x by default. + // + // This parameter is available only for HTTPS listeners. If you configure this parameter for listeners with other protocols, it will not take effect. Http2Enable bool `json:"http2_enable"` - // A list of load balancer IDs. + // Specifies the ID of the load balancer that the listener is added to. A listener can be added to only one load balancer. Loadbalancers []structs.ResourceRef `json:"loadbalancers"` // Specifies the Listener Name. Name string `json:"name"` // Specifies the ProjectID where the listener is used. ProjectID string `json:"project_id"` - // The protocol to loadbalancer. A valid value is TCP, HTTP, or HTTPS. + // Specifies the protocol used by the listener. + // + // The value can be TCP, HTTP, UDP, HTTPS, or TERMINATED_HTTPS. + // + // Note: + // + // Protocol used by HTTPS listeners added to a shared load balancer can only be set to TERMINATED_HTTPS. If HTTPS is passed, the value will be automatically changed to TERMINATED_HTTPS. + // + // Protocol used by HTTPS listeners added to a dedicated load balancer can only be set to HTTPS. If TERMINATED_HTTPS is passed, the value will be automatically changed to HTTPS. Protocol string `json:"protocol"` // The port on which to listen to client traffic that is associated with the // Loadbalancer. A valid value is from 0 to 65535. ProtocolPort int `json:"protocol_port"` - // The list of references to TLS secrets. + // Specifies the IDs of SNI certificates (server certificates with domain names) used by the listener. + // + // Note: + // + // The domain names of all SNI certificates must be unique. + // + // The total number of domain names of all SNI certificates cannot exceed 30. SniContainerRefs []string `json:"sni_container_refs"` - // SNI certificates wildcard. + // Specifies how wildcard domain name matches with the SNI certificates used by the listener. + // + // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. + // + // The default value is wildcard. SniMatchAlgo string `json:"sni_match_algo"` // Lists the Tags. Tags []tags.ResourceTag `json:"tags"` // Specifies the security policy used by the listener. + // + // Values: tls-1-0-inherit,tls-1-0, tls-1-1, tls-1-2,tls-1-2-strict, tls-1-2-fs, tls-1-0-with-1-3, tls-1-2-fs-with-1-3, hybrid-policy-1-0, and tls-1-0 (default). + // + // Note: + // + // This parameter will take effect only for HTTPS listeners added to a dedicated load balancer. + // + // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // + // The priority of the encryption suite from high to low is: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). TlsCiphersPolicy string `json:"tls_ciphers_policy"` + // Specifies the ID of the custom security policy. + // + // Note: + // + // This parameter is available only for HTTPS listeners added to a dedicated load balancer. + // + // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. // + // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). SecurityPolicy string `json:"security_policy_id"` - // Whether enable member retry + // Specifies whether to enable health check retries for backend servers. The value can be true (enable health check retries) or false (disable health check retries). The default value is true. Note: + // + // If a shared load balancer is associated, this parameter is available only when protocol is set to HTTP or TERMINATED_HTTPS. + // + // If a dedicated load balancer is associated, this parameter is available only when protocol is set to HTTP, or HTTPS. EnableMemberRetry bool `json:"enable_member_retry"` - // The keepalive timeout of the Listener. + // Specifies the idle timeout duration, in seconds. If there are no requests reaching the load balancer after the idle timeout duration elapses, the load balancer will disconnect the connection with the client and establish a new connection when there is a new request. + // + // For TCP listeners, the value ranges from 10 to 4000, and the default value is 300. + // + // For HTTP and HTTPS listeners, the value ranges from 1 to 4000, and the default value is 60. + // + // For UDP listeners, this parameter does not take effect. KeepAliveTimeout int `json:"keepalive_timeout"` - // The client timeout of the Listener. + // Specifies the timeout duration for waiting for a response from a client, in seconds. There are two situations: + // + // If the client fails to send a request header to the load balancer within the timeout duration, the request will be interrupted. + // + // If the interval between two consecutive request bodies reaching the load balancer is greater than the timeout duration, the connection will be disconnected. + // + // The value ranges from 1 to 300, and the default value is 60. + // + // This parameter is available only for HTTP and HTTPS listeners. ClientTimeout int `json:"client_timeout"` - // The member timeout of the Listener. + // Specifies the timeout duration for waiting for a response from a backend server, in seconds. If the backend server fails to respond after the timeout duration elapses, the load balancer will stop waiting and return HTTP 504 Gateway Timeout to the client. + // + // The value ranges from 1 to 300, and the default value is 60. + // + // This parameter is available only for HTTP and HTTPS listeners. MemberTimeout int `json:"member_timeout"` - // The ipgroup of the Listener. + // Specifies the IP address group associated with the listener. IpGroup IpGroup `json:"ipgroup"` - // The http insert headers of the Listener. + // Specifies the HTTP header fields that can transmit required information to backend servers. For example, the X-Forwarded-ELB-IP header field can transmit the EIP of the load balancer to backend servers. InsertHeaders InsertHeaders `json:"insert_headers"` - // Transparent client ip enable + // Specifies whether to pass source IP addresses of the clients to backend servers. + // + // TCP or UDP listeners of shared load balancers: The value can be true or false, and the default value is false if this parameter is not passed. + // + // HTTP or HTTPS listeners of shared load balancers: The value can only be true, and the default value is true if this parameter is not passed. + // + // All listeners of dedicated load balancers: The value can only be true, and the default value is true if this parameter is not passed. + // + // Note: + // + // If this function is enabled, the load balancer communicates with backend servers using their real IP addresses. Ensure that security group rules and access control policies are correctly configured. + // + // If this function is enabled, a server cannot serve as both a backend server and a client. + // + // If this function is enabled, backend server specifications cannot be changed. TransparentClientIP bool `json:"transparent_client_ip_enable"` - // Enhance L7policy enable + // Specifies whether to enable advanced forwarding. The value can be true (enable advanced forwarding) or false (disable advanced forwarding), and the default value is false. + // + // If this function is enabled, action can be set to REDIRECT_TO_URL (requests will be redirected to another URL) or Fixed_RESPONSE (a fixed response body will be returned to clients). + // + // Parameters priority, redirect_url_config, and fixed_response_config can be specified in a forwarding policy. + // + // Parameter type can be set to METHOD, HEADER, QUERY_STRING, or SOURCE_IP for a forwarding rule . + // + // If type is set to HOST_NAME for a forwarding rule, the value parameter of the forwarding rule supports wildcard asterisks (*). + // + // The conditions parameter can be specified for forwarding rules. + // + // This parameter is not available in eu-nl region. Please do not use it. + // + // Default: false EnhanceL7policy bool `json:"enhance_l7policy_enable"` + // Specifies the QUIC configuration for the current listener. This parameter is valid only when protocol is set to HTTPS. + // + // For a TCP/UDP/HTTP/QUIC listener, if this parameter is not left blank, an error will be reported. + // + // Note + // + // The client sends a normal HTTP request that contains information indicating that the QUIC protocol is supported. + // + // If QUIC upgrade is enabled for the listeners, QUIC port and version information will be added to the response header. + // + // When the client sends both HTTPS and QUIC requests to the server, if the QUIC request is successfully sent, QUIC protocol will be used for subsequent communications. + // + // QUIC protocol is not supported. + QuicConfig QuicConfigOption `json:"quic_config"` } From 049227ad9227ea11a8d58cf2a165d531321cc47e Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 11:19:48 +0200 Subject: [PATCH 18/54] List --- openstack/elb/v3/listeners/List.go | 198 +++++++++++++++++++++----- openstack/elb/v3/listeners/results.go | 22 --- 2 files changed, 161 insertions(+), 59 deletions(-) diff --git a/openstack/elb/v3/listeners/List.go b/openstack/elb/v3/listeners/List.go index c41e359ba..61bf3ea85 100644 --- a/openstack/elb/v3/listeners/List.go +++ b/openstack/elb/v3/listeners/List.go @@ -2,53 +2,177 @@ package listeners import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -type ListOptsBuilder interface { - ToListenerListQuery() (string, error) -} - type ListOpts struct { - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` - - ProtocolPort []int `q:"protocol_port"` - Protocol []Protocol `q:"protocol"` - Description []string `q:"description"` - DefaultTLSContainerRef []string `q:"default_tls_container_ref"` - ClientCATLSContainerRef []string `q:"client_ca_tls_container_ref"` - DefaultPoolID []string `q:"default_pool_id"` - ID []string `q:"id"` - Name []string `q:"name"` - LoadBalancerID []string `q:"loadbalancer_id"` - TLSCiphersPolicy []string `q:"tls_ciphers_policy"` - MemberAddress []string `q:"member_address"` - MemberDeviceID []string `q:"member_device_id"` - MemberTimeout []int `q:"member_timeout"` - ClientTimeout []int `q:"client_timeout"` - KeepAliveTimeout []int `q:"keepalive_timeout"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit int `q:"limit"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse bool `q:"page_reverse"` + // Specifies the port used by the listener. + // + // Multiple ports can be queried in the format of protocol_port=xxx&protocol_port=xxx. + ProtocolPort []int `q:"protocol_port"` + // Specifies the protocol used by the listener. The value can be TCP, HTTP, UDP, HTTPS or TERMINATED_HTTPS. Note: TERMINATED_HTTPS is only available for the listeners of shared load balancers. + // + // Multiple protocols can be queried in the format of protocol=xxx&protocol=xxx. + Protocol []string `q:"protocol"` + // Provides supplementary information about the listener. + // + // Multiple descriptions can be queried in the format of description=xxx&description=xxx. + Description []string `q:"description"` + // Specifies the ID of the server certificate used by the listener. + // + // Multiple IDs can be queried in the format of default_tls_container_ref=xxx&default_tls_container_ref=xxx. + DefaultTLSContainerRef []string `q:"default_tls_container_ref"` + // Specifies the ID of the CA certificate used by the listener. + // + // Multiple IDs can be queried in the format of client_ca_tls_container_ref=xxx&client_ca_tls_container_ref=xxx. + ClientCATLSContainerRef []string `q:"client_ca_tls_container_ref"` + // Specifies the administrative status of the listener. The value can only be true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the maximum number of connections that the load balancer can establish with backend servers. The value -1 indicates that the number of connections is not limited. + // + // Multiple values can be queried in the format of connection_limit=xxx&connection_limit=xxx. + // + // This parameter is unsupported. Please do not use it. + ConnectionLimit []int `q:"connection_limit"` + // Specifies the ID of the default backend server group. If there is no matched forwarding policy, requests will be routed to the default backend server. + // + // Multiple IDs can be queried in the format of default_pool_id=xxx&default_pool_id=xxx. + DefaultPoolID []string `q:"default_pool_id"` + // Specifies the listener ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + ID []string `q:"id"` + // Specifies the name of the listener added to the load balancer. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Specifies whether to use HTTP/2 if you want the clients to use HTTP/2 to communicate with the listener. However, connections between the load balancer and backend servers still use HTTP/1.x by default. + // + // This parameter is available only for HTTPS listeners. If you configure this parameter for listeners with other protocols, it will not take effect. + Http2Enable *bool `q:"http2_enable"` + // Specifies the ID of the load balancer that the listener is added to. + // + // Multiple IDs can be queried in the format of loadbalancer_id=xxx&loadbalancer_id=xxx. + LoadBalancerID []string `q:"loadbalancer_id"` + // Specifies the security policy used by the listener. + // + // Multiple security policies can be queried in the format of tls_ciphers_policy=xxx&tls_ciphers_policy=xxx. + TLSCiphersPolicy []string `q:"tls_ciphers_policy"` + // Specifies the private IP address bound to the backend server. This parameter is used only as a query condition and is not included in the response. + // + // Multiple IP addresses can be queried in the format of member_address=xxx&member_address=xxx. + MemberAddress []string `q:"member_address"` + // Specifies the ID of the cloud server that serves as a backend server. This parameter is used only as a query condition and is not included in the response. + // + // Multiple IDs can be queried in the format of member_device_id=xxx&member_device_id=xxx. + MemberDeviceID []string `q:"member_device_id"` + // Specifies whether to enable health check retries for backend servers. + // + // The value can be true (enable health check retries) or false (disable health check retries). + EnableMemberRetry *bool `q:"enable_member_retry"` + // Specifies the timeout duration for waiting for a response from a backend server, in seconds. If the backend server fails to respond after the timeout duration elapses, the load balancer will stop waiting and return HTTP 504 Gateway Timeout to the client. + // + // The value ranges from 1 to 300. + // + // Multiple durations can be queried in the format of member_timeout=xxx&member_timeout=xxx. + MemberTimeout []int `q:"member_timeout"` + // Specifies the timeout duration for waiting for a response from a client, in seconds. There are two situations: + // + // If the client fails to send a request header to the load balancer within the timeout duration, the request will be interrupted. + // + // If the interval between two consecutive request bodies reaching the load balancer is greater than the timeout duration, the connection will be disconnected. + // + // The value ranges from 1 to 300. + // + // Multiple durations can be queried in the format of client_timeout=xxx&client_timeout=xxx. + ClientTimeout []int `q:"client_timeout"` + // Specifies the idle timeout duration, in seconds. If there are no requests reaching the load balancer after the idle timeout duration elapses, the load balancer will disconnect the connection with the client and establish a new connection when there is a new request. + // + // For TCP listeners, the value ranges from 10 to 4000. + // + // For HTTP, HTTPS, and TERMINATED_HTTPS listeners, the value ranges from 1 to 4000. + // + // For UDP listeners, this parameter does not take effect. + // + // Multiple durations can be queried in the format of keepalive_timeout=xxx&keepalive_timeout=xxx. + KeepAliveTimeout []int `q:"keepalive_timeout"` + // Specifies whether to pass source IP addresses of the clients to backend servers. + // + // This parameter is only available for TCP or UDP listeners of shared load balancers. + // + // true: Source IP addresses will be passed to backend servers. + // + // false: Source IP addresses will not be passed to backend servers. + TransparentClientIpEnable *bool `q:"transparent_client_ip_enable"` + // Specifies whether to enable advanced forwarding. If you enable this function, you can configure more flexible forwarding policies and rules. + // + // true: Enable advanced forwarding. + // + // false: Disable advanced forwarding. This parameter is not available in eu-nl region. Please do not use it. + EnhanceL7policyEnable *bool `q:"enhance_l7policy_enable"` + // Specifies the backend server ID. This parameter is used only as a query condition and is not included in the response. Multiple IDs can be queried in the format of member_instance_id=xxx&member_instance_id=xxx. + MemberInstanceId []string `q:"member_instance_id"` } -func (opts ListOpts) ToListenerListQuery() (string, error) { +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { q, err := golangsdk.BuildQueryString(opts) if err != nil { - return "", err + return pagination.Pager{Err: err} } - return q.String(), nil -} -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("listeners") - if opts != nil { - q, err := opts.ToListenerListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += q - } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + // GET /v3/{project_id}/elb/listeners + return pagination.NewPager(client, client.ServiceURL("listeners")+q.String(), func(r pagination.PageResult) pagination.Page { return ListenerPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +type ListenerPage struct { + pagination.PageWithInfo +} + +func (p ListenerPage) IsEmpty() (bool, error) { + l, err := ExtractListeners(p) + if err != nil { + return false, err + } + return len(l) == 0, nil +} + +func ExtractListeners(r pagination.Page) ([]Listener, error) { + var res []Listener + err := extract.IntoSlicePtr(r.(ListenerPage).BodyReader(), &res, "listeners") + return res, err +} diff --git a/openstack/elb/v3/listeners/results.go b/openstack/elb/v3/listeners/results.go index 818f47f67..5dde9ef90 100644 --- a/openstack/elb/v3/listeners/results.go +++ b/openstack/elb/v3/listeners/results.go @@ -2,7 +2,6 @@ package listeners import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type commonResult struct { @@ -42,24 +41,3 @@ type UpdateResult struct { type DeleteResult struct { golangsdk.ErrResult } - -type ListenerPage struct { - pagination.PageWithInfo -} - -func (p ListenerPage) IsEmpty() (bool, error) { - l, err := ExtractListeners(p) - if err != nil { - return false, err - } - return len(l) == 0, nil -} - -func ExtractListeners(r pagination.Page) ([]Listener, error) { - var s []Listener - err := (r.(ListenerPage)).ExtractIntoSlicePtr(&s, "listeners") - if err != nil { - return nil, err - } - return s, nil -} From 1be04279b98cd15d731aa41c3363e92f582264af Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 11:28:22 +0200 Subject: [PATCH 19/54] Update --- openstack/elb/v3/listeners/Create.go | 5 +- openstack/elb/v3/listeners/Update.go | 176 +++++++++++++++++++------- openstack/elb/v3/listeners/results.go | 43 ------- 3 files changed, 134 insertions(+), 90 deletions(-) delete mode 100644 openstack/elb/v3/listeners/results.go diff --git a/openstack/elb/v3/listeners/Create.go b/openstack/elb/v3/listeners/Create.go index 758d76be6..b8c98b5db 100644 --- a/openstack/elb/v3/listeners/Create.go +++ b/openstack/elb/v3/listeners/Create.go @@ -278,10 +278,7 @@ type QuicConfigOption struct { } // Create is an operation which provisions a new Listeners 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. -// +// configuration defined in the CreateOpts struct. // Users with an admin role can create Listeners on behalf of other tenants by // specifying a TenantID attribute different from their own. func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Listener, error) { diff --git a/openstack/elb/v3/listeners/Update.go b/openstack/elb/v3/listeners/Update.go index 295156c81..f853b3b90 100644 --- a/openstack/elb/v3/listeners/Update.go +++ b/openstack/elb/v3/listeners/Update.go @@ -1,84 +1,174 @@ package listeners -import "github.com/opentelekomcloud/gophertelekomcloud" - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToListenerUpdateMap() (map[string]interface{}, error) -} +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) // UpdateOpts represents options for updating a Listener. type UpdateOpts struct { - // The administrative state of the Listener. A valid value is true (UP) - // or false (DOWN). + // Specifies the administrative status of the listener. The value can only be true. + // + // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` - // the ID of the CA certificate used by the listener. + // Specifies the ID of the CA certificate used by the listener. This parameter is available only when type is set to client. CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"` - // The ID of the default pool with which the Listener is associated. + // Specifies the ID of the default backend server group. If there is no matched forwarding policy, requests are forwarded to the default backend server. + // + // Minimum: 1 + // + // Maximum: 36 DefaultPoolID string `json:"default_pool_id,omitempty"` - // A reference to a container of TLS secrets. + // Specifies the ID of the server certificate used by the listener. This parameter is available only when the listener's protocol is HTTPS and type is set to server. DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"` - // Provides supplementary information about the Listener. + // Provides supplementary information about the listener. + // + // Minimum: 0 + // + // Maximum: 255 Description *string `json:"description,omitempty"` - // whether to use HTTP2. + // Specifies whether to use HTTP/2 if you want the clients to use HTTP/2 to communicate with the load balancer. However, connections between the load balancer and backend servers still use HTTP/1.x by default. + // + // This parameter is available only for HTTPS listeners. If you configure this parameter for listeners with other protocols, it will not take effect. Http2Enable *bool `json:"http2_enable,omitempty"` - // Specifies the Listener name. + // Specifies the listener name. + // + // Minimum: 0 + // + // Maximum: 255 Name *string `json:"name,omitempty"` - // A list of references to TLS secrets. + // Specifies the IDs of SNI certificates (server certificates with domain names) used by the listener. + // + // Note: + // + // The domain names of all SNI certificates must be unique. + // + // The total number of domain names of all SNI certificates cannot exceed 30. SniContainerRefs *[]string `json:"sni_container_refs,omitempty"` // Specifies how wildcard domain name matches with the SNI certificates used by the listener. + // // longest_suffix indicates longest suffix match. wildcard indicates wildcard match. + // // The default value is wildcard. SniMatchAlgo string `json:"sni_match_algo,omitempty"` // Specifies the security policy used by the listener. + // + // Values: tls-1-0-inherit,tls-1-0, tls-1-1, tls-1-2,tls-1-2-strict, tls-1-2-fs, tls-1-0-with-1-3, tls-1-2-fs-with-1-3, hybrid-policy-1-0, and tls-1-0 (default). + // + // Note: + // + // This parameter will take effect only for HTTPS listeners added to a dedicated load balancer. + // + // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // + // The priority of the encryption suite from high to low is: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"` // Specifies the ID of the custom security policy. + // // Note: + // // This parameter is available only for HTTPS listeners added to a dedicated load balancer. + // // If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect. + // // The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa). + // + // Minimum: 1 + // + // Maximum: 36 SecurityPolicy string `json:"security_policy_id,omitempty"` - // Whether enable member retry + // Specifies whether to enable health check retries for backend servers. The value can be true (enable health check retries) or false (disable health check retries). The default value is true. Note: + // + // If a shared load balancer is associated, this parameter is available only when protocol is set to HTTP or TERMINATED_HTTPS. + // + // If a dedicated load balancer is associated, this parameter is available only when protocol is set to HTTP, or HTTPS. EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` - // The keepalive timeout of the Listener. + // Specifies the idle timeout duration, in seconds. If there are no requests reaching the load balancer after the idle timeout duration elapses, the load balancer will disconnect the connection with the client and establish a new connection when there is a new request. + // + // For TCP listeners, the value ranges from 10 to 4000. + // + // For HTTP and HTTPS listeners, the value ranges from 1 to 4000. + // + // For UDP listeners, this parameter does not take effect. KeepAliveTimeout int `json:"keepalive_timeout,omitempty"` - // The client timeout of the Listener. + // Specifies the timeout duration for waiting for a response from a client, in seconds. + // + // This parameter is available only for HTTP and HTTPS listeners. The value ranges from 1 to 300. + // + // Minimum: 1 + // + // Maximum: 300 ClientTimeout int `json:"client_timeout,omitempty"` - // The member timeout of the Listener. + // Specifies the timeout duration for waiting for a response from a backend server, in seconds. If the backend server fails to respond after the timeout duration elapses, the load balancer will stop waiting and return HTTP 504 Gateway Timeout to the client. + // + // The value ranges from 1 to 300. + // + // This parameter is available only for HTTP and HTTPS listeners. + // + // Minimum: 1 + // + // Maximum: 300 MemberTimeout int `json:"member_timeout,omitempty"` - // The IpGroup of the Listener. - IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"` - // The http insert headers of the Listener. + // Specifies the IP address group associated with the listener. + IpGroup *IpGroup `json:"ipgroup,omitempty"` + // Specifies the HTTP header fields that can transmit required information to backend servers. For example, the X-Forwarded-ELB-IP header field can transmit the EIP of the load balancer to backend servers. InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` - // Transparent client ip enable + // Specifies whether to pass source IP addresses of the clients to backend servers. + // + // TCP or UDP listeners of shared load balancers: The value can be true or false, and the default value is false if this parameter is not passed. + // + // HTTP or HTTPS listeners of shared load balancers: The value can only be true, and the default value is true if this parameter is not passed. + // + // All listeners of dedicated load balancers: The value can only be true, and the default value is true if this parameter is not passed. + // + // Note: + // + // If this function is enabled, the load balancer communicates with backend servers using their real IP addresses. Ensure that security group rules and access control policies are correctly configured. + // + // If this function is enabled, a server cannot serve as both a backend server and a client. + // + // If this function is enabled, backend server specifications cannot be changed. TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` - // Enhance L7policy enable + // Specifies whether to enable advanced forwarding. The value can be true (enable advanced forwarding) or false (disable advanced forwarding), and the default value is false. + // + // If this function is enabled, action can be set to REDIRECT_TO_URL (requests will be redirected to another URL) or Fixed_RESPONSE (a fixed response body will be returned to clients). + // + // Parameters priority, redirect_url_config, and fixed_response_config can be specified in a forwarding policy. + // + // Parameter type can be set to METHOD, HEADER, QUERY_STRING, or SOURCE_IP for a forwarding rule . + // + // If type is set to HOST_NAME for a forwarding rule, the value parameter of the forwarding rule supports wildcard asterisks (*). + // + // The conditions parameter can be specified for forwarding rules. + // + // This parameter is not available in eu-nl region. Please do not use it. EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` -} - -type IpGroupUpdate struct { + // Specifies the QUIC configuration for the current listener. This parameter is valid only when protocol is set to HTTPS. // - IpGroupId string `json:"ipgroup_id,omitempty"` + // For a TCP/UDP/HTTP/QUIC listener, if this parameter is not left blank, an error will be reported. // - Type string `json:"type,omitempty"` -} - -// ToListenerUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "listener") + // Note + // + // The client sends a normal HTTP request that contains information indicating that the QUIC protocol is supported. + // + // If QUIC upgrade is enabled for the listeners, QUIC port and version information will be added to the response header. + // + // When the client sends both HTTPS and QUIC requests to the server, if the QUIC request is successfully sent, QUIC protocol will be used for subsequent communications. + // + // QUIC protocol is not supported. + QuicConfig QuicConfigOption `json:"quic_config"` } -// Update is an operation which modifies the attributes of the specified -// Listener. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToListenerUpdateMap() +// Update is an operation which modifies the attributes of the specified Listener. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*Listener, error) { + // PUT /v3/{project_id}/elb/listeners/{listener_id} + b, err := build.RequestBody(opts, "listener") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("listeners", id), b, &r.Body, &golangsdk.RequestOpts{ + + raw, err := client.Put(client.ServiceURL("listeners", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) - return + return extra(err, raw) } diff --git a/openstack/elb/v3/listeners/results.go b/openstack/elb/v3/listeners/results.go deleted file mode 100644 index 5dde9ef90..000000000 --- a/openstack/elb/v3/listeners/results.go +++ /dev/null @@ -1,43 +0,0 @@ -package listeners - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -type commonResult struct { - golangsdk.Result -} - -// Extract is a function that accepts a result and extracts a listener. -func (r commonResult) Extract() (*Listener, error) { - s := new(Listener) - err := r.ExtractIntoStructPtr(s, "listener") - if err != nil { - return nil, err - } - return s, nil -} - -// CreateResult represents the result of a create operation. Call its Extract -// method to interpret it as a Listener. -type CreateResult struct { - commonResult -} - -// GetResult represents the result of a get operation. Call its Extract -// method to interpret it as a Listener. -type GetResult struct { - commonResult -} - -// UpdateResult represents the result of an update operation. Call its Extract -// method to interpret it as a Listener. -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 { - golangsdk.ErrResult -} From 34183ac39369b81971d0cc8da84433f9fac1178c Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 11:50:08 +0200 Subject: [PATCH 20/54] ACC --- .../openstack/elb/v3/certificates_test.go | 6 +-- acceptance/openstack/elb/v3/flavors_test.go | 2 +- acceptance/openstack/elb/v3/helpers.go | 10 ++--- acceptance/openstack/elb/v3/ipgroups_test.go | 8 ++-- acceptance/openstack/elb/v3/listeners_test.go | 18 +++++---- .../openstack/elb/v3/loadbalancers_test.go | 4 +- acceptance/openstack/elb/v3/members_test.go | 10 +++-- acceptance/openstack/elb/v3/monitors_test.go | 10 +++-- acceptance/openstack/elb/v3/policies_test.go | 38 +++++++++---------- acceptance/openstack/elb/v3/pools_test.go | 6 ++- acceptance/openstack/elb/v3/rules_test.go | 30 ++++++++------- .../openstack/elb/v3/security_policy_test.go | 30 +++++++-------- 12 files changed, 93 insertions(+), 79 deletions(-) diff --git a/acceptance/openstack/elb/v3/certificates_test.go b/acceptance/openstack/elb/v3/certificates_test.go index a9fc137c4..0eabc71ba 100644 --- a/acceptance/openstack/elb/v3/certificates_test.go +++ b/acceptance/openstack/elb/v3/certificates_test.go @@ -37,14 +37,14 @@ func TestCertificateLifecycle(t *testing.T) { emptyDescription := "" updateOpts := certificates.UpdateOpts{ Name: certName, - Description: &emptyDescription, + Description: emptyDescription, } - _, err = certificates.Update(client, certificateID, updateOpts).Extract() + _, err = certificates.Update(client, certificateID, updateOpts) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 certificate: %s", certificateID) - newCertificate, err := certificates.Get(client, certificateID).Extract() + newCertificate, err := certificates.Get(client, certificateID) th.AssertNoErr(t, err) th.AssertEquals(t, updateOpts.Name, newCertificate.Name) th.AssertEquals(t, emptyDescription, newCertificate.Description) diff --git a/acceptance/openstack/elb/v3/flavors_test.go b/acceptance/openstack/elb/v3/flavors_test.go index 92c859990..ba7d4894e 100644 --- a/acceptance/openstack/elb/v3/flavors_test.go +++ b/acceptance/openstack/elb/v3/flavors_test.go @@ -19,7 +19,7 @@ func TestFlavorsList(t *testing.T) { flavorsList, err := flavors.ExtractFlavors(flavorsPages) th.AssertNoErr(t, err) - zeroFlavor, err := flavors.Get(client, flavorsList[0].ID).Extract() + zeroFlavor, err := flavors.Get(client, flavorsList[0].ID) th.AssertNoErr(t, err) th.AssertDeepEquals(t, zeroFlavor, &flavorsList[0]) } diff --git a/acceptance/openstack/elb/v3/helpers.go b/acceptance/openstack/elb/v3/helpers.go index 650337002..14c5795fb 100644 --- a/acceptance/openstack/elb/v3/helpers.go +++ b/acceptance/openstack/elb/v3/helpers.go @@ -130,7 +130,7 @@ i1YhgnQbn5E0hz55OLu5jvOkKQjPCW+8Kg== Certificate: cert, } - certificate, err := certificates.Create(client, createOpts).Extract() + certificate, err := certificates.Create(client, createOpts) th.AssertNoErr(t, err) th.AssertEquals(t, createOpts.Name, certificate.Name) th.AssertEquals(t, createOpts.Description, certificate.Description) @@ -141,7 +141,7 @@ i1YhgnQbn5E0hz55OLu5jvOkKQjPCW+8Kg== func deleteCertificate(t *testing.T, client *golangsdk.ServiceClient, certificateID string) { t.Logf("Attempting to delete ELBv3 certificate: %s", certificateID) - err := certificates.Delete(client, certificateID).ExtractErr() + err := certificates.Delete(client, certificateID) th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 certificate: %s", certificateID) } @@ -184,13 +184,13 @@ func deletePool(t *testing.T, client *golangsdk.ServiceClient, poolID string) { func createListener(t *testing.T, client *golangsdk.ServiceClient, loadbalancerID string) string { listener, err := listeners.Create(client, listeners.CreateOpts{ LoadbalancerID: loadbalancerID, - Protocol: listeners.ProtocolHTTP, + Protocol: "HTTP", ProtocolPort: 80, - }).Extract() + }) th.AssertNoErr(t, err) return listener.ID } func deleteListener(t *testing.T, client *golangsdk.ServiceClient, listenerID string) { - th.AssertNoErr(t, listeners.Delete(client, listenerID).ExtractErr()) + th.AssertNoErr(t, listeners.Delete(client, listenerID)) } diff --git a/acceptance/openstack/elb/v3/ipgroups_test.go b/acceptance/openstack/elb/v3/ipgroups_test.go index 806f00282..a5c697744 100644 --- a/acceptance/openstack/elb/v3/ipgroups_test.go +++ b/acceptance/openstack/elb/v3/ipgroups_test.go @@ -81,16 +81,18 @@ func TestIpGroupsLifecycle(t *testing.T) { t.Logf("Attempting to create ELBv3 Listener with ipGroup association") listener, err := listeners.Create(client, listeners.CreateOpts{ LoadbalancerID: loadbalancerID, - Protocol: listeners.ProtocolHTTP, + Protocol: "HTTP", ProtocolPort: 80, EnhanceL7policy: pointerto.Bool(true), IpGroup: &listeners.IpGroup{ IpGroupID: ipGroup.ID, Enable: pointerto.Bool(true), }, - }).Extract() + }) th.AssertNoErr(t, err) - defer deleteListener(t, client, listener.ID) + t.Cleanup(func() { + deleteListener(t, client, listener.ID) + }) updatedIpList, err := ipgroups.UpdateIpList(client, ipGroup.ID, ipgroups.UpdateOpts{ IpList: []ipgroups.IpGroupOption{ diff --git a/acceptance/openstack/elb/v3/listeners_test.go b/acceptance/openstack/elb/v3/listeners_test.go index a18f1d218..97e97f403 100644 --- a/acceptance/openstack/elb/v3/listeners_test.go +++ b/acceptance/openstack/elb/v3/listeners_test.go @@ -15,10 +15,12 @@ func TestListenerLifecycle(t *testing.T) { th.AssertNoErr(t, err) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { + deleteLoadbalancer(t, client, loadbalancerID) + }) certificateID := createCertificate(t, client) - defer deleteCertificate(t, client, certificateID) + t.Cleanup(func() { deleteCertificate(t, client, certificateID) }) t.Logf("Attempting to create ELBv3 Listener") listenerName := tools.RandomString("create-listener-", 3) @@ -38,13 +40,13 @@ func TestListenerLifecycle(t *testing.T) { }, } - listener, err := listeners.Create(client, createOpts).Extract() - defer func() { + listener, err := listeners.Create(client, createOpts) + t.Cleanup(func() { t.Logf("Attempting to delete ELBv3 Listener: %s", listener.ID) - err := listeners.Delete(client, listener.ID).ExtractErr() + err := listeners.Delete(client, listener.ID) th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 Listener: %s", listener.ID) - }() + }) th.AssertNoErr(t, err) th.AssertEquals(t, createOpts.Name, listener.Name) th.AssertEquals(t, createOpts.Description, listener.Description) @@ -58,11 +60,11 @@ func TestListenerLifecycle(t *testing.T) { Name: &listenerName, SniMatchAlgo: "longest_suffix", } - _, err = listeners.Update(client, listener.ID, updateOpts).Extract() + _, err = listeners.Update(client, listener.ID, updateOpts) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 Listener: %s", listener.ID) - newListener, err := listeners.Get(client, listener.ID).Extract() + newListener, err := listeners.Get(client, listener.ID) th.AssertNoErr(t, err) th.AssertEquals(t, listenerName, newListener.Name) th.AssertEquals(t, emptyDescription, newListener.Description) diff --git a/acceptance/openstack/elb/v3/loadbalancers_test.go b/acceptance/openstack/elb/v3/loadbalancers_test.go index ad8a88ca5..f91c83d0f 100644 --- a/acceptance/openstack/elb/v3/loadbalancers_test.go +++ b/acceptance/openstack/elb/v3/loadbalancers_test.go @@ -31,7 +31,9 @@ func TestLoadBalancerLifecycle(t *testing.T) { th.AssertNoErr(t, err) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { + deleteLoadbalancer(t, client, loadbalancerID) + }) t.Logf("Attempting to update ELBv3 LoadBalancer: %s", loadbalancerID) lbName := tools.RandomString("update-lb-", 3) diff --git a/acceptance/openstack/elb/v3/members_test.go b/acceptance/openstack/elb/v3/members_test.go index ad89711b8..9256c59d7 100644 --- a/acceptance/openstack/elb/v3/members_test.go +++ b/acceptance/openstack/elb/v3/members_test.go @@ -21,10 +21,12 @@ func TestMemberLifecycle(t *testing.T) { th.AssertNoErr(t, err) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { + deleteLoadbalancer(t, client, loadbalancerID) + }) poolID := createPool(t, client, loadbalancerID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) t.Logf("Attempting to create ELBv3 Member") memberName := tools.RandomString("create-member-", 3) @@ -38,12 +40,12 @@ func TestMemberLifecycle(t *testing.T) { member, err := members.Create(client, poolID, createOpts).Extract() th.AssertNoErr(t, err) - defer func() { + t.Cleanup(func() { t.Logf("Attempting to delete ELBv3 Member: %s", member.ID) err := members.Delete(client, poolID, member.ID).ExtractErr() th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 Member: %s", member.ID) - }() + }) th.AssertEquals(t, createOpts.Name, member.Name) th.AssertEquals(t, createOpts.ProtocolPort, member.ProtocolPort) th.AssertEquals(t, createOpts.Address, member.Address) diff --git a/acceptance/openstack/elb/v3/monitors_test.go b/acceptance/openstack/elb/v3/monitors_test.go index 5d37aaadf..0e7c7dc15 100644 --- a/acceptance/openstack/elb/v3/monitors_test.go +++ b/acceptance/openstack/elb/v3/monitors_test.go @@ -30,10 +30,12 @@ func TestMonitorLifecycle(t *testing.T) { th.AssertNoErr(t, err) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { + deleteLoadbalancer(t, client, loadbalancerID) + }) poolID := createPool(t, client, loadbalancerID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) t.Logf("Attempting to Create ELBv3 Monitor") monitorName := tools.RandomString("create-monitor-", 3) @@ -49,12 +51,12 @@ func TestMonitorLifecycle(t *testing.T) { } monitor, err := monitors.Create(client, createOpts).Extract() th.AssertNoErr(t, err) - defer func() { + t.Cleanup(func() { t.Logf("Attempting to Delete ELBv3 Monitor: %s", monitor.ID) err := monitors.Delete(client, monitor.ID).ExtractErr() th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 Monitor: %s", monitor.ID) - }() + }) th.AssertEquals(t, createOpts.Name, monitor.Name) th.AssertEquals(t, createOpts.Type, monitor.Type) diff --git a/acceptance/openstack/elb/v3/policies_test.go b/acceptance/openstack/elb/v3/policies_test.go index d8118a70b..8b4a51846 100644 --- a/acceptance/openstack/elb/v3/policies_test.go +++ b/acceptance/openstack/elb/v3/policies_test.go @@ -18,13 +18,13 @@ func TestPolicyWorkflow(t *testing.T) { th.AssertNoErr(t, err) lbID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, lbID) + t.Cleanup(func() { deleteLoadbalancer(t, client, lbID) }) listenerID := createListener(t, client, lbID) - defer deleteListener(t, client, listenerID) + t.Cleanup(func() { deleteListener(t, client, listenerID) }) poolID := createPool(t, client, lbID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) createOpts := policies.CreateOpts{ Action: policies.ActionRedirectToPool, @@ -39,10 +39,10 @@ func TestPolicyWorkflow(t *testing.T) { t.Logf("Created L7 Policy") id := created.ID - defer func() { + t.Cleanup(func() { th.AssertNoErr(t, policies.Delete(client, id).ExtractErr()) t.Log("Deleted L7 Policy") - }() + }) got, err := policies.Get(client, id).Extract() th.AssertNoErr(t, err) @@ -79,19 +79,19 @@ func TestPolicyWorkflowFixedResponse(t *testing.T) { th.AssertNoErr(t, err) lbID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, lbID) + t.Cleanup(func() { deleteLoadbalancer(t, client, lbID) }) listener, err := listeners.Create(client, listeners.CreateOpts{ LoadbalancerID: lbID, - Protocol: listeners.ProtocolHTTP, + Protocol: "HTTP", ProtocolPort: 80, EnhanceL7policy: pointerto.Bool(true), - }).Extract() + }) th.AssertNoErr(t, err) - defer deleteListener(t, client, listener.ID) + t.Cleanup(func() { deleteListener(t, client, listener.ID) }) poolID := createPool(t, client, lbID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) createOpts := policies.CreateOpts{ Action: policies.ActionFixedResponse, @@ -110,10 +110,10 @@ func TestPolicyWorkflowFixedResponse(t *testing.T) { t.Logf("Created L7 Policy") id := created.ID - defer func() { + t.Cleanup(func() { th.AssertNoErr(t, policies.Delete(client, id).ExtractErr()) t.Log("Deleted L7 Policy") - }() + }) got, err := policies.Get(client, id).Extract() th.AssertNoErr(t, err) @@ -155,19 +155,19 @@ func TestPolicyWorkflowUlrRedirect(t *testing.T) { th.AssertNoErr(t, err) lbID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, lbID) + t.Cleanup(func() { deleteLoadbalancer(t, client, lbID) }) listener, err := listeners.Create(client, listeners.CreateOpts{ LoadbalancerID: lbID, - Protocol: listeners.ProtocolHTTP, + Protocol: "HTTP", ProtocolPort: 80, EnhanceL7policy: pointerto.Bool(true), - }).Extract() + }) th.AssertNoErr(t, err) - defer deleteListener(t, client, listener.ID) + t.Cleanup(func() { deleteListener(t, client, listener.ID) }) poolID := createPool(t, client, lbID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) createOpts := policies.CreateOpts{ Action: policies.ActionUrlRedirect, @@ -190,10 +190,10 @@ func TestPolicyWorkflowUlrRedirect(t *testing.T) { t.Logf("Created L7 Policy") id := created.ID - defer func() { + t.Cleanup(func() { th.AssertNoErr(t, policies.Delete(client, id).ExtractErr()) t.Log("Deleted L7 Policy") - }() + }) got, err := policies.Get(client, id).Extract() th.AssertNoErr(t, err) diff --git a/acceptance/openstack/elb/v3/pools_test.go b/acceptance/openstack/elb/v3/pools_test.go index 0508c8732..ed95e7808 100644 --- a/acceptance/openstack/elb/v3/pools_test.go +++ b/acceptance/openstack/elb/v3/pools_test.go @@ -31,10 +31,12 @@ func TestPoolLifecycle(t *testing.T) { th.AssertNoErr(t, err) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { deleteLoadbalancer(t, client, loadbalancerID) }) poolID := createPool(t, client, loadbalancerID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { + deletePool(t, client, poolID) + }) t.Logf("Attempting to update ELBv3 Pool: %s", poolID) poolName := tools.RandomString("update-pool-", 3) diff --git a/acceptance/openstack/elb/v3/rules_test.go b/acceptance/openstack/elb/v3/rules_test.go index 4a10bbaaa..b898834e4 100644 --- a/acceptance/openstack/elb/v3/rules_test.go +++ b/acceptance/openstack/elb/v3/rules_test.go @@ -20,16 +20,16 @@ func TestRuleWorkflow(t *testing.T) { th.AssertNoErr(t, err) lbID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, lbID) + t.Cleanup(func() { deleteLoadbalancer(t, client, lbID) }) listenerID := createListener(t, client, lbID) - defer deleteListener(t, client, listenerID) + t.Cleanup(func() { deleteListener(t, client, listenerID) }) poolID := createPool(t, client, lbID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) policyID := createPolicy(t, client, listenerID, poolID) - defer deletePolicy(t, client, policyID) + t.Cleanup(func() { deletePolicy(t, client, policyID) }) opts := rules.CreateOpts{ Type: rules.Path, @@ -42,10 +42,10 @@ func TestRuleWorkflow(t *testing.T) { t.Logf("Rule %s added to the policy %s", id, policyID) th.CheckEquals(t, opts.Type, created.Type) - defer func() { + t.Cleanup(func() { th.AssertNoErr(t, rules.Delete(client, policyID, id).ExtractErr()) t.Log("Rule removed from policy") - }() + }) got, err := rules.Get(client, policyID, id).Extract() th.AssertNoErr(t, err) @@ -78,22 +78,24 @@ func TestRuleWorkflowConditions(t *testing.T) { th.AssertNoErr(t, err) lbID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, lbID) + t.Cleanup(func() { + deleteLoadbalancer(t, client, lbID) + }) listener, err := listeners.Create(client, listeners.CreateOpts{ LoadbalancerID: lbID, - Protocol: listeners.ProtocolHTTP, + Protocol: "HTTP", ProtocolPort: 80, EnhanceL7policy: pointerto.Bool(true), - }).Extract() + }) th.AssertNoErr(t, err) - defer deleteListener(t, client, listener.ID) + t.Cleanup(func() { deleteListener(t, client, listener.ID) }) poolID := createPool(t, client, lbID) - defer deletePool(t, client, poolID) + t.Cleanup(func() { deletePool(t, client, poolID) }) policyID := createPolicy(t, client, listener.ID, poolID) - defer deletePolicy(t, client, policyID) + t.Cleanup(func() { deletePolicy(t, client, policyID) }) condition := rules.Condition{ Key: "", Value: "/", @@ -110,10 +112,10 @@ func TestRuleWorkflowConditions(t *testing.T) { t.Logf("Rule %s added to the policy %s", id, policyID) th.CheckEquals(t, opts.Type, created.Type) - defer func() { + t.Cleanup(func() { th.AssertNoErr(t, rules.Delete(client, policyID, id).ExtractErr()) t.Log("Rule removed from policy") - }() + }) got, err := rules.Get(client, policyID, id).Extract() th.AssertNoErr(t, err) diff --git a/acceptance/openstack/elb/v3/security_policy_test.go b/acceptance/openstack/elb/v3/security_policy_test.go index a44f7c749..c488daff7 100644 --- a/acceptance/openstack/elb/v3/security_policy_test.go +++ b/acceptance/openstack/elb/v3/security_policy_test.go @@ -40,7 +40,7 @@ func TestSecurityPolicyLifecycle(t *testing.T) { secPolicy := createSecurityPolicy(t, client, policyName) tools.PrintResource(t, secPolicy) - defer deleteSecurityPolicy(t, client, secPolicy.SecurityPolicy.ID) + t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicy.SecurityPolicy.ID) }) updatedName := tools.RandomString("update-policy-", 3) @@ -78,14 +78,14 @@ func TestPolicyAssignment(t *testing.T) { policyName := tools.RandomString("create-policy-", 3) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { deleteLoadbalancer(t, client, loadbalancerID) }) certificateID := createCertificate(t, client) - defer deleteCertificate(t, client, certificateID) + t.Cleanup(func() { deleteCertificate(t, client, certificateID) }) t.Run("AssignSecurityPolicyListenerCreation", func(t *testing.T) { secPolicyID := createSecurityPolicy(t, client, policyName).SecurityPolicy.ID - defer deleteSecurityPolicy(t, client, secPolicyID) + t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicyID) }) listenerName := tools.RandomString("create-listener-", 3) @@ -99,20 +99,20 @@ func TestPolicyAssignment(t *testing.T) { SecurityPolicy: secPolicyID, } - listener, err := listeners.Create(client, createOpts).Extract() - defer func() { + listener, err := listeners.Create(client, createOpts) + t.Cleanup(func() { t.Logf("Attempting to delete ELBv3 Listener: %s", listener.ID) - err := listeners.Delete(client, listener.ID).ExtractErr() + err := listeners.Delete(client, listener.ID) th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 Listener: %s", listener.ID) - }() + }) th.AssertNoErr(t, err) th.AssertEquals(t, listener.SecurityPolicy, secPolicyID) }) t.Run("AssignSecurityPolicyListenerUpdate", func(t *testing.T) { secPolicyUpdatedID := createSecurityPolicy(t, client, policyName).SecurityPolicy.ID - defer deleteSecurityPolicy(t, client, secPolicyUpdatedID) + t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicyUpdatedID) }) listenerName := tools.RandomString("create-listener-", 3) createOpts := listeners.CreateOpts{ @@ -124,22 +124,22 @@ func TestPolicyAssignment(t *testing.T) { ProtocolPort: 443, } - listener, err := listeners.Create(client, createOpts).Extract() + listener, err := listeners.Create(client, createOpts) th.AssertNoErr(t, err) - defer func() { + t.Cleanup(func() { t.Logf("Attempting to delete ELBv3 Listener: %s", listener.ID) - err := listeners.Delete(client, listener.ID).ExtractErr() + err := listeners.Delete(client, listener.ID) th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 Listener: %s", listener.ID) - }() + }) updateOpts := listeners.UpdateOpts{ SecurityPolicy: secPolicyUpdatedID, } - _ = listeners.Update(client, listener.ID, updateOpts) + _, _ = listeners.Update(client, listener.ID, updateOpts) - updatedListener, err := listeners.Get(client, listener.ID).Extract() + updatedListener, err := listeners.Get(client, listener.ID) th.AssertNoErr(t, err) th.AssertEquals(t, updatedListener.SecurityPolicy, secPolicyUpdatedID) }) From c269d2fc93b53f4f72fc58de0758a1066025783f Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 12:01:04 +0200 Subject: [PATCH 21/54] Create --- openstack/elb/v3/loadbalancers/Create.go | 198 ++++++++++++++++------- 1 file changed, 144 insertions(+), 54 deletions(-) diff --git a/openstack/elb/v3/loadbalancers/Create.go b/openstack/elb/v3/loadbalancers/Create.go index a8fe5fc86..a41a59bb8 100644 --- a/openstack/elb/v3/loadbalancers/Create.go +++ b/openstack/elb/v3/loadbalancers/Create.go @@ -1,90 +1,180 @@ package loadbalancers import ( + "net/http" + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" ) -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToLoadBalancerCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's Create -// operation. +// CreateOpts is the common options' struct used in this package's Create operation. type CreateOpts struct { - // Human-readable name for the Loadbalancer. Does not have to be unique. + // Specifies the load balancer name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // Human-readable description for the Loadbalancer. + // Provides supplementary information about the load balancer. + // + // Minimum: 0 + // + // Maximum: 255 Description string `json:"description,omitempty"` - - // The IP address of the Loadbalancer. + // Specifies the private IPv4 address bound to the load balancer. The IP address must be from the IPv4 subnet where the load balancer resides and should not be occupied by other services. + // + // Note: + // + // vip_subnet_cidr_id is also required if vip_address is passed. + // + // If only vip_subnet_cidr_id is passed, the system will automatically assign a private IPv4 address to the load balancer. + // + // If both vip_address and vip_subnet_cidr_id are not passed, no private IPv4 address will be assigned, and the value of vip_address will be null. VipAddress string `json:"vip_address,omitempty"` - - // The network on which to allocate the Loadbalancer's address. + // Specifies the ID of the IPv4 subnet where the load balancer resides. This parameter is mandatory if you need to create a load balancer with a private IPv4 address. + // + // You can query parameter neutron_subnet_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). + // + // Note: + // + // vpc_id, vip_subnet_cidr_id and ipv6_vip_virsubnet_id cannot be left blank at the same time. The subnet specified by vip_subnet_cidr_id and the subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id. + // + // The subnet specified by vip_subnet_cidr_id must be in the VPC specified by vpc_id if both vpc_id and vip_subnet_cidr_id are passed. + // + // Minimum: 1 + // + // Maximum: 36 VipSubnetCidrID string `json:"vip_subnet_cidr_id,omitempty"` - - // The V6 network on which to allocate the Loadbalancer's address. + // Specifies the ID of the IPv6 subnet where the load balancer resides. You can query id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). + // + // Note: + // + // vpc_id, vip_subnet_cidr_id and ipv6_vip_virsubnet_id cannot be left blank at the same time. The subnet specified by vip_subnet_cidr_id and the subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id. + // + // IPv6 must have been enabled for the IPv6 subnet where the load balancer resides. + // + // IPv6 is unsupported. Please do not use this parameter. IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id,omitempty"` - - // The UUID of a l4 flavor. + // Specifies the provider of the load balancer. The value can only be vlb. + // + // Minimum: 1 + // + // Maximum: 255 + Provider string `json:"provider,omitempty"` + // Specifies the ID of a flavor at Layer 4. + // + // Note: + // + // If neither l4_flavor_id nor l7_flavor_id is specified, the default flavor is used. The default flavor varies depending on the sites. + // + // Minimum: 1 + // + // Maximum: 36 L4Flavor string `json:"l4_flavor_id,omitempty"` - - // Guaranteed. + // Specifies whether the load balancer is a dedicated load balancer. + // + // true (default): The load balancer is a dedicated load balancer. + // + // false: The load balancer is a shared load balancer. + // + // Currently, the value can only be true. If the value is set to false, 400 Bad Request will be returned. Guaranteed *bool `json:"guaranteed,omitempty"` - - // The VPC ID. + // Specifies the ID of the VPC where the load balancer resides. You can query parameter id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/vpcs). + // + // vpc_id, vip_subnet_cidr_id and ipv6_vip_virsubnet_id cannot be left blank at the same time. The subnet specified by vip_subnet_cidr_id and the subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id. VpcID string `json:"vpc_id,omitempty"` - - // Availability Zone List. + // Specifies the list of AZs where the load balancer can be created. You can query the AZs by calling the API (GET https://{ELB_Endpoint}/v3/{project_id}/elb/availability-zones). Select one or more AZs in the same set. AvailabilityZoneList []string `json:"availability_zone_list" required:"true"` - - // The tags of the Loadbalancer. + // Lists the tags added to the load balancer. + // + // Example: "tags":[{"key":"my_tag","value":"my_tag_value"}] Tags []tags.ResourceTag `json:"tags,omitempty"` - - // The administrative state of the Loadbalancer. A valid value is true (UP) - // or false (DOWN). + // Specifies the administrative status of the load balancer. The value can only be true (default). + // + // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The UUID of a l7 flavor. + // Specifies the ID of a flavor at Layer 7. + // + // Note: + // + // If neither l4_flavor_id nor l7_flavor_id is specified, the default flavor is used. The default flavor varies depending on the sites. + // + // Minimum: 1 + // + // Maximum: 36 L7Flavor string `json:"l7_flavor_id,omitempty"` - - // IPv6 Bandwidth. + // Specifies the ID of the bandwidth used by an IPv6 address. This parameter is available only when you create or update a load balancer with a public IPv6 address. If you use a new IPv6 address and specify a shared bandwidth, the IPv6 address will be added to the shared bandwidth. + // + // IPv6 is unsupported. Please do not use this parameter. IPV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` - - // Public IP IDs. + // Specifies the ID of the EIP the system will automatically assign and bind to the load balancer during load balancer creation. Only the first EIP will be bound to the load balancer although multiple EIP IDs can be set. PublicIpIDs []string `json:"publicip_ids,omitempty"` - - // Public IP. + // Specifies the new EIP that will be bound to the load balancer. PublicIp *PublicIp `json:"publicip,omitempty"` - - // ELB VirSubnet IDs. + // + // Specifies the IDs of subnets on the downstream plane. You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). + // + // If this parameter is not specified, select subnets as follows: + // + // If IPv6 is enabled for a load balancer, the ID of subnet specified in ipv6_vip_virsubnet_id will be used. + // + // If IPv4 is enabled for a load balancer, the ID of subnet specified in vip_subnet_cidr_id will be used. + // + // If only pubilc network is available for a load balancer, the ID of any subnet in the VPC where the load balancer resides will be used. Subnets with more IP addresses are preferred. + // + // If there is more than one subnet, the first subnet in the list will be used. + // + // The subnets must be in the VPC where the load balancer resides. + // + // IPv6 is unsupported. ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"` - - // IP Target Enable. + // Specifies whether to enable cross-VPC backend. + // + // If you enable this function, you can add servers in a peer VPC connected through a VPC peering connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using their IP addresses. + // + // This function is supported only by dedicated load balancers. + // + // The value can be true (enable cross-VPC backend) or false (disable cross-VPC backend). + // + // The value can only be update to true. This parameter is not available in eu-nl region. Please do not use it. IpTargetEnable *bool `json:"ip_target_enable,omitempty"` - // Specifies whether to enable deletion protection for the load balancer. + // + // true: Enable deletion protection. + // + // false (default): Disable deletion protection. + // + // Note + // + // Disable deletion protection for all your resources before deleting your account. + // + // This parameter is not available in eu-nl region. Please do not use it. DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` } -// ToLoadBalancerCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToLoadBalancerCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "loadbalancer") -} - // Create is an operation which provisions a new loadbalancer 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(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToLoadBalancerCreateMap() +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*LoadBalancer, error) { + b, err := build.RequestBody(opts, "loadbalancer") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("loadbalancers"), b, &r.Body, nil) - return + + // POST /v3/{project_id}/elb/loadbalancers + raw, err := client.Post(client.ServiceURL("loadbalancers"), b, nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*LoadBalancer, error) { + if err != nil { + return nil, err + } + + var res LoadBalancer + err = extract.IntoStructPtr(raw.Body, &res, "loadbalancer") + return &res, err } From e74fce46ee2fe012757ec2fa85228f2080051acd Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 10 May 2023 12:11:13 +0200 Subject: [PATCH 22/54] LoadBalancer --- openstack/elb/v3/loadbalancers/Delete.go | 5 +- openstack/elb/v3/loadbalancers/Get.go | 173 +++++++++++++++++++++- openstack/elb/v3/loadbalancers/results.go | 109 -------------- 3 files changed, 172 insertions(+), 115 deletions(-) diff --git a/openstack/elb/v3/loadbalancers/Delete.go b/openstack/elb/v3/loadbalancers/Delete.go index ce9706ed3..ffcf23bce 100644 --- a/openstack/elb/v3/loadbalancers/Delete.go +++ b/openstack/elb/v3/loadbalancers/Delete.go @@ -4,7 +4,8 @@ import "github.com/opentelekomcloud/gophertelekomcloud" // Delete will permanently delete a particular LoadBalancer based on its // unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("loadbalancers", id), nil) +func Delete(client *golangsdk.ServiceClient, id string) (err error) { + // DELETE /v3/{project_id}/elb/loadbalancers/{loadbalancer_id} + _, err = client.Delete(client.ServiceURL("loadbalancers", id), nil) return } diff --git a/openstack/elb/v3/loadbalancers/Get.go b/openstack/elb/v3/loadbalancers/Get.go index e413f35a7..175d1df4a 100644 --- a/openstack/elb/v3/loadbalancers/Get.go +++ b/openstack/elb/v3/loadbalancers/Get.go @@ -1,9 +1,174 @@ package loadbalancers -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" +) // Get retrieves a particular Loadbalancer based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("loadbalancers", id), &r.Body, nil) - return +func Get(client *golangsdk.ServiceClient, id string) (*LoadBalancer, error) { + // GET /v3/{project_id}/elb/loadbalancers/{loadbalancer_id} + raw, err := client.Get(client.ServiceURL("loadbalancers", id), nil, nil) + return extra(err, raw) +} + +// LoadBalancer is the primary load balancing configuration object that +// specifies the virtual IP address on which client traffic is received, as well +// as other details such as the load balancing method to be use, protocol, etc. +type LoadBalancer struct { + // The unique ID for the LoadBalancer. + ID string `json:"id"` + // Provides supplementary information about the load balancer. + // + // Minimum: 1 + // + // Maximum: 255 + Description string `json:"description"` + // Specifies the provisioning status of the load balancer. The value can be one of the following: + // + // ACTIVE: The load balancer is successfully provisioned. + // + // PENDING_DELETE: The load balancer is being deleted. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies the administrative status of the load balancer. The value can only be true. + AdminStateUp bool `json:"admin_state_up"` + // Specifies the provider of the load balancer. The value can only be vlb. + Provider string `json:"provider"` + // Lists the IDs of backend server groups associated with the load balancer. + Pools []structs.ResourceRef `json:"pools"` + // Lists the IDs of listeners added to the load balancer. + Listeners []structs.ResourceRef `json:"listeners"` + // Specifies the operating status of the load balancer. The value can only be ONLINE, indicating that the load balancer is running normally. + OperatingStatus string `json:"operating_status"` + // Specifies the private IPv4 address bound to the load balancer. + VipAddress string `json:"vip_address"` + // Specifies the ID of the IPv4 subnet where the load balancer resides. + VipSubnetCidrID string `json:"vip_subnet_cidr_id"` + // Specifies the load balancer name. + Name string `json:"name"` + // Owner of the LoadBalancer. + ProjectID string `json:"project_id"` + // Specifies the ID of the port bound to the private IPv4 address of the load balancer. + // + // The security group associated with the port will not take effect. + VipPortID string `json:"vip_port_id"` + // Lists the tags added to the load balancer. + Tags []tags.ResourceTag `json:"tags"` + // Specifies whether the load balancer is a dedicated load balancer. + // + // true (default): The load balancer is a dedicated load balancer. + // + // false: The load balancer is a shared load balancer. + Guaranteed bool `json:"guaranteed"` + // Specifies the ID of the VPC where the load balancer resides. + VpcID string `json:"vpc_id"` + // Specifies the EIP bound to the load balancer. Only one EIP can be bound to a load balancer. + // + // This parameter has the same meaning as publicips. + Eips []EipInfo `json:"eips"` + // Specifies the IPv6 address bound to the load balancer. + // + // IPv6 is unsupported. Please do not use this parameter. + IpV6VipAddress string `json:"ipv6_vip_address"` + // Specifies the ID of the IPv6 subnet where the load balancer resides. + // + // IPv6 is unsupported. Please do not use this parameter. + IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id"` + // Specifies the ID of the port bound to the IPv6 address of the load balancer. + // + // IPv6 is unsupported. Please do not use this parameter. + IpV6VipPortID string `json:"ipv6_vip_port_id"` + // Specifies the list of AZs where the load balancer is created. + AvailabilityZoneList []string `json:"availability_zone_list"` + // Specifies the ID of a flavor at Layer 4. + // + // Minimum: 1 + // + // Maximum: 255 + L4FlavorID string `json:"l4_flavor_id"` + // Specifies the ID of the reserved flavor at Layer 4. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 255 + L4ScaleFlavorID string `json:"l4_scale_flavor_id"` + // Specifies the ID of a flavor at Layer 7. + // + // Minimum: 1 + // + // Maximum: 255 + L7FlavorID string `json:"l7_flavor_id"` + // Specifies the ID of the reserved flavor at Layer 7. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 255 + L7ScaleFlavorID string `json:"l7_scale_flavor_id"` + // Specifies the EIP bound to the load balancer. Only one EIP can be bound to a load balancer. + // + // This parameter has the same meaning as eips. + PublicIps []PublicIpInfo `json:"publicips"` + // Lists the IDs of subnets on the downstream plane. + ElbSubnetIDs []string `json:"elb_virsubnet_ids"` + // Specifies the type of the subnet on the downstream plane. + // + // ipv4: IPv4 subnet + // + // dualstack: subnet that supports IPv4/IPv6 dual stack + // + // "dualstack" is not supported. + ElbSubnetType string `json:"elb_virsubnet_type"` + // Specifies whether to enable cross-VPC backend. + // + // If you enable this function, you can add servers in a peer VPC connected through a VPC peering connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using their IP addresses. + // + // This function is supported only by dedicated load balancers. + // + // The value can be true (enable cross-VPC backend) or false (disable cross-VPC backend). + // + // The value can only be update to true. This parameter is not available in eu-nl region. Please do not use it. + IpTargetEnable bool `json:"ip_target_enable"` + // Specifies the scenario where the load balancer is frozen. Multiple values are separated using commas (,). + // + // POLICE: The load balancer is frozen due to security reasons. + // + // ILLEGAL: The load balancer is frozen due to violation of laws and regulations. + // + // VERIFY: Your account has not completed real-name authentication. + // + // PARTNER: The load balancer is frozen by the partner. + // + // ARREAR: Your account is in arrears. + // + // This parameter is unsupported. Please do not use it. + FrozenScene string `json:"frozen_scene"` + // Specifies the ID of the bandwidth used by an IPv6 address. This parameter is available only when you create or update a load balancer with a public IPv6 address. If you use a new IPv6 address and specify a shared bandwidth, the IPv6 address will be added to the shared bandwidth. + // + // IPv6 is unsupported. Please do not use this parameter. + IpV6Bandwidth BandwidthRef `json:"ipv6_bandwidth"` + // Specifies the time when the load balancer was created, in the format of yyyy-MM-dd''T''HH:mm:ss''Z''. + CreatedAt string `json:"created_at"` + // Specifies the time when the load balancer was updated, in the format of yyyy-MM-dd''T''HH:mm:ss''Z''. + UpdatedAt string `json:"updated_at"` + // Specifies whether deletion protection is enabled. + // + // false: Deletion protection is not enabled. + // + // true: Deletion protection is enabled. + // + // Note + // + // Disable deletion protection for all your resources before deleting your account. + // + // This parameter is returned only when deletion protection is enabled at the site. + // + // This parameter is not available in eu-nl region. Please do not use it. + DeletionProtectionEnable bool `json:"deletion_protection_enable"` + // Specifies the AZ group to which the load balancer belongs. + PublicBorderGroup string `json:"public_border_group"` } diff --git a/openstack/elb/v3/loadbalancers/results.go b/openstack/elb/v3/loadbalancers/results.go index 0964d9995..24467cc52 100644 --- a/openstack/elb/v3/loadbalancers/results.go +++ b/openstack/elb/v3/loadbalancers/results.go @@ -2,118 +2,9 @@ package loadbalancers import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// LoadBalancer is the primary load balancing configuration object that -// specifies the virtual IP address on which client traffic is received, as well -// as other details such as the load balancing method to be use, protocol, etc. -type LoadBalancer struct { - // The unique ID for the LoadBalancer. - ID string `json:"id"` - - // Human-readable description for the Loadbalancer. - Description string `json:"description"` - - // The provisioning status of the LoadBalancer. - // This value is ACTIVE, PENDING_CREATE or ERROR. - ProvisioningStatus string `json:"provisioning_status"` - - // The administrative state of the Loadbalancer. - // A valid value is true (UP) or false (DOWN). - AdminStateUp bool `json:"admin_state_up"` - - // The name of the provider. - Provider string `json:"provider"` - - // Pools are the pools related to this Loadbalancer. - Pools []structs.ResourceRef `json:"pools"` - - // Listeners are the listeners related to this Loadbalancer. - Listeners []structs.ResourceRef `json:"listeners"` - - // The operating status of the LoadBalancer. This value is ONLINE or OFFLINE. - OperatingStatus string `json:"operating_status"` - - // The IP address of the Loadbalancer. - VipAddress string `json:"vip_address"` - - // The UUID of the subnet on which to allocate the virtual IP for the - // Loadbalancer address. - VipSubnetCidrID string `json:"vip_subnet_cidr_id"` - - // Human-readable name for the LoadBalancer. Does not have to be unique. - Name string `json:"name"` - - // Owner of the LoadBalancer. - ProjectID string `json:"project_id"` - - // The UUID of the port associated with the IP address. - VipPortID string `json:"vip_port_id"` - - // The UUID of a flavor if set. - Tags []tags.ResourceTag `json:"tags"` - - // Guaranteed. - Guaranteed bool `json:"guaranteed"` - - // The VPC ID. - VpcID string `json:"vpc_id"` - - // EIP Info. - Eips []EipInfo `json:"eips"` - - // IpV6 Vip Address. - IpV6VipAddress string `json:"ipv6_vip_address"` - - // IpV6 Vip VirSubnet ID. - IpV6VipSubnetID string `json:"ipv6_vip_virsubnet_id"` - - // IpV6 Vip Port ID. - IpV6VipPortID string `json:"ipv6_vip_port_id"` - - // Availability Zone List. - AvailabilityZoneList []string `json:"availability_zone_list"` - - // L4 Flavor ID. - L4FlavorID string `json:"l4_flavor_id"` - - // L4 Scale Flavor ID. - L4ScaleFlavorID string `json:"l4_scale_flavor_id"` - - // L7 Flavor ID. - L7FlavorID string `json:"l7_flavor_id"` - - // L7 Scale Flavor ID. - L7ScaleFlavorID string `json:"l7_scale_flavor_id"` - - // Public IP Info. - PublicIps []PublicIpInfo `json:"publicips"` - - // Elb VirSubnet IDs. - ElbSubnetIDs []string `json:"elb_virsubnet_ids"` - - // Elb VirSubnet Type. - ElbSubnetType string `json:"elb_virsubnet_type"` - - // Ip Target Enable. - IpTargetEnable bool `json:"ip_target_enable"` - - // Frozen Scene. - FrozenScene string `json:"frozen_scene"` - - // Ipv6 Bandwidth. - IpV6Bandwidth BandwidthRef `json:"ipv6_bandwidth"` - - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` - - // Ip Target Enable. - DeletionProtectionEnable bool `json:"deletion_protection_enable"` -} - type EipInfo struct { // Eip ID EipID string `json:"eip_id"` From ca4da36f6ef659c9272550c36a9020b579512a53 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 11 May 2023 15:29:39 +0200 Subject: [PATCH 23/54] GetStatuses --- openstack/elb/v3/loadbalancers/GetStatuses.go | 19 ++++++++++++---- openstack/elb/v3/loadbalancers/results.go | 22 ------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/openstack/elb/v3/loadbalancers/GetStatuses.go b/openstack/elb/v3/loadbalancers/GetStatuses.go index 1faf465d8..84f008166 100644 --- a/openstack/elb/v3/loadbalancers/GetStatuses.go +++ b/openstack/elb/v3/loadbalancers/GetStatuses.go @@ -1,9 +1,20 @@ package loadbalancers -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) // GetStatuses will return the status of a particular LoadBalancer. -func GetStatuses(client *golangsdk.ServiceClient, id string) (r GetStatusesResult) { - _, r.Err = client.Get(client.ServiceURL("loadbalancers", id, "statuses"), &r.Body, nil) - return +func GetStatuses(client *golangsdk.ServiceClient, id string) (*LoadBalancer, error) { + raw, err := client.Get(client.ServiceURL("loadbalancers", id, "statuses"), nil, nil) + if err != nil { + return nil, err + } + + var res struct { + Loadbalancer LoadBalancer `json:"loadbalancer"` + } + err = extract.IntoStructPtr(raw.Body, &res, "statuses") + return &res.Loadbalancer, nil } diff --git a/openstack/elb/v3/loadbalancers/results.go b/openstack/elb/v3/loadbalancers/results.go index 24467cc52..474ac5f2e 100644 --- a/openstack/elb/v3/loadbalancers/results.go +++ b/openstack/elb/v3/loadbalancers/results.go @@ -23,11 +23,6 @@ type PublicIpInfo struct { IpVersion int `json:"ip_version"` } -// StatusTree represents the status of a loadbalancer. -type StatusTree struct { - Loadbalancer *LoadBalancer `json:"loadbalancer"` -} - type commonResult struct { golangsdk.Result } @@ -42,23 +37,6 @@ func (r commonResult) Extract() (*LoadBalancer, error) { return s, nil } -// GetStatusesResult represents the result of a GetStatuses operation. -// Call its Extract method to interpret it as a StatusTree. -type GetStatusesResult struct { - golangsdk.Result -} - -// Extract is a function that accepts a result and extracts the status of -// a Loadbalancer. -func (r GetStatusesResult) Extract() (*StatusTree, error) { - s := new(StatusTree) - err := r.ExtractIntoStructPtr(s, "statuses") - if err != nil { - return nil, err - } - return s, nil -} - // LoadbalancerPage is the page returned by a pager when traversing over a // collection of loadbalancer. type LoadbalancerPage struct { From 389019dee7848aed7e772f4453d9ca7239e07bba Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 12 May 2023 11:57:19 +0200 Subject: [PATCH 24/54] todo --- openstack/elb/v3/loadbalancers/List.go | 125 ++++++++++++++++++++----- 1 file changed, 104 insertions(+), 21 deletions(-) diff --git a/openstack/elb/v3/loadbalancers/List.go b/openstack/elb/v3/loadbalancers/List.go index 0b3d72df2..822283fb3 100644 --- a/openstack/elb/v3/loadbalancers/List.go +++ b/openstack/elb/v3/loadbalancers/List.go @@ -5,29 +5,112 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToLoadbalancerListQuery() (string, error) -} - type ListOpts struct { - ID []string `q:"id"` - Name []string `q:"name"` - Description []string `q:"description"` - ProvisioningStatus []string `q:"provisioning_status"` - OperatingStatus []string `q:"operating_status"` - VpcID []string `q:"vpc_id"` - VipPortID []string `q:"vip_port_id"` - VipAddress []string `q:"vip_address"` - VipSubnetCidrID []string `q:"vip_subnet_cidr_id"` - L4FlavorID []string `q:"l4_flavor_id"` - L4ScaleFlavorID []string `q:"l4_scale_flavor_id"` + // Specifies the load balancer ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + ID []string `q:"id"` + // Specifies the load balancer name. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Provides supplementary information about the load balancer. + // + // Multiple descriptions can be queried in the format of description=xxx&description=xxx. + Description []string `q:"description"` + // Specifies the administrative status of the load balancer. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the provisioning status of the load balancer. + // + // ACTIVE: The load balancer is successfully provisioned. + // + // PENDING_DELETE: The load balancer is being deleted. + // + // Multiple provisioning statuses can be queried in the format of provisioning_status=xxx&provisioning_status=xxx. + ProvisioningStatus []string `q:"provisioning_status"` + // Specifies the operating status of the load balancer. + // + // ONLINE: The load balancer is working normally. + // + // FROZEN: The load balancer has been frozen. + // + // Multiple operating statuses can be queried in the format of operating_status=xxx&operating_status=xxx. + OperatingStatus []string `q:"operating_status"` + // Specifies whether the load balancer is a dedicated load balancer. + // + // false: The load balancer is a shared load balancer. + // + // true: The load balancer is a dedicated load balancer. + Guaranteed *bool `q:"guaranteed"` + // Specifies the ID of the VPC where the load balancer resides. + // + // Multiple IDs can be queried in the format of vpc_id=xxx&vpc_id=xxx. + VpcID []string `q:"vpc_id"` + // Specifies the ID of the port bound to the private IPv4 address of the load balancer. + // + // Multiple IDs can be queried in the format of vip_port_id=xxx&vip_port_id=xxx. + VipPortID []string `q:"vip_port_id"` + // Specifies the virtual IP address bound to the load balancer. + // + // Multiple virtual IP addresses can be queried in the format of vip_address=xxx&vip_address=xxx. + VipAddress []string `q:"vip_address"` + // Specifies the ID of the IPv4 subnet where the load balancer resides. + // + // Multiple IDs can be queried in the format of vip_subnet_cidr_id=xxx&vip_subnet_cidr_id=xxx. + VipSubnetCidrID []string `q:"vip_subnet_cidr_id"` + // Specifies the ID of a flavor at Layer 4. + // + // Multiple IDs can be queried in the format of l4_flavor_id=xxx&l4_flavor_id=xxx. + L4FlavorID []string `q:"l4_flavor_id"` + // Specifies the ID of the elastic flavor at Layer 4, which is reserved for now. + // + // Multiple flavors can be queried in the format of l4_scale_flavor_id=xxx&l4_scale_flavor_id=xxx. + // + // This parameter is unsupported. Please do not use it. + L4ScaleFlavorID []string `q:"l4_scale_flavor_id"` + // Specifies the list of AZs where the load balancer is created. + // + // Multiple AZs can be queried in the format of availability_zone_list=xxx&availability_zone_list=xxx. AvailabilityZoneList []string `q:"availability_zone_list"` - L7FlavorID []string `q:"l7_flavor_id"` - L7ScaleFlavorID []string `q:"l7_scale_flavor_id"` - Limit int `q:"limit"` - Marker string `q:"marker"` + // Specifies the ID of a flavor at Layer 7. + // + // Multiple flavors can be queried in the format of l7_flavor_id=xxx&l7_flavor_id=xxx. + L7FlavorID []string `q:"l7_flavor_id"` + // Specifies the ID of the elastic flavor at Layer 7. Multiple flavors can be queried in the format of l7_scale_flavor_id=xxx&l7_scale_flavor_id=xxx. This parameter is unsupported. Please do not use it. + L7ScaleFlavorID []string `q:"l7_scale_flavor_id"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit int `q:"limit"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` } // ToLoadbalancerListQuery formats a ListOpts into a query string. From c098263d5985d68957eee0550b234efd626f8160 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 13:53:33 +0200 Subject: [PATCH 25/54] List --- .../openstack/elb/v3/loadbalancers_test.go | 6 +- openstack/elb/v3/loadbalancers/List.go | 195 +++++++++++++----- openstack/elb/v3/loadbalancers/results.go | 25 --- 3 files changed, 152 insertions(+), 74 deletions(-) diff --git a/acceptance/openstack/elb/v3/loadbalancers_test.go b/acceptance/openstack/elb/v3/loadbalancers_test.go index f91c83d0f..93442a41c 100644 --- a/acceptance/openstack/elb/v3/loadbalancers_test.go +++ b/acceptance/openstack/elb/v3/loadbalancers_test.go @@ -18,7 +18,7 @@ func TestLoadBalancerList(t *testing.T) { loadbalancerPages, err := loadbalancers.List(client, listOpts).AllPages() th.AssertNoErr(t, err) - loadbalancerList, err := loadbalancers.ExtractLoadbalancers(loadbalancerPages) + loadbalancerList, err := loadbalancers.ExtractLoadBalancers(loadbalancerPages) th.AssertNoErr(t, err) for _, lb := range loadbalancerList { @@ -47,7 +47,7 @@ func TestLoadBalancerLifecycle(t *testing.T) { th.AssertNoErr(t, err) t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID) - err = loadbalancers.Delete(client, loadbalancerID).ExtractErr() + err = loadbalancers.Delete(client, loadbalancerID) if err != nil { t.Logf("Cannot delete, Deletion Protection enabled for ELBv3 LoadBalancer: %s", loadbalancerID) } @@ -61,7 +61,7 @@ func TestLoadBalancerLifecycle(t *testing.T) { th.AssertNoErr(t, err) t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID) - newLoadbalancer, err := loadbalancers.Get(client, loadbalancerID).Extract() + newLoadbalancer, err := loadbalancers.Get(client, loadbalancerID) th.AssertNoErr(t, err) th.AssertEquals(t, updateOptsDpD.Name, newLoadbalancer.Name) th.AssertEquals(t, emptyDescription, newLoadbalancer.Description) diff --git a/openstack/elb/v3/loadbalancers/List.go b/openstack/elb/v3/loadbalancers/List.go index 822283fb3..eda48753c 100644 --- a/openstack/elb/v3/loadbalancers/List.go +++ b/openstack/elb/v3/loadbalancers/List.go @@ -2,14 +2,45 @@ package loadbalancers import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type ListOpts struct { + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit int `q:"limit"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` // Specifies the load balancer ID. // // Multiple IDs can be queried in the format of id=xxx&id=xxx. - ID []string `q:"id"` + Id []string `q:"id"` // Specifies the load balancer name. // // Multiple names can be queried in the format of name=xxx&name=xxx. @@ -47,11 +78,11 @@ type ListOpts struct { // Specifies the ID of the VPC where the load balancer resides. // // Multiple IDs can be queried in the format of vpc_id=xxx&vpc_id=xxx. - VpcID []string `q:"vpc_id"` + VpcId []string `q:"vpc_id"` // Specifies the ID of the port bound to the private IPv4 address of the load balancer. // // Multiple IDs can be queried in the format of vip_port_id=xxx&vip_port_id=xxx. - VipPortID []string `q:"vip_port_id"` + VipPortId []string `q:"vip_port_id"` // Specifies the virtual IP address bound to the load balancer. // // Multiple virtual IP addresses can be queried in the format of vip_address=xxx&vip_address=xxx. @@ -59,76 +90,148 @@ type ListOpts struct { // Specifies the ID of the IPv4 subnet where the load balancer resides. // // Multiple IDs can be queried in the format of vip_subnet_cidr_id=xxx&vip_subnet_cidr_id=xxx. - VipSubnetCidrID []string `q:"vip_subnet_cidr_id"` + VipSubnetCidrId []string `q:"vip_subnet_cidr_id"` + // Specifies the ID of the port bound to the IPv6 address of the load balancer. + // + // Multiple ports can be queried in the format of ipv6_vip_port_id=xxx&ipv6_vip_port_id=xxx. + // + // IPv6 is unsupported. Please do not use this parameter. + Ipv6VipPortId []string `q:"ipv6_vip_port_id"` + // Specifies the IPv6 address bound to the load balancer. + // + // Multiple IPv6 addresses can be queried in the format of ipv6_vip_address=xxx&ipv6_vip_address=xxx. + // + // IPv6 is unsupported. Please do not use this parameter. + Ipv6VipAddress []string `q:"ipv6_vip_address"` + // Specifies the ID of the IPv6 subnet where the load balancer resides. + // + // Multiple IDs can be queried in the format of ipv6_vip_virsubnet_id=xxx&ipv6_vip_virsubnet_id=xxx. + // + // IPv6 is unsupported. Please do not use this parameter. + Ipv6VipVirSubnetId []string `q:"ipv6_vip_virsubnet_id"` + // Specifies the IPv4 EIP bound to the load balancer. The following is an example: "eips": [ { "eip_id": "e9b72a9d-4275-455e-a724-853504e4d9c6", "eip_address": "88.88.14.122", "ip_version": 4 } ] + // + // Multiple EIPs can be queried. + // + // If eip_id is used as the query condition, the format is eips=eip_id=xxx&eips=eip_id=xxx. + // + // If eip_address is used as the query condition, the format is eips=eip_address=xxx&eips=eip_address=xxx. + // + // If ip_version is used as the query condition, the format is eips=ip_version=xxx&eips=ip_version=xxx. + // + // Note that this parameter has the same meaning as publicips. + Eips []string `q:"eips"` + // Specifies the IPv4 EIP bound to the load balancer. The following is an example: "publicips": [ { "publicip_id": "e9b72a9d-4275-455e-a724-853504e4d9c6", "publicip_address": "88.88.14.122", "ip_version": 4 } ] + // + // Multiple EIPs can be queried. + // + // If publicip_id is used as the query condition, the format is publicips=publicip_id=xxx&publicips=publicip_id=xxx. + // + // If publicip_address is used as the query condition, the format is *publicips=publicip_address=xxx&publicips=publicip_address=xxx. + // + // If publicip_address is used as the query condition, the format is publicips=ip_version=xxx&publicips=ip_version=xxx. + // + // Note that this parameter has the same meaning as eips. + PublicIps []string `q:"publicips"` + // Specifies the list of AZs where the load balancer is created. + // + // Multiple AZs can be queried in the format of availability_zone_list=xxx&availability_zone_list=xxx. + AvailabilityZoneList []string `q:"availability_zone_list"` // Specifies the ID of a flavor at Layer 4. // // Multiple IDs can be queried in the format of l4_flavor_id=xxx&l4_flavor_id=xxx. - L4FlavorID []string `q:"l4_flavor_id"` + L4FlavorId []string `q:"l4_flavor_id"` // Specifies the ID of the elastic flavor at Layer 4, which is reserved for now. // // Multiple flavors can be queried in the format of l4_scale_flavor_id=xxx&l4_scale_flavor_id=xxx. // // This parameter is unsupported. Please do not use it. - L4ScaleFlavorID []string `q:"l4_scale_flavor_id"` - // Specifies the list of AZs where the load balancer is created. - // - // Multiple AZs can be queried in the format of availability_zone_list=xxx&availability_zone_list=xxx. - AvailabilityZoneList []string `q:"availability_zone_list"` + L4ScaleFlavorId []string `q:"l4_scale_flavor_id"` // Specifies the ID of a flavor at Layer 7. // // Multiple flavors can be queried in the format of l7_flavor_id=xxx&l7_flavor_id=xxx. - L7FlavorID []string `q:"l7_flavor_id"` + L7FlavorId []string `q:"l7_flavor_id"` // Specifies the ID of the elastic flavor at Layer 7. Multiple flavors can be queried in the format of l7_scale_flavor_id=xxx&l7_scale_flavor_id=xxx. This parameter is unsupported. Please do not use it. - L7ScaleFlavorID []string `q:"l7_scale_flavor_id"` - // Specifies the number of records on each page. + L7ScaleFlavorId []string `q:"l7_scale_flavor_id"` + // Provides resource billing information. // - // Minimum: 0 + // Multiple values can be queried in the format of billing_info=xxx&billing_info=xxx. // - // Maximum: 2000 + // This parameter is unsupported. Please do not use it. + BillingInfo []string `q:"billing_info"` + // Specifies the ID of the cloud server that is associated with the load balancer as a backend server. This is a query parameter and will not be included in the response. // - // Default: 2000 - Limit int `q:"limit"` - // Specifies the ID of the last record on the previous page. + // Multiple IDs can be queried in the format of member_device_id=xxx&member_device_id=xxx. + MemberDeviceId []string `q:"member_device_id"` + // Specifies the private IP address of the cloud server that is associated with the load balancer as a backend server. This is a query parameter and will not be included in the response. // - // Note: + // Multiple private IP addresses can be queried in the format of member_address=xxx&member_address=xxx. + MemberAddress []string `q:"member_address"` + // Specifies the enterprise project ID. // - // This parameter must be used together with limit. + // If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project. // - // If this parameter is not specified, the first page will be queried. + // If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried). // - // This parameter cannot be left blank or set to an invalid ID. - Marker string `q:"marker"` + // Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx. // - // Specifies whether to use reverse query. Values: + // This parameter is unsupported. Please do not use it. + EnterpriseProjectId []string `q:"enterprise_project_id"` + // Specifies the IP version. The value can be 4 (IPv4) or 6 (IPv6). // - // true: Query the previous page. + // Multiple versions can be queried in the format of ip_version=xxx&ip_version=xxx. // - // false (default): Query the next page. + // IPv6 is unsupported. The value cannot be 6. + IpVersion []string `q:"ip_version"` + // Specifies whether to enable deletion protection. // - // Note: + // true: Enable deletion protection. // - // This parameter must be used together with limit. + // false: Disable deletion protection. // - // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. - PageReverse *bool `q:"page_reverse"` -} - -// ToLoadbalancerListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToLoadbalancerListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - return q.String(), err + // This parameter is not available in eu-nl region. Please do not use it. + DeletionProtectionEnable *bool `q:"deletion_protection_enable"` + // Specifies the type of the subnet on the downstream plane. + // + // ipv4: IPv4 subnet + // + // dualstack: subnet that supports IPv4/IPv6 dual stack + // + // Multiple values query can be queried in the format of elb_virsubnet_type=ipv4&elb_virsubnet_type=dualstack. + // + // "dualstack" is not supported. + ElbVirSubnetType []string `q:"elb_virsubnet_type"` } -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("loadbalancers") - if opts != nil { - query, err := opts.ToLoadbalancerListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return LoadbalancerPage{PageWithInfo: pagination.NewPageWithInfo(r)} + + // GET /v3/{project_id}/elb/loadbalancers + return pagination.NewPager(client, client.ServiceURL("loadbalancers")+query.String(), func(r pagination.PageResult) pagination.Page { + return LoadBalancerPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +// LoadBalancerPage is the page returned by a pager when traversing over a +// collection of loadbalancer. +type LoadBalancerPage struct { + pagination.PageWithInfo +} + +// IsEmpty checks whether a FlavorsPage struct is empty. +func (r LoadBalancerPage) IsEmpty() (bool, error) { + is, err := ExtractLoadBalancers(r) + return len(is) == 0, err +} + +// ExtractLoadBalancers accepts a Page struct, specifically a LoadBalancerPage struct, +// and extracts the elements into a slice of loadbalancer structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractLoadBalancers(r pagination.Page) ([]LoadBalancer, error) { + var res []LoadBalancer + err := extract.IntoSlicePtr(r.(LoadBalancerPage).BodyReader(), &res, "loadbalancers") + return res, err +} diff --git a/openstack/elb/v3/loadbalancers/results.go b/openstack/elb/v3/loadbalancers/results.go index 474ac5f2e..fbad4f8aa 100644 --- a/openstack/elb/v3/loadbalancers/results.go +++ b/openstack/elb/v3/loadbalancers/results.go @@ -2,7 +2,6 @@ package loadbalancers import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type EipInfo struct { @@ -37,30 +36,6 @@ func (r commonResult) Extract() (*LoadBalancer, error) { return s, nil } -// LoadbalancerPage is the page returned by a pager when traversing over a -// collection of loadbalancer. -type LoadbalancerPage struct { - pagination.PageWithInfo -} - -// IsEmpty checks whether a FlavorsPage struct is empty. -func (r LoadbalancerPage) IsEmpty() (bool, error) { - is, err := ExtractLoadbalancers(r) - return len(is) == 0, err -} - -// ExtractLoadbalancers accepts a Page struct, specifically a LoadbalancerPage struct, -// and extracts the elements into a slice of loadbalancer structs. In other words, -// a generic collection is mapped into a relevant slice. -func ExtractLoadbalancers(r pagination.Page) ([]LoadBalancer, error) { - var s []LoadBalancer - err := (r.(LoadbalancerPage)).ExtractIntoSlicePtr(&s, "loadbalancers") - if err != nil { - return nil, err - } - return s, nil -} - // CreateResult represents the result of a create operation. Call its Extract // method to interpret it as a LoadBalancer. type CreateResult struct { From 080b8d34221dacc3d5f6b9016b84c48484a3efad Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:02:00 +0200 Subject: [PATCH 26/54] Update --- openstack/elb/v3/loadbalancers/Update.go | 188 +++++++++++++++++------ 1 file changed, 138 insertions(+), 50 deletions(-) diff --git a/openstack/elb/v3/loadbalancers/Update.go b/openstack/elb/v3/loadbalancers/Update.go index 6b956710a..196734c25 100644 --- a/openstack/elb/v3/loadbalancers/Update.go +++ b/openstack/elb/v3/loadbalancers/Update.go @@ -1,69 +1,157 @@ package loadbalancers -import "github.com/opentelekomcloud/gophertelekomcloud" - -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToLoadBalancerUpdateMap() (map[string]interface{}, error) -} +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) // UpdateOpts is the common options' struct used in this package's Update // operation. type UpdateOpts struct { - // Human-readable name for the Loadbalancer. Does not have to be unique. + // Specifies the load balancer name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // Human-readable description for the Loadbalancer. - Description *string `json:"description,omitempty"` - - // The administrative state of the Loadbalancer. A valid value is true (UP) - // or false (DOWN). + // Specifies the administrative status of the load balancer. The value can only be true. + // + // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The IP address of the Loadbalancer. + // Provides supplementary information about the load balancer. + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Specifies the ID of the IPv6 subnet where the load balancer resides. You can query parameter id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). + // + // The IPv6 subnet can be updated using ipv6_vip_virsubnet_id, and the private IPv6 address of the load balancer will be changed accordingly. + // + // Note: + // + // This parameter will be passed only when IPv6 is enabled for the subnet. The subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id. + // + // This parameter can be updated only when guaranteed is set to true. + // + // The value will become null if the IPv6 address is unbound from the load balancer. + // + // The IPv4 subnet will not change, if IPv6 subet is updated. This parameter is unsupported. Please do not use it. + Ipv6VipVirsubnetId string `json:"ipv6_vip_virsubnet_id,omitempty"` + // Specifies the ID of the IPv4 subnet where the load balancer resides. You can query parameter neutron_subnet_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). + // + // The IPv4 subnet can be updated using vip_subnet_cidr_id, and the private IPv4 address of the load balancer will be changed accordingly. Note: + // + // If vip_address is also specified, the IP address specified by vip_address must be in the subnet specified by vip_subnet_cidr_id and will be used as the private IPv4 address of the load balancer. + // + // The IPv4 subnet must be in the VPC where the load balancer resides. + // + // This parameter can be updated only when guaranteed is set to true. + // + // The value will become null if the private IPv4 address is unbound from the load balancer. + // + // The IPv6 subnet will not change, if IPv4 subet is updated. + // + // Minimum: 1 + // + // Maximum: 36 + VipSubnetCidrId string `json:"vip_subnet_cidr_id,omitempty"` + // Specifies the private IPv4 address bound to the load balancer. The IP address must be from the IPv4 subnet where the load balancer resides and should not be occupied by other services. + // + // vip_address can be updated only when guaranteed is set to true. + // + // Minimum: 1 + // + // Maximum: 36 VipAddress string `json:"vip_address,omitempty"` - - // The network on which to allocate the Loadbalancer's address. - VipSubnetCidrID *string `json:"vip_subnet_cidr_id,omitempty"` - - // The V6 network on which to allocate the Loadbalancer's address. - IpV6VipSubnetID *string `json:"ipv6_vip_virsubnet_id,omitempty"` - - // The UUID of a l4 flavor. - L4Flavor string `json:"l4_flavor_id,omitempty"` - - // The UUID of a l7 flavor. - L7Flavor string `json:"l7_flavor_id,omitempty"` - - // IPv6 Bandwidth. - IpV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` - - // ELB VirSubnet IDs. - ElbSubnetIDs []string `json:"elb_virsubnet_ids,omitempty"` - - // IP Target Enable. + // Specifies the ID of a flavor at Layer 4. + // + // Note: + // + // This parameter can be updated only when guaranteed is set to true. + // + // The value cannot be changed from null to a specific value, or in the other way around. + // + // If you change the flavor, you can select only a higher or lower one. If you select a lower one, part of persistent connections will be interrupted. + // + // If autoscaling.enable is set to true, updating this parameter will not take effect. + // + // Minimum: 1 + // + // Maximum: 255 + L4FlavorId string `json:"l4_flavor_id,omitempty"` + // Specifies the ID of a flavor at Layer 7. + // + // Note: + // + // This parameter can be updated only when guaranteed is set to true. + // + // The value cannot be changed from null to a specific value, or in the other way around. + // + // If you change the flavor, you can select only a higher or lower one. If you select a lower one, part of persistent connections will be interrupted. + // + // If autoscaling.enable is set to true, updating this parameter will not take effect. + // + // Minimum: 1 + // + // Maximum: 36 + L7FlavorId string `json:"l7_flavor_id,omitempty"` + // Specifies the ID of the bandwidth used by an IPv6 address. This parameter is available only when you create or update a load balancer with a public IPv6 address. If you use a new IPv6 address and specify a shared bandwidth, the IPv6 address will be added to the shared bandwidth. + // + // IPv6 is unsupported. Please do not use this parameter. + Ipv6Bandwidth BandwidthRef `json:"ipv6_bandwidth,omitempty"` + // Specifies whether to enable cross-VPC backend. + // + // If you enable this function, you can add servers in a peer VPC connected through a VPC peering connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using their IP addresses. + // + // This function is supported only by dedicated load balancers. + // + // The value can be true (enable cross-VPC backend) or false (disable cross-VPC backend). + // + // The value can only be update to true. + // + // This parameter is not available in eu-nl region. Please do not use it. IpTargetEnable *bool `json:"ip_target_enable,omitempty"` - + // Specifies the IDs of subnets on the downstream plane. You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). + // + // If the IDs of the subnets required by the load balancer are specified in elb_virsubnet_ids, the subnets will still be bound to the load balancer. + // + // If the IDs of the subnets required by the load balancer are not specified in elb_virsubnet_ids, the subnets will be unbound from the load balancers. Do not unbound the subnets that have been used by the load balancer. Otherwise, an error will be returned. + // + // If the IDs of the subnets are specified in elb_virsubnet_ids, but not on the downstream plane, a new load balancer will be bound to the downstream plane. + // + // Note: + // + // All subnets belong to the same VPC where the load balancer resides. + // + // Edge subnets are not supported. + // + // Minimum: 1 + // + // Maximum: 64 + ElbVirSubnetIds []string `json:"elb_virsubnet_ids,omitempty"` // Specifies whether to enable deletion protection for the load balancer. + // + // true: Enable deletion protection. + // + // false: Disable deletion protection. + // + // Disable deletion protection for all your resources before deleting your account. + // + // This parameter is not available in eu-nl region. Please do not use it. DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` } -// ToLoadBalancerUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToLoadBalancerUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "loadbalancer") -} - -// Update is an operation which modifies the attributes of the specified -// LoadBalancer. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { - b, err := opts.ToLoadBalancerUpdateMap() +// Update is an operation which modifies the attributes of the specified LoadBalancer. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*LoadBalancer, error) { + b, err := build.RequestBody(opts, "loadbalancer") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("loadbalancers", id), b, &r.Body, &golangsdk.RequestOpts{ + + // PUT /v3/{project_id}/elb/loadbalancers/{loadbalancer_id} + raw, err := client.Put(client.ServiceURL("loadbalancers", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) - return + return extra(err, raw) } From c6573855cfb7cebd7bca29fe790c94619f91d3b0 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:12:03 +0200 Subject: [PATCH 27/54] Update --- openstack/elb/v3/loadbalancers/GetStatuses.go | 180 +++++++++++++++++- 1 file changed, 177 insertions(+), 3 deletions(-) diff --git a/openstack/elb/v3/loadbalancers/GetStatuses.go b/openstack/elb/v3/loadbalancers/GetStatuses.go index 84f008166..ebfcfea70 100644 --- a/openstack/elb/v3/loadbalancers/GetStatuses.go +++ b/openstack/elb/v3/loadbalancers/GetStatuses.go @@ -6,15 +6,189 @@ import ( ) // GetStatuses will return the status of a particular LoadBalancer. -func GetStatuses(client *golangsdk.ServiceClient, id string) (*LoadBalancer, error) { +func GetStatuses(client *golangsdk.ServiceClient, id string) (*LoadBalancerStatus, error) { + // GET /v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/statuses raw, err := client.Get(client.ServiceURL("loadbalancers", id, "statuses"), nil, nil) if err != nil { return nil, err } var res struct { - Loadbalancer LoadBalancer `json:"loadbalancer"` + LoadBalancer LoadBalancerStatus `json:"loadbalancer"` } err = extract.IntoStructPtr(raw.Body, &res, "statuses") - return &res.Loadbalancer, nil + return &res.LoadBalancer, err +} + +type LoadBalancerStatus struct { + // Specifies the load balancer name. + // + // Minimum: 1 + // + // Maximum: 255 + Name string `json:"name"` + // Specifies the provisioning status of the load balancer. The value can be ACTIVE or PENDING_DELETE. + // + // ACTIVE: The load balancer is successfully provisioned. + // + // PENDING_DELETE: The load balancer is being deleted. + ProvisioningStatus string `json:"provisioning_status"` + // Lists the listeners added to the load balancer. + Listeners []LoadBalancerStatusListener `json:"listeners"` + // Lists the backend server groups associated with the load balancer. + Pools []LoadBalancerStatusPool `json:"pools"` + // Specifies the load balancer ID. + Id string `json:"id"` + // Specifies the operating status of the load balancer. + // + // The value can only be one of the following: + // + // ONLINE (default): The load balancer is running normally. + // + // FROZEN: The load balancer has been frozen. + // + // DEGRADED: This status is displayed only when operating_status is set to OFFLINE for a backend server associated with the load balancer and the API for querying the load balancer status tree is called. + // + // DISABLED: This status is displayed only when admin_state_up of the load balancer is set to false. + // + // DEGRADED and DISABLED are returned only when the API for querying the load balancer status tree is called. + OperatingStatus string `json:"operating_status"` +} + +type LoadBalancerStatusListener struct { + // Specifies the name of the listener added to the load balancer. + // + // Minimum: 1 + // + // Maximum: 255 + Name string `json:"name"` + // Specifies the provisioning status of the listener. The value can only be ACTIVE, indicating that the listener is successfully provisioned. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies the operating status of the backend server group associated with the listener. + Pools []LoadBalancerStatusPool `json:"pools"` + // Specifies the operating status of the forwarding policy added to the listener. + L7policies []LoadBalancerStatusPolicy `json:"l7policies"` + // Specifies the listener ID. + Id string `json:"id"` + // Specifies the operating status of the listener. + // + // The value can only be one of the following: + // + // ONLINE (default): The listener is running normally. + // + // DEGRADED: This status is displayed only when provisioning_status of a forwarding policy or a forwarding rule added to the listener is set to ERROR or operating_status is set to OFFLINE for a backend server associated with the listener. + // + // DISABLED: This status is displayed only when admin_state_up of the load balancer or of the listener is set to false. Note: DEGRADED and DISABLED are returned only when the API for querying the load balancer status tree is called. + OperatingStatus string `json:"operating_status"` +} + +type LoadBalancerStatusPolicy struct { + // Specifies whether requests are forwarded to another backend server group or redirected to an HTTPS listener. The value can be one of the following: + // + // REDIRECT_TO_POOL: Requests are forwarded to another backend server group. + // + // REDIRECT_TO_LISTENER: Requests are redirected to an HTTPS listener. + Action string `json:"action"` + // Specifies the forwarding policy ID. + Id string `json:"id"` + // Specifies the provisioning status of the forwarding policy. + // + // ACTIVE (default): The forwarding policy is provisioned successfully. + // + // ERROR: Another forwarding policy of the same listener has the same forwarding rule. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies the policy name. + // + // Minimum: 1 + // + // Maximum: 255 + Name string `json:"name"` + // Specifies the forwarding rule. + Rules []LoadBalancerStatusL7Rule `json:"rules"` +} + +type LoadBalancerStatusL7Rule struct { + // Specifies the ID of the forwarding rule. + Id string `json:"id"` + // Specifies the type of the match content. The value can be HOST_NAME or PATH. + // + // HOST_NAME: A domain name will be used for matching. + // + // PATH: A URL will be used for matching. + // + // The value must be unique for each forwarding rule in a forwarding policy. + Type string `json:"type"` + // Specifies the provisioning status of the forwarding rule. + // + // ACTIVE (default): The forwarding rule is successfully provisioned. + // + // ERROR: Another forwarding policy of the same listener has the same forwarding rule. + ProvisioningStatus string `json:"provisioning_status"` +} + +type LoadBalancerStatusPool struct { + // Specifies the provisioning status of the backend server group. The value can only be ACTIVE, indicating that the backend server group is successfully provisioned. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies the name of the backend server group. + // + // Minimum: 1 + // + // Maximum: 255 + Name string `json:"name"` + // Specifies the health check results of backend servers in the load balancer status tree. + HealthMonitor LoadBalancerStatusHealthMonitor `json:"healthmonitor"` + // Specifies the backend server. + Members []LoadBalancerStatusMember `json:"members"` + // Specifies the ID of the backend server group. + Id string `json:"id"` + // Specifies the operating status of the backend server group. + // + // The value can be one of the following: + // + // ONLINE: The backend server group is running normally. + // + // DEGRADED: This status is displayed only when operating_status of a backend server in the backend server group is set to OFFLINE. + // + // DISABLED: This status is displayed only when admin_state_up of the backend server group or of the associated load balancer is set to false. + // + // Note: DEGRADED and DISABLED are returned only when the API for querying the load balancer status tree is called. + OperatingStatus string `json:"operating_status"` +} + +type LoadBalancerStatusHealthMonitor struct { + // Specifies the health check protocol. The value can be TCP, UDP_CONNECT, or HTTP. + Type string `json:"type"` + // Specifies the health check ID. + Id string `json:"id"` + // Specifies the health check name. + // + // Minimum: 1 + // + // Maximum: 255 + Name string `json:"name"` + // Specifies the provisioning status of the health check. The value can only be ACTIVE, indicating that the health check is successfully provisioned. + ProvisioningStatus string `json:"provisioning_status"` +} + +type LoadBalancerStatusMember struct { + // Specifies the provisioning status of the backend server. The value can only be ACTIVE, indicating that the backend server is successfully provisioned. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies the private IP address bound to the backend server. + Address string `json:"address"` + // Specifies the port used by the backend server to receive requests. The port number ranges from 1 to 65535. + ProtocolPort *int `json:"protocol_port"` + // Specifies the backend server ID. + Id string `json:"id"` + // Specifies the operating status of the backend server. + // + // The value can be one of the following: + // + // ONLINE: The backend server is running normally. + // + // NO_MONITOR: No health check is configured for the backend server group to which the backend server belongs. + // + // DISABLED: The backend server is not available. This status is displayed only when admin_state_up of the backend server, or the backend server group to which it belongs, or the associated load balancer is set to false and the API for querying the load balancer status tree is called. + // + // OFFLINE: The cloud server used as the backend server is stopped or does not exist. + OperatingStatus string `json:"operating_status"` } From b23f2e8dd21673146d7122a5c424bd5278aabdd6 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:17:06 +0200 Subject: [PATCH 28/54] loadbalancers --- openstack/elb/v3/loadbalancers/Create.go | 120 ++++++++++++++++++++- openstack/elb/v3/loadbalancers/Get.go | 5 + openstack/elb/v3/loadbalancers/requests.go | 37 ------- 3 files changed, 123 insertions(+), 39 deletions(-) delete mode 100644 openstack/elb/v3/loadbalancers/requests.go diff --git a/openstack/elb/v3/loadbalancers/Create.go b/openstack/elb/v3/loadbalancers/Create.go index a41a59bb8..e589e8e8b 100644 --- a/openstack/elb/v3/loadbalancers/Create.go +++ b/openstack/elb/v3/loadbalancers/Create.go @@ -108,11 +108,11 @@ type CreateOpts struct { // Specifies the ID of the bandwidth used by an IPv6 address. This parameter is available only when you create or update a load balancer with a public IPv6 address. If you use a new IPv6 address and specify a shared bandwidth, the IPv6 address will be added to the shared bandwidth. // // IPv6 is unsupported. Please do not use this parameter. - IPV6Bandwidth *BandwidthRef `json:"ipv6_bandwidth,omitempty"` + IPV6Bandwidth BandwidthRef `json:"ipv6_bandwidth,omitempty"` // Specifies the ID of the EIP the system will automatically assign and bind to the load balancer during load balancer creation. Only the first EIP will be bound to the load balancer although multiple EIP IDs can be set. PublicIpIDs []string `json:"publicip_ids,omitempty"` // Specifies the new EIP that will be bound to the load balancer. - PublicIp *PublicIp `json:"publicip,omitempty"` + PublicIp PublicIp `json:"publicip,omitempty"` // // Specifies the IDs of subnets on the downstream plane. You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). // @@ -154,6 +154,122 @@ type CreateOpts struct { DeletionProtectionEnable *bool `json:"deletion_protection_enable,omitempty"` } +type PublicIp struct { + // Specifies the IP address version. The value can be 4 (IPv4) or 6 (IPv6). + // + // IPv6 is unsupported, and the value cannot be 6. + // + // Default: 4 + IpVersion *int `json:"ip_version,omitempty"` + // Specifies the EIP type. The default value is 5_bgp. For more information, see the API for assigning an EIP in the Virtual Private Cloud API Reference. + // + // Minimum: 1 + // + // Maximum: 36 + NetworkType string `json:"network_type" required:"true"` + // Provides billing information about the EIP. + // + // If the value is left blank, the EIP is billed in pay-per-use mode. + // + // If the value is not left blank, the EIP is billed on a yearly/monthly basis. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 1024 + BillingInfo string `json:"billing_info,omitempty"` + // Provides supplementary information about the EIP. + // + // Minimum: 1 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // bandwidth + Bandwidth Bandwidth `json:"bandwidth" required:"true"` +} + +type Bandwidth struct { + // Specifies the bandwidth name. + // + // The value can contain 1 to 64 characters, including letters, digits, underscores (_), hyphens (-), and periods. + // + // Note: + // + // This parameter is mandatory if share_type is set to PER. + // + // This parameter will be ignored if the bandwidth reference has a specific ID. + // + // Minimum: 1 + // + // Maximum: 64 + Name string `json:"name,omitempty"` + // Specifies the bandwidth range. + // + // The default range is 1 Mbit/s to 2,000 Mbit/s. (The specific range may vary depending on the configuration in each region. You can see the available bandwidth range on the management console.) + // + // Note: + // + // The minimum increment for bandwidth adjustment varies depending on the bandwidth range. The following are the details: + // + // The minimum increment is 1 Mbit/s if the bandwidth range is from 0 Mbit/s to 300 Mbit/s. + // + // The minimum increment is 50 Mbit/s if the bandwidth range is from 301 Mbit/s to 1,000 Mbit/s. + // + // The minimum increment is 500 Mbit/s if the bandwidth is greater than 1,000 Mbit/s. + // + // This parameter is mandatory if id is set to null. + // + // Minimum: 0 + // + // Maximum: 99999 + Size *int `json:"size,omitempty"` + // Specifies how the bandwidth used by the EIP is billed. + // + // Currently, the bandwidth can be billed only by traffic. + // + // This parameter is mandatory if id is set to null. + // + // Minimum: 1 + // + // Maximum: 36 + ChargeMode string `json:"charge_mode,omitempty"` + // Specifies the bandwidth type. + // + // PER: indicates dedicated bandwidth. + // + // WHOLE: indicates shared bandwidth. + // + // Note: + // + // This parameter is mandatory when id is set to null. It will be ignored if the value of id is not null. + // + // The bandwidth ID must be specified if the bandwidth type is set to WHOLE. + // + // The bandwidth type cannot be WHOLE for IPv6 EIPs. + ShareType string `json:"share_type,omitempty"` + // Specifies bandwidth billing information. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 1024 + BillingInfo string `json:"billing_info,omitempty"` + // Specifies the ID of the shared bandwidth to which the IP address bound to the load balancer is added. + // + // Note: + // + // The value is the bandwidth ID when share_type is set to WHOLE. + // + // There is no need to specify this parameter if the billing mode is yearly/monthly. This parameter will be ignored if it is left blank. + // + // Minimum: 1 + // + // Maximum: 36 + Id string `json:"id,omitempty"` +} + // Create is an operation which provisions a new loadbalancer based on the // configuration defined in the CreateOpts struct. Once the request is // validated and progress has started on the provisioning process, a diff --git a/openstack/elb/v3/loadbalancers/Get.go b/openstack/elb/v3/loadbalancers/Get.go index 175d1df4a..dcf40e0d6 100644 --- a/openstack/elb/v3/loadbalancers/Get.go +++ b/openstack/elb/v3/loadbalancers/Get.go @@ -172,3 +172,8 @@ type LoadBalancer struct { // Specifies the AZ group to which the load balancer belongs. PublicBorderGroup string `json:"public_border_group"` } + +type BandwidthRef struct { + // Share Bandwidth ID + ID string `json:"id" required:"true"` +} diff --git a/openstack/elb/v3/loadbalancers/requests.go b/openstack/elb/v3/loadbalancers/requests.go deleted file mode 100644 index e391319e3..000000000 --- a/openstack/elb/v3/loadbalancers/requests.go +++ /dev/null @@ -1,37 +0,0 @@ -package loadbalancers - -type BandwidthRef struct { - // Share Bandwidth ID - ID string `json:"id" required:"true"` -} - -type PublicIp struct { - // IP Version. - IpVersion int `json:"ip_version,omitempty"` - - // Network Type - NetworkType string `json:"network_type" required:"true"` - - // Billing Info. - BillingInfo string `json:"billing_info,omitempty"` - - // Description. - Description string `json:"description,omitempty"` - - // Bandwidth - Bandwidth Bandwidth `json:"bandwidth" required:"true"` -} - -type Bandwidth struct { - // Name - Name string `json:"name" required:"true"` - - // Size - Size int `json:"size" required:"true"` - - // Charge Mode - ChargeMode string `json:"charge_mode" required:"true"` - - // Share Type - ShareType string `json:"share_type" required:"true"` -} From 2e237951eed509c5ab946e1ae2922858c486e2b4 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:43:23 +0200 Subject: [PATCH 29/54] Get --- openstack/elb/v3/members/Create.go | 105 +++++++++++++---------- openstack/elb/v3/members/Get.go | 127 +++++++++++++++++++++++++++- openstack/elb/v3/members/results.go | 35 -------- 3 files changed, 183 insertions(+), 84 deletions(-) diff --git a/openstack/elb/v3/members/Create.go b/openstack/elb/v3/members/Create.go index e0259b76e..88bfe7a52 100644 --- a/openstack/elb/v3/members/Create.go +++ b/openstack/elb/v3/members/Create.go @@ -1,61 +1,76 @@ package members -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToMemberCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's CreateMember -// operation. +// CreateOpts is the common options' struct used in this package's CreateMember operation. type CreateOpts struct { - // The IP address of the member to receive traffic from the load balancer. + // Specifies the private IP address bound to the backend server. + // + // If subnet_cidr_id is left blank, cross-VPC backend is enabled. In this case, the IP address must be an IPv4 address. + // + // If subnet_cidr_id is not left blank, the IP address can be IPv4 or IPv6. It must be in the subnet specified by subnet_cidr_id and can only be bound to the primary NIC of the backend server. + // + // IPv6 is unsupported. Please do not enter an IPv6 address. + // + // Minimum: 1 + // + // Maximum: 64 Address string `json:"address" required:"true"` - - // The port on which to listen for client traffic. - ProtocolPort int `json:"protocol_port" required:"true"` - - // Name of the Member. + // Specifies the administrative status of the backend server. The value can be true or false. + // + // Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether cloud servers exist. If cloud servers exist, the value is true. Otherwise, the value is false. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies the backend server name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // ProjectID is the UUID of the project who owns the Member. - // Only administrative users can specify a project UUID other than their own. - ProjectID string `json:"project_id,omitempty"` - - // Specifies the weight of the backend server. + // Specifies the project ID. // - // Requests are routed to backend servers in the same backend server group based on their weights. + // Minimum: 1 // - // If the weight is 0, the backend server will not accept new requests. + // Maximum: 32 + ProjectId string `json:"project_id,omitempty"` + // Specifies the port used by the backend server to receive requests. // - // This parameter is invalid when lb_algorithm is set to SOURCE_IP for the backend server group that contains the backend server. + // Minimum: 1 + // + // Maximum: 65535 + ProtocolPort *int `json:"protocol_port" required:"true"` + // Specifies the ID of the IPv4 or IPv6 subnet where the backend server resides. + // + // Note: + // + // The IPv4 or IPv6 subnet must be in the same VPC as the subnet of the load balancer. + // + // If this parameter is not passed, cross-VPC backend has been enabled for the load balancer. In this case, cross-VPC backend servers must use private IPv4 addresses, and the protocol of the backend server group must be TCP, HTTP, or HTTPS. + // + // IPv6 is unsupported. Please do not set the value to the ID of an IPv6 subnet. + // + // Minimum: 1 + // + // Maximum: 36 + SubnetCidrId string `json:"subnet_cidr_id,omitempty"` + // Specifies the weight of the backend server. Requests are routed to backend servers in the same backend server group based on their weights. + // + // The value ranges from 0 to 100, and the default value is 1. The larger the weight is, the higher proportion of requests the backend server receives. If the weight is set to 0, the backend server will not accept new requests. + // + // If lb_algorithm is set to SOURCE_IP, this parameter will not take effect. Weight *int `json:"weight,omitempty"` - - // If you omit this parameter, LBaaS uses the vip_subnet_id parameter value - // for the subnet UUID. - SubnetID string `json:"subnet_cidr_id,omitempty"` - - // The administrative state of the Pool. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` -} - -// ToMemberCreateMap builds a request body from CreateOptsBuilder. -func (opts CreateOpts) ToMemberCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "member") } // Create will create and associate a Member with a particular Pool. -func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToMemberCreateMap() +func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOpts) (*Member, error) { + b, err := build.RequestBody(opts, "member") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("pools", poolID, "members"), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{201}, - }) - return + + // POST /v3/{project_id}/elb/pools/{pool_id}/members + raw, err := client.Post(client.ServiceURL("pools", poolID, "members"), b, nil, nil) + return extra(err, raw) } diff --git a/openstack/elb/v3/members/Get.go b/openstack/elb/v3/members/Get.go index 48acf3c6a..44ac84521 100644 --- a/openstack/elb/v3/members/Get.go +++ b/openstack/elb/v3/members/Get.go @@ -1,9 +1,128 @@ package members -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "net/http" + + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" +) // Get retrieves a particular Pool Member based on its unique ID. -func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("pools", poolID, "members", memberID), &r.Body, nil) - return +func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (*Member, error) { + raw, err := client.Get(client.ServiceURL("pools", poolID, "members", memberID), nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*Member, error) { + if err != nil { + return nil, err + } + + var res Member + err = extract.IntoStructPtr(raw.Body, &res, "member") + return &res, err +} + +// Member represents the application running on a backend server. +type Member struct { + // Specifies the backend server ID. + // + // Note: + // + // The value of this parameter is not the ID of the server but an ID automatically generated for the backend server that has already associated with the load balancer. + Id string `json:"id"` + // Specifies the backend server name. + Name string `json:"name"` + // Specifies the project ID of the backend server. + ProjectId string `json:"project_id"` + // Specifies the ID of the backend server group to which the backend server belongs. + // + // This parameter is unsupported. Please do not use it. + PoolId string `json:"pool_id"` + // Specifies the administrative status of the backend server. The value can be true or false. + // + // Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether cloud servers exist. If cloud servers exist, the value is true. Otherwise, the value is false. + AdminStateUp *bool `json:"admin_state_up"` + // Specifies the ID of the IPv4 or IPv6 subnet where the backend server resides. + // + // This parameter can be left blank, indicating that cross-VPC backend has been enabled for the load balancer. In this case, IP addresses of these servers must be IPv4 addresses, and the protocol of the backend server group must be TCP, HTTP, or HTTPS. + // + // The IPv4 or IPv6 subnet must be in the same VPC as the subnet of the load balancer. + // + // IPv6 is unsupported. Please do not set the value to the ID of an IPv6 subnet. + SubnetCidrId string `json:"subnet_cidr_id"` + // Specifies the port used by the backend server to receive requests. + // + // Minimum: 1 + // + // Maximum: 65535 + ProtocolPort *int `json:"protocol_port"` + // Specifies the weight of the backend server. Requests are routed to backend servers in the same backend server group based on their weights. + // + // The value ranges from 0 to 100, and the default value is 1. The larger the weight is, the higher proportion of requests the backend server receives. If the weight is set to 0, the backend server will not accept new requests. + // + // If lb_algorithm is set to SOURCE_IP, this parameter will not take effect. + // + // Minimum: 0 + // + // Maximum: 100 + Weight *int `json:"weight"` + // Specifies the private IP address bound to the backend server. + // + // If subnet_cidr_id is left blank, cross-VPC backend is enabled. In this case, the IP address must be an IPv4 address. + // + // If subnet_cidr_id is not left blank, the IP address can be IPv4 or IPv6. It must be in the subnet specified by subnet_cidr_id and can only be bound to the primary NIC of the backend server. + // + // IPv6 is unsupported. Please do not enter an IPv6 address. + Address string `json:"address"` + // Specifies the IP version supported by the backend server. The value can be v4 (IPv4) or v6 (IPv6), depending on the value of address returned by the system. + IpVersion string `json:"ip_version"` + // Specifies the health status of the backend server if listener_id under status is not specified. The value can be one of the following: + // + // ONLINE: The backend server is running normally. + // + // NO_MONITOR: No health check is configured for the backend server group to which the backend server belongs. + // + // OFFLINE: The cloud server used as the backend server is stopped or does not exist. + OperatingStatus string `json:"operating_status"` + // Specifies the health status of the backend server if listener_id is specified. + Status []MemberStatus `json:"status"` + // Specifies the ID of the load balancer with which the backend server is associated. + // + // This parameter is unsupported. Please do not use it. + LoadBalancerId string `json:"loadbalancer_id"` + // Specifies the IDs of the load balancers associated with the backend server. + // + // This parameter is unsupported. Please do not use it. + LoadBalancers []structs.ResourceRef `json:"loadbalancers"` + // Specifies the time when a backend server was added. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + CreatedAt string `json:"created_at"` + // Specifies the time when a backend server was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + UpdatedAt string `json:"updated_at"` + // Specifies the type of the backend server. Values: + // + // ip: cross-VPC backend servers + // + // instance: ECSs used as backend servers + MemberType string `json:"member_type"` + // Specifies the ID of the ECS used as the backend server. If this parameter is left blank, the backend server is not an ECS. For example, it may be an IP address. + InstanceId string `json:"instance_id"` +} + +type MemberStatus struct { + // Specifies the listener ID. + ListenerId string `json:"listener_id"` + // Specifies the health status of the backend server. The value can be one of the following: + // + // ONLINE: The backend server is running normally. + // + // NO_MONITOR: No health check is configured for the backend server group to which the backend server belongs. + // + // OFFLINE: The cloud server used as the backend server is stopped or does not exist. + OperatingStatus string `json:"operating_status"` } diff --git a/openstack/elb/v3/members/results.go b/openstack/elb/v3/members/results.go index a3e4549f8..8e2fabff2 100644 --- a/openstack/elb/v3/members/results.go +++ b/openstack/elb/v3/members/results.go @@ -5,41 +5,6 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// Member represents the application running on a backend server. -type Member struct { - // Name of the Member. - Name string `json:"name"` - - // Weight of Member. - Weight int `json:"weight"` - - // The administrative state of the member, which is up (true) or down (false). - AdminStateUp bool `json:"admin_state_up"` - - // Owner of the Member. - ProjectID string `json:"project_id"` - - // Parameter value for the subnet UUID. - SubnetID string `json:"subnet_cidr_id"` - - // The Pool to which the Member belongs. - PoolID string `json:"pool_id"` - - // The IP address of the Member. - Address string `json:"address"` - - // The port on which the application is hosted. - ProtocolPort int `json:"protocol_port"` - - // The unique ID for the Member. - ID string `json:"id"` - - IpVersion string `json:"ip_version"` - - // The operating status of the member. - OperatingStatus string `json:"operating_status"` -} - // MemberPage is the page returned by a pager when traversing over a // collection of Members in a Pool. type MemberPage struct { From 748441cbdecf3c139e0d165c1d5417ef3d4ce4df Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:49:12 +0200 Subject: [PATCH 30/54] List --- openstack/elb/v3/members/Get.go | 1 + openstack/elb/v3/members/List.go | 160 +++++++++++++++++++++------- openstack/elb/v3/members/results.go | 27 ----- 3 files changed, 125 insertions(+), 63 deletions(-) diff --git a/openstack/elb/v3/members/Get.go b/openstack/elb/v3/members/Get.go index 44ac84521..90996c86b 100644 --- a/openstack/elb/v3/members/Get.go +++ b/openstack/elb/v3/members/Get.go @@ -10,6 +10,7 @@ import ( // Get retrieves a particular Pool Member based on its unique ID. func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (*Member, error) { + // GET /v3/{project_id}/elb/pools/{pool_id}/members/{member_id} raw, err := client.Get(client.ServiceURL("pools", poolID, "members", memberID), nil, nil) return extra(err, raw) } diff --git a/openstack/elb/v3/members/List.go b/openstack/elb/v3/members/List.go index e4a4a0794..a39a775df 100644 --- a/openstack/elb/v3/members/List.go +++ b/openstack/elb/v3/members/List.go @@ -2,42 +2,112 @@ package members import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToMembersListQuery() (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 Member attributes you want to see returned. SortKey allows // you to sort by a particular Member attribute. SortDir sets the direction, // and is either `asc' or `desc'. Marker and Limit are used for pagination. type ListOpts struct { - Name string `q:"name"` - Weight int `q:"weight"` - AdminStateUp *bool `q:"admin_state_up"` - SubnetID string `q:"subnet_sidr_id"` - Address string `q:"address"` - ProtocolPort int `q:"protocol_port"` - ID string `q:"id"` - OperatingStatus string `q:"operating_status"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` -} - -// ToMembersListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToMembersListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), err + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit *int `q:"limit"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` + // Specifies the backend server name. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Specifies the weight of the backend server. Requests are routed to backend servers in the same backend server group based on their weights. + // + // The value ranges from 0 to 100. The larger the weight is, the higher proportion of requests the backend server receives. If the weight is set to 0, the backend server will not accept new requests. + // + // Multiple weights can be queried in the format of weight=xxx&weight=xxx. + Weight []string `q:"weight"` + // Specifies the administrative status of the backend server. The value can be true or false. + // + // Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether cloud servers exist. If cloud servers exist, the value is true. Otherwise, the value is false. + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the ID of the IPv4 or IPv6 subnet where the backend server resides. + // + // Multiple IDs can be queried in the format of subnet_cidr_id=xxx&subnet_cidr_id=xxx. + // + // IPv6 is unsupported. Please do not set the value to the ID of an IPv6 subnet. + SubnetCidrId []string `q:"subnet_cidr_id"` + // Specifies the IP address bound to the backend server. + // + // Multiple IP addresses can be queried in the format of address=xxx&address=xxx. + // + // IPv6 is unsupported. Please do not set the value to an IPv6 address. + Address []string `q:"address"` + // Specifies the port used by the backend server to receive requests. + // + // Multiple ports can be queried in the format of protocol_port=xxx&protocol_port=xxx. + ProtocolPort []string `q:"protocol_port"` + // Specifies the backend server ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + Id []string `q:"id"` + // Specifies the health status of the backend server. The value can be one of the following: + // + // ONLINE: The backend server is running normally. + // + // NO_MONITOR: No health check is configured for the backend server group to which the backend server belongs. + // + // OFFLINE: The cloud server used as the backend server is stopped or does not exist. + // + // Multiple operating statuses can be queried in the format of operating_status=xxx&operating_status=xxx. + OperatingStatus []string `q:"operating_status"` + // Specifies the enterprise project ID. + // + // If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project. + // + // If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried). + // + // Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx. + // + // This parameter is unsupported. Please do not use it. + EnterpriseProjectId []string `q:"enterprise_project_id"` + // Specifies the IP version supported by the backend server. The value can be v4 (IPv4) or v6 (IPv6). + IpVersion []string `q:"ip_version"` + // Specifies the type of the backend server. Values: + // + // ip: cross-VPC backend servers + // + // instance: ECSs used as backend servers Multiple values can be queried in the format of member_type=xxx&member_type=xxx. + MemberType []string `q:"member_type"` + // Specifies the ID of the instance associated with the backend server. If this parameter is left blank, the backend server is not an ECS. It may be an IP address. + // + // Multiple instance id can be queried in the format of instance_id=xxx&instance_id=xxx. + InstanceId []string `q:"instance_id"` } // List returns a Pager which allows you to iterate over a collection of @@ -46,16 +116,34 @@ func (opts ListOpts) ToMembersListQuery() (string, error) { // // Default policy settings return only those members that are owned by the // tenant who submits the request, unless an admin user submits the request. -func List(client *golangsdk.ServiceClient, poolID string, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("pools", poolID, "members") - if opts != nil { - query, err := opts.ToMembersListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query +func List(client *golangsdk.ServiceClient, poolID string, opts ListOpts) pagination.Pager { + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + + // GET /v3/{project_id}/elb/pools/{pool_id}/members + return pagination.NewPager(client, client.ServiceURL("pools", poolID, "members")+query.String(), func(r pagination.PageResult) pagination.Page { return MemberPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +// MemberPage is the page returned by a pager when traversing over a +// collection of Members in a Pool. +type MemberPage struct { + pagination.PageWithInfo +} + +func (p MemberPage) IsEmpty() (bool, error) { + l, err := ExtractMembers(p) + return len(l) == 0, err +} + +// ExtractMembers accepts a Page struct, specifically a MemberPage struct, +// and extracts the elements into a slice of Members structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractMembers(r pagination.Page) ([]Member, error) { + var res []Member + err := extract.IntoSlicePtr(r.(MemberPage).BodyReader(), &res, "members") + return res, err +} diff --git a/openstack/elb/v3/members/results.go b/openstack/elb/v3/members/results.go index 8e2fabff2..c52d41a79 100644 --- a/openstack/elb/v3/members/results.go +++ b/openstack/elb/v3/members/results.go @@ -2,35 +2,8 @@ package members import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// MemberPage is the page returned by a pager when traversing over a -// collection of Members in a Pool. -type MemberPage struct { - pagination.PageWithInfo -} - -func (p MemberPage) IsEmpty() (bool, error) { - l, err := ExtractMembers(p) - if err != nil { - return false, err - } - return len(l) == 0, nil -} - -// ExtractMembers accepts a Page struct, specifically a MemberPage struct, -// and extracts the elements into a slice of Members structs. In other words, -// a generic collection is mapped into a relevant slice. -func ExtractMembers(r pagination.Page) ([]Member, error) { - var s []Member - err := (r.(MemberPage)).ExtractIntoSlicePtr(&s, "members") - if err != nil { - return nil, err - } - return s, err -} - type commonResult struct { golangsdk.Result } From 9afec5264d9c8570555a24809cdb5e0d3ee3eee0 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:49:58 +0200 Subject: [PATCH 31/54] Delete --- openstack/elb/v3/members/Delete.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openstack/elb/v3/members/Delete.go b/openstack/elb/v3/members/Delete.go index 5003e36cc..3839db8b0 100644 --- a/openstack/elb/v3/members/Delete.go +++ b/openstack/elb/v3/members/Delete.go @@ -6,7 +6,8 @@ import ( // Delete will remove and disassociate a Member from a particular // Pool. -func Delete(client *golangsdk.ServiceClient, poolID string, memberID string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("pools", poolID, "members", memberID), nil) +func Delete(client *golangsdk.ServiceClient, poolID string, memberID string) (err error) { + // DELETE /v3/{project_id}/elb/pools/{pool_id}/members/{member_id} + _, err = client.Delete(client.ServiceURL("pools", poolID, "members", memberID), nil) return } From 496a804ccc49597ffac9e60fb2f5386418ed214a Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:52:48 +0200 Subject: [PATCH 32/54] Update --- openstack/elb/v3/members/Update.go | 66 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/openstack/elb/v3/members/Update.go b/openstack/elb/v3/members/Update.go index 2fdb6ccc6..81efc0872 100644 --- a/openstack/elb/v3/members/Update.go +++ b/openstack/elb/v3/members/Update.go @@ -1,44 +1,46 @@ package members -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) -// UpdateOptsBuilder allows extensions to add additional parameters to the -// List request. -type UpdateOptsBuilder interface { - ToMemberUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts is the common options' struct used in this package's Update -// operation. +// UpdateOpts is the common options' struct used in this package's Update operation. type UpdateOpts struct { - // Name of the Member. - Name *string `json:"name,omitempty"` - - // A positive integer value that indicates the relative portion of traffic - // that this member should receive from the pool. For example, a member with - // a weight of 10 receives five times as much traffic as a member with a - // weight of 2. - Weight *int `json:"weight,omitempty"` - - // The administrative state of the Pool. A valid value is true (UP) - // or false (DOWN). + // Specifies the administrative status of the backend server. + // + // Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether cloud servers exist. If cloud servers exist, the value is true. Otherwise, the value is false. + // + // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` -} - -// ToMemberUpdateMap builds a request body from UpdateOptsBuilder. -func (opts UpdateOpts) ToMemberUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "member") + // Specifies the backend server name. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Specifies the weight of the backend server. Requests are routed to backend servers in the same backend server group based on their weights. + // + // The value ranges from 0 to 100, and the default value is 1. The larger the weight is, the higher proportion of requests the backend server receives. If the weight is set to 0, the backend server will not accept new requests. + // + // If lb_algorithm is set to SOURCE_IP, this parameter will not take effect. + // + // Minimum: 0 + // + // Maximum: 100 + Weight *int `json:"weight,omitempty"` } // Update allows Member to be updated. -func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToMemberUpdateMap() +func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opts UpdateOpts) (*Member, error) { + b, err := build.RequestBody(opts, "member") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("pools", poolID, "members", memberID), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200, 201, 202}, + + // PUT /v3/{project_id}/elb/pools/{pool_id}/members/{member_id} + raw, err := client.Put(client.ServiceURL("pools", poolID, "members", memberID), b, nil, &golangsdk.RequestOpts{ + OkCodes: []int{200}, }) - return + return extra(err, raw) } From b21b7d25206b8b69e0ecef6b2c2e0e21bb6b46e8 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 May 2023 14:55:48 +0200 Subject: [PATCH 33/54] member --- acceptance/openstack/elb/v3/helpers.go | 4 +- .../openstack/elb/v3/loadbalancers_test.go | 8 ++-- acceptance/openstack/elb/v3/members_test.go | 34 +++++++-------- openstack/elb/v3/members/results.go | 43 ------------------- 4 files changed, 21 insertions(+), 68 deletions(-) delete mode 100644 openstack/elb/v3/members/results.go diff --git a/acceptance/openstack/elb/v3/helpers.go b/acceptance/openstack/elb/v3/helpers.go index 14c5795fb..4932802b3 100644 --- a/acceptance/openstack/elb/v3/helpers.go +++ b/acceptance/openstack/elb/v3/helpers.go @@ -50,7 +50,7 @@ func createLoadBalancer(t *testing.T, client *golangsdk.ServiceClient) string { IpTargetEnable: &ipTargetEnable, } - loadbalancer, err := loadbalancers.Create(client, createOpts).Extract() + loadbalancer, err := loadbalancers.Create(client, createOpts) th.AssertNoErr(t, err) th.AssertEquals(t, createOpts.Name, loadbalancer.Name) th.AssertEquals(t, createOpts.Description, loadbalancer.Description) @@ -61,7 +61,7 @@ func createLoadBalancer(t *testing.T, client *golangsdk.ServiceClient) string { func deleteLoadbalancer(t *testing.T, client *golangsdk.ServiceClient, loadbalancerID string) { t.Logf("Attempting to delete ELBv3 LoadBalancer: %s", loadbalancerID) - err := loadbalancers.Delete(client, loadbalancerID).ExtractErr() + err := loadbalancers.Delete(client, loadbalancerID) th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 LoadBalancer: %s", loadbalancerID) } diff --git a/acceptance/openstack/elb/v3/loadbalancers_test.go b/acceptance/openstack/elb/v3/loadbalancers_test.go index 93442a41c..a9a9ae284 100644 --- a/acceptance/openstack/elb/v3/loadbalancers_test.go +++ b/acceptance/openstack/elb/v3/loadbalancers_test.go @@ -40,10 +40,10 @@ func TestLoadBalancerLifecycle(t *testing.T) { emptyDescription := "" updateOptsDpE := loadbalancers.UpdateOpts{ Name: lbName, - Description: &emptyDescription, + Description: emptyDescription, DeletionProtectionEnable: pointerto.Bool(true), } - _, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpE).Extract() + _, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpE) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID) @@ -54,10 +54,10 @@ func TestLoadBalancerLifecycle(t *testing.T) { updateOptsDpD := loadbalancers.UpdateOpts{ Name: lbName, - Description: &emptyDescription, + Description: emptyDescription, DeletionProtectionEnable: pointerto.Bool(false), } - _, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpD).Extract() + _, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpD) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID) diff --git a/acceptance/openstack/elb/v3/members_test.go b/acceptance/openstack/elb/v3/members_test.go index 9256c59d7..31f746c1d 100644 --- a/acceptance/openstack/elb/v3/members_test.go +++ b/acceptance/openstack/elb/v3/members_test.go @@ -12,10 +12,6 @@ import ( th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" ) -func iInt(v int) *int { - return &v -} - func TestMemberLifecycle(t *testing.T) { client, err := clients.NewElbV3Client() th.AssertNoErr(t, err) @@ -33,39 +29,39 @@ func TestMemberLifecycle(t *testing.T) { createOpts := members.CreateOpts{ Address: openstack.ValidIP(t, clients.EnvOS.GetEnv("NETWORK_ID")), - ProtocolPort: 89, + ProtocolPort: pointerto.Int(89), Name: memberName, - Weight: iInt(1), + Weight: pointerto.Int(1), } - member, err := members.Create(client, poolID, createOpts).Extract() + member, err := members.Create(client, poolID, createOpts) th.AssertNoErr(t, err) t.Cleanup(func() { - t.Logf("Attempting to delete ELBv3 Member: %s", member.ID) - err := members.Delete(client, poolID, member.ID).ExtractErr() + t.Logf("Attempting to delete ELBv3 Member: %s", member.Id) + err := members.Delete(client, poolID, member.Id) th.AssertNoErr(t, err) - t.Logf("Deleted ELBv3 Member: %s", member.ID) + t.Logf("Deleted ELBv3 Member: %s", member.Id) }) th.AssertEquals(t, createOpts.Name, member.Name) th.AssertEquals(t, createOpts.ProtocolPort, member.ProtocolPort) th.AssertEquals(t, createOpts.Address, member.Address) th.AssertEquals(t, *createOpts.Weight, member.Weight) - t.Logf("Created ELBv3 Member: %s", member.ID) + t.Logf("Created ELBv3 Member: %s", member.Id) - t.Logf("Attempting to update ELBv3 Member: %s", member.ID) + t.Logf("Attempting to update ELBv3 Member: %s", member.Id) memberName = "" updateOpts := members.UpdateOpts{ - Name: &memberName, - Weight: iInt(0), + Name: memberName, + Weight: pointerto.Int(0), } - _, err = members.Update(client, poolID, member.ID, updateOpts).Extract() + _, err = members.Update(client, poolID, member.Id, updateOpts) th.AssertNoErr(t, err) - t.Logf("Updated ELBv3 Member: %s", member.ID) + t.Logf("Updated ELBv3 Member: %s", member.Id) - newMember, err := members.Get(client, poolID, member.ID).Extract() + newMember, err := members.Get(client, poolID, member.Id) th.AssertNoErr(t, err) - th.AssertEquals(t, *updateOpts.Name, newMember.Name) - th.AssertEquals(t, *updateOpts.Weight, newMember.Weight) + th.AssertEquals(t, updateOpts.Name, newMember.Name) + th.AssertEquals(t, updateOpts.Weight, newMember.Weight) updateOptsPool := pools.UpdateOpts{ DeletionProtectionEnable: pointerto.Bool(false), diff --git a/openstack/elb/v3/members/results.go b/openstack/elb/v3/members/results.go deleted file mode 100644 index c52d41a79..000000000 --- a/openstack/elb/v3/members/results.go +++ /dev/null @@ -1,43 +0,0 @@ -package members - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -type commonResult struct { - golangsdk.Result -} - -// Extract is a function that accepts a result and extracts a Member. -func (r commonResult) Extract() (*Member, error) { - s := new(Member) - err := r.ExtractIntoStructPtr(s, "member") - if err != nil { - return nil, err - } - return s, nil -} - -// CreateResult represents the result of a Create operation. -// Call its Extract method to interpret it as a Member. -type CreateResult struct { - commonResult -} - -// GetResult represents the result of a Get operation. -// Call its Extract method to interpret it as a Member. -type GetResult struct { - commonResult -} - -// UpdateResult represents the result of an Update operation. -// Call its Extract method to interpret it as a Member. -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 { - golangsdk.ErrResult -} From 1d5425e84776ac4d3c4f504a16e2e518f99b91ac Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 28 Jun 2023 22:42:32 +0200 Subject: [PATCH 34/54] Create --- openstack/elb/v3/monitors/Create.go | 195 +++++++++++++++++---------- openstack/elb/v3/monitors/results.go | 10 +- 2 files changed, 129 insertions(+), 76 deletions(-) diff --git a/openstack/elb/v3/monitors/Create.go b/openstack/elb/v3/monitors/Create.go index 88dbe429e..0b09e87cb 100644 --- a/openstack/elb/v3/monitors/Create.go +++ b/openstack/elb/v3/monitors/Create.go @@ -1,89 +1,144 @@ package monitors -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) -// CreateOptsBuilder allows extensions to add additional parameters to the -// List request. -type CreateOptsBuilder interface { - ToMonitorCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's Create -// operation. +// CreateOpts is the common options' struct used in this package's Create operation. type CreateOpts struct { - // The Pool to Monitor. - PoolID string `json:"pool_id" required:"true"` - - // Specifies the health check protocol. + // Specifies the administrative status of the health check. // - // The value can be TCP, UDP_CONNECT, HTTP, HTTPS, or PING. - Type Type `json:"type" required:"true"` - - // The time, in seconds, between sending probes to members. - Delay int `json:"delay" required:"true"` - - // Specifies the maximum time required for waiting for a response from the health check, in seconds. - // It is recommended that you set the value less than that of parameter delay. - Timeout int `json:"timeout" required:"true"` - - // Specifies the number of consecutive health checks when the health check result of a backend server changes - // from OFFLINE to ONLINE. The value ranges from 1 to 10. - MaxRetries int `json:"max_retries" required:"true"` - - // Specifies the number of consecutive health checks when the health check result of a backend server changes - // from ONLINE to OFFLINE. - MaxRetriesDown int `json:"max_retries_down,omitempty"` - - // Specifies the HTTP request path for the health check. - // The value must start with a slash (/), and the default value is /. This parameter is available only when type is set to HTTP. - URLPath string `json:"url_path,omitempty"` - + // true (default): Health check is enabled. + // + // false: Health check is disabled. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies the interval between health checks, in seconds. The value ranges from 1 to 50. + Delay *int `json:"delay" required:"true"` // Specifies the domain name that HTTP requests are sent to during the health check. + // + // The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter. + // + // The value is left blank by default, indicating that the virtual IP address of the load balancer is used as the destination address of HTTP requests. + // // This parameter is available only when type is set to HTTP. + // + // Minimum: 1 + // + // Maximum: 100 DomainName string `json:"domain_name,omitempty"` - - // The HTTP method used for requests by the Monitor. If this attribute - // is not specified, it defaults to "GET". - HTTPMethod string `json:"http_method,omitempty"` - - // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify - // a single status like "200", or a range like "200-202". + // Specifies the expected HTTP status code. This parameter will take effect only when type is set to HTTP or HTTPS. + // + // The value options are as follows: + // + // A specific value, for example, 200 + // + // A list of values that are separated with commas (,), for example, 200, 202 + // + // A value range, for example, 200-204 + // + // The default value is 200. Multiple status codes can be queried in the format of expected_codes=xxx&expected_codes=xxx. + // + // Minimum: 1 + // + // Maximum: 64 ExpectedCodes string `json:"expected_codes,omitempty"` - - // ProjectID is the UUID of the project who owns the Monitor. - // Only administrative users can specify a project UUID other than their own. - ProjectID string `json:"project_id,omitempty"` - - // The Name of the Monitor. + // Specifies the HTTP method. The value can be GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, or PATCH. The default value is GET. + // + // This parameter is available when type is set to HTTP or HTTPS. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 16 + HttpMethod string `json:"http_method,omitempty"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. + // + // The value ranges from 1 to 10. + // + // Minimum: 1 + // + // Maximum: 10 + MaxRetries *int `json:"max_retries" required:"true"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE. + // + // The value ranges from 1 to 10, and the default value is 3. + // + // Minimum: 1 + // + // Maximum: 10 + // + // Default: 3 + MaxRetriesDown *int `json:"max_retries_down,omitempty"` + // Specifies the port used for the health check. If this parameter is left blank, a port of the backend server will be used by default. The port number ranges from 1 to 65535. + // + // Minimum: 1 + // + // Maximum: 65535 + MonitorPort *int `json:"monitor_port,omitempty"` + // Specifies the health check name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // The administrative state of the Monitor. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The Port of the Monitor. - MonitorPort int `json:"monitor_port,omitempty"` + // Specifies the ID of the backend server group for which the health check is configured. + PoolId string `json:"pool_id" required:"true"` + // Specifies the project ID. + // + // Minimum: 1 + // + // Maximum: 32 + ProjectId string `json:"project_id,omitempty"` + // Specifies the maximum time required for waiting for a response from the health check, in seconds. It is recommended that you set the value less than that of parameter delay. + // + // Minimum: 1 + // + // Maximum: 50 + Timeout *int `json:"timeout" required:"true"` + // Specifies the health check protocol. The value can be TCP, UDP_CONNECT, HTTP, or HTTPS. + // + // Note: + // + // If the protocol of the backend server is QUIC, the value can only be UDP_CONNECT. + // + // If the protocol of the backend server is UDP, the value can only be UDP_CONNECT. + // + // If the protocol of the backend server is TCP, the value can only be TCP, HTTP, or HTTPS. + // + // If the protocol of the backend server is HTTP, the value can only be TCP, HTTP, or HTTPS. + // + // If the protocol of the backend server is HTTPS, the value can only be TCP, HTTP, or HTTPS. + // + // QUIC protocol is not supported in eu-nl region. + Type string `json:"type" required:"true"` + // Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /. Note: This parameter is available only when type is set to HTTP. + // + // Default: / + // + // Minimum: 1 + // + // Maximum: 80 + UrlPath string `json:"url_path,omitempty"` } -// ToMonitorCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToMonitorCreateMap() (map[string]interface{}, error) { - b, err := golangsdk.BuildRequestBody(opts, "healthmonitor") +// Create is an operation which provisions a new Health Monitor. There are +// different types of Monitor you can provision: PING, TCP or HTTP(S). Below +// are examples of how to create each one. +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Monitor, error) { + b, err := build.RequestBody(opts, "healthmonitor") if err != nil { return nil, err } - return b, nil -} - -// Create is an operation which provisions a new Health Monitor. There are -// different types of Monitor you can provision: PING, TCP or HTTP(S). Below -// are examples of how to create each one. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToMonitorCreateMap() + raw, err := client.Post(client.ServiceURL("healthmonitors"), b, nil, nil) if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("healthmonitors"), b, &r.Body, nil) - return + + var res Monitor + err = extract.IntoStructPtr(raw.Body, res, "healthmonitor") + return &res, err } diff --git a/openstack/elb/v3/monitors/results.go b/openstack/elb/v3/monitors/results.go index 726588a79..1a8b785d6 100644 --- a/openstack/elb/v3/monitors/results.go +++ b/openstack/elb/v3/monitors/results.go @@ -2,6 +2,7 @@ package monitors import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) @@ -105,12 +106,9 @@ type commonResult struct { // Extract is a function that accepts a result and extracts a Monitor. func (r commonResult) Extract() (*Monitor, error) { - s := new(Monitor) - err := r.ExtractIntoStructPtr(s, "healthmonitor") - if err != nil { - return nil, err - } - return s, nil + var res Monitor + err := extract.IntoStructPtr(res, "healthmonitor") + return &res, err } // CreateResult represents the result of a create operation. Call its Extract From 111c1903c7180f4743c612217b6a7aa58c91ac2f Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:13:15 +0200 Subject: [PATCH 35/54] Get --- openstack/elb/v3/monitors/Create.go | 9 +-------- openstack/elb/v3/monitors/Delete.go | 4 ++-- openstack/elb/v3/monitors/Get.go | 23 +++++++++++++++++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/openstack/elb/v3/monitors/Create.go b/openstack/elb/v3/monitors/Create.go index 0b09e87cb..dfa7c02cf 100644 --- a/openstack/elb/v3/monitors/Create.go +++ b/openstack/elb/v3/monitors/Create.go @@ -3,7 +3,6 @@ package monitors import ( "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/build" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) // CreateOpts is the common options' struct used in this package's Create operation. @@ -134,11 +133,5 @@ func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Monitor, error) } raw, err := client.Post(client.ServiceURL("healthmonitors"), b, nil, nil) - if err != nil { - return nil, err - } - - var res Monitor - err = extract.IntoStructPtr(raw.Body, res, "healthmonitor") - return &res, err + return extra(err, raw) } diff --git a/openstack/elb/v3/monitors/Delete.go b/openstack/elb/v3/monitors/Delete.go index ef12edfb1..7c04a7b51 100644 --- a/openstack/elb/v3/monitors/Delete.go +++ b/openstack/elb/v3/monitors/Delete.go @@ -3,7 +3,7 @@ package monitors import "github.com/opentelekomcloud/gophertelekomcloud" // Delete will permanently delete a particular Monitor based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("healthmonitors", id), nil) +func Delete(client *golangsdk.ServiceClient, id string) (err error) { + _, err = client.Delete(client.ServiceURL("healthmonitors", id), nil) return } diff --git a/openstack/elb/v3/monitors/Get.go b/openstack/elb/v3/monitors/Get.go index dc624134b..156bd7d2e 100644 --- a/openstack/elb/v3/monitors/Get.go +++ b/openstack/elb/v3/monitors/Get.go @@ -1,9 +1,24 @@ package monitors -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "net/http" + + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) // Get retrieves a particular Health Monitor based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("healthmonitors", id), &r.Body, nil) - return +func Get(client *golangsdk.ServiceClient, id string) (*Monitor, error) { + raw, err := client.Get(client.ServiceURL("healthmonitors", id), nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*Monitor, error) { + if err != nil { + return nil, err + } + + var res Monitor + err = extract.IntoStructPtr(raw.Body, res, "healthmonitor") + return &res, err } From 712f304b5f7fa2b7394859b8c2ea543d6849df5e Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:22:30 +0200 Subject: [PATCH 36/54] List --- acceptance/openstack/elb/v3/monitors_test.go | 31 ++-- openstack/elb/v3/monitors/Get.go | 119 ++++++++++++++ openstack/elb/v3/monitors/List.go | 157 ++++++++++++++++--- openstack/elb/v3/monitors/requests.go | 11 -- openstack/elb/v3/monitors/results.go | 95 ----------- 5 files changed, 266 insertions(+), 147 deletions(-) delete mode 100644 openstack/elb/v3/monitors/requests.go diff --git a/acceptance/openstack/elb/v3/monitors_test.go b/acceptance/openstack/elb/v3/monitors_test.go index 0e7c7dc15..efa4d3e88 100644 --- a/acceptance/openstack/elb/v3/monitors_test.go +++ b/acceptance/openstack/elb/v3/monitors_test.go @@ -5,6 +5,7 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/monitors" th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" ) @@ -40,28 +41,28 @@ func TestMonitorLifecycle(t *testing.T) { t.Logf("Attempting to Create ELBv3 Monitor") monitorName := tools.RandomString("create-monitor-", 3) createOpts := monitors.CreateOpts{ - PoolID: poolID, - Type: monitors.TypeHTTP, - Delay: 1, - Timeout: 30, - MaxRetries: 3, - HTTPMethod: "OPTIONS", + PoolId: poolID, + Type: "HTTP", + Delay: pointerto.Int(1), + Timeout: pointerto.Int(30), + MaxRetries: pointerto.Int(3), + HttpMethod: "OPTIONS", ExpectedCodes: "200-299", Name: monitorName, } - monitor, err := monitors.Create(client, createOpts).Extract() + monitor, err := monitors.Create(client, createOpts) th.AssertNoErr(t, err) t.Cleanup(func() { - t.Logf("Attempting to Delete ELBv3 Monitor: %s", monitor.ID) - err := monitors.Delete(client, monitor.ID).ExtractErr() + t.Logf("Attempting to Delete ELBv3 Monitor: %s", monitor.Id) + err := monitors.Delete(client, monitor.Id) th.AssertNoErr(t, err) - t.Logf("Deleted ELBv3 Monitor: %s", monitor.ID) + t.Logf("Deleted ELBv3 Monitor: %s", monitor.Id) }) th.AssertEquals(t, createOpts.Name, monitor.Name) th.AssertEquals(t, createOpts.Type, monitor.Type) th.AssertEquals(t, createOpts.MaxRetries, monitor.MaxRetries) - t.Logf("Created ELBv3 Monitor: %s", monitor.ID) + t.Logf("Created ELBv3 Monitor: %s", monitor.Id) t.Logf("Attempting to Update ELBv3 Monitor") monitorName = tools.RandomString("update-monitor-", 3) @@ -72,15 +73,15 @@ func TestMonitorLifecycle(t *testing.T) { MaxRetriesDown: 3, Name: monitorName, } - _, err = monitors.Update(client, monitor.ID, updateOpts).Extract() + _, err = monitors.Update(client, monitor.Id, updateOpts).Extract() th.AssertNoErr(t, err) - t.Logf("Updated ELBv3 Monitor: %s", monitor.ID) + t.Logf("Updated ELBv3 Monitor: %s", monitor.Id) - newMonitor, err := monitors.Get(client, monitor.ID).Extract() + newMonitor, err := monitors.Get(client, monitor.Id) th.AssertNoErr(t, err) th.AssertEquals(t, updateOpts.Name, newMonitor.Name) th.AssertEquals(t, updateOpts.Timeout, newMonitor.Timeout) th.AssertEquals(t, updateOpts.Delay, newMonitor.Delay) th.AssertEquals(t, updateOpts.MaxRetries, newMonitor.MaxRetries) - th.AssertEquals(t, createOpts.HTTPMethod, newMonitor.HTTPMethod) + th.AssertEquals(t, createOpts.HttpMethod, newMonitor.HttpMethod) } diff --git a/openstack/elb/v3/monitors/Get.go b/openstack/elb/v3/monitors/Get.go index 156bd7d2e..8e457f09e 100644 --- a/openstack/elb/v3/monitors/Get.go +++ b/openstack/elb/v3/monitors/Get.go @@ -5,6 +5,7 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" ) // Get retrieves a particular Health Monitor based on its unique ID. @@ -22,3 +23,121 @@ func extra(err error, raw *http.Response) (*Monitor, error) { err = extract.IntoStructPtr(raw.Body, res, "healthmonitor") return &res, err } + +// Monitor represents a load balancer health monitor. A health monitor is used +// to determine whether back-end members of the VIP's pool are usable +// for processing a request. A pool can have several health monitors associated +// with it. There are different types of health monitors supported: +// +// PING: used to ping the members using ICMP. +// TCP: used to connect to the members using TCP. +// HTTP: used to send an HTTP request to the member. +// HTTPS: used to send a secure HTTP request to the member. +// +// When a pool has several monitors associated with it, each member of the pool +// is monitored by all these monitors. If any monitor declares the member as +// unhealthy, then the member status is changed to INACTIVE and the member +// won't participate in its pool's load balancing. In other words, ALL monitors +// must declare the member to be healthy for it to stay ACTIVE. +type Monitor struct { + // Specifies the administrative status of the health check. + // + // true(default) indicates that the health check is enabled. + // + // false indicates that the health check is disabled. + AdminStateUp *bool `json:"admin_state_up"` + // Specifies the interval between health checks, in seconds. The value ranges from 1 to 50. + // + // Minimum: 1 + // + // Maximum: 50 + Delay *int `json:"delay"` + // Specifies the domain name that HTTP requests are sent to during the health check. + // + // The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter. + // + // The value is left blank by default, indicating that the virtual IP address of the load balancer is used as the destination address of HTTP requests. + // + // This parameter is available only when type is set to HTTP. + DomainName string `json:"domain_name"` + // Specifies the expected HTTP status code. This parameter will take effect only when type is set to HTTP or HTTPS. + // + // The value options are as follows: + // + // A specific value, for example, 200 + // + // A list of values that are separated with commas (,), for example, 200, 202 + // + // A value range, for example, 200-204 + // + // The default value is 200. Multiple status codes can be queried in the format of expected_codes=xxx&expected_codes=xxx. + ExpectedCodes string `json:"expected_codes"` + // Specifies the HTTP method. The value can be GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, or PATCH. The default value is GET. + // + // This parameter is available when type is set to HTTP or HTTPS. + // + // This parameter is unsupported. Please do not use it. + HttpMethod string `json:"http_method"` + // Specifies the health check ID. + Id string `json:"id"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. + // + // The value ranges from 1 to 10 + // + // Minimum: 1 + // + // Maximum: 10 + MaxRetries *int `json:"max_retries"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE. + // + // The value ranges from 1 to 10, and the default value is 3. + // + // Minimum: 1 + // + // Maximum: 10 + MaxRetriesDown *int `json:"max_retries_down"` + // Specifies the port used for the health check. If this parameter is left blank, a port of the backend server will be used by default. The port number ranges from 1 to 65535. + // + // Minimum: 1 + // + // Maximum: 65535 + MonitorPort *int `json:"monitor_port"` + // Specifies the health check name. + Name string `json:"name"` + // Lists the IDs of backend server groups for which the health check is configured. Only one ID will be returned. + Pools []structs.ResourceRef `json:"pools"` + // Specifies the project ID. + ProjectId string `json:"project_id"` + // Specifies the maximum time required for waiting for a response from the health check, in seconds. It is recommended that you set the value less than that of parameter delay. + // + // Minimum: 1 + // + // Maximum: 50 + Timeout *int `json:"timeout"` + // Specifies the health check protocol. The value can be TCP, UDP_CONNECT, HTTP, or HTTPS. + // + // Note: + // + // If the protocol of the backend server is QUIC, the value can only be UDP_CONNECT. + // + // If the protocol of the backend server is UDP, the value can only be UDP_CONNECT. + // + // If the protocol of the backend server is TCP, the value can only be TCP, HTTP, or HTTPS. + // + // If the protocol of the backend server is HTTP, the value can only be TCP, HTTP, or HTTPS. + // + // If the protocol of the backend server is HTTPS, the value can only be TCP, HTTP, or HTTPS. + // + // QUIC protocol is not supported in eu-nl region. + Type string `json:"type"` + // Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /. Note: This parameter is available only when type is set to HTTP. + UrlPath string `json:"url_path"` + // Specifies the time when the health check was configured. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + CreatedAt string `json:"created_at"` + // Specifies the time when the health check was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + UpdatedAt string `json:"updated_at"` +} diff --git a/openstack/elb/v3/monitors/List.go b/openstack/elb/v3/monitors/List.go index 826f01563..d66ea010b 100644 --- a/openstack/elb/v3/monitors/List.go +++ b/openstack/elb/v3/monitors/List.go @@ -2,6 +2,7 @@ package monitors import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) @@ -17,24 +18,110 @@ type ListOptsBuilder interface { // sort by a particular Monitor attribute. SortDir sets the direction, and is // either `asc' or `desc'. Marker and Limit are used for pagination. type ListOpts struct { - ID string `q:"id"` - Name string `q:"name"` - TenantID string `q:"tenant_id"` - ProjectID string `q:"project_id"` - PoolID string `q:"pool_id"` - Type string `q:"type"` - Delay int `q:"delay"` - Timeout int `q:"timeout"` - MaxRetries int `q:"max_retries"` - HTTPMethod string `q:"http_method"` - URLPath string `q:"url_path"` - ExpectedCodes string `q:"expected_codes"` - AdminStateUp *bool `q:"admin_state_up"` - Status string `q:"status"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit *int `q:"limit"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` + // Specifies the health check ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + Id []string `q:"id"` + // Specifies the port used for the health check. + // + // Multiple ports can be queried in the format of monitor_port=xxx&monitor_port=xxx. + MonitorPort []string `q:"monitor_port"` + // Specifies the domain name to which HTTP requests are sent during the health check. + // + // The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter. + // + // Multiple domain names can be queried in the format of domain_name=xxx&domain_name=xxx. + DomainName []string `q:"domain_name"` + // Specifies the health check name. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Specifies the interval between health checks, in seconds. The value ranges from 1 to 50. + // + // Multiple intervals can be queried in the format of delay=xxx&delay=xxx. + Delay []string `q:"delay"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. + // + // Multiple values can be queried in the format of max_retries=xxx&max_retries=xxx. + MaxRetries []string `q:"max_retries"` + // Specifies the administrative status of the health check. + // + // The value can be true (health check is enabled) or false (health check is disabled). + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE. The value ranges from 1 to 10. + // + // Multiple values can be queried in the format of max_retries_down=xxx&max_retries_down=xxx. + MaxRetriesDown []string `q:"max_retries_down"` + // Specifies the maximum time required for waiting for a response from the health check, in seconds. + Timeout *int `q:"timeout"` + // Specifies the health check protocol. The value can be TCP, UDP_CONNECT, HTTP, or HTTPS. + // + // Multiple protocols can be queried in the format of type=xxx&type=xxx. + Type []string `q:"type"` + // Specifies the expected HTTP status code. This parameter will take effect only when type is set to HTTP or HTTPS. + // + // The value options are as follows: + // + // A specific value, for example, 200 + // + // A list of values that are separated with commas (,), for example, 200, 202 + // + // A value range, for example, 200-204 + // + // The default value is 200. Multiple status codes can be queried in the format of expected_codes=xxx&expected_codes=xxx. + ExpectedCodes []string `q:"expected_codes"` + // Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /. This parameter is available only when type is set to HTTP. + // + // Multiple paths can be queried in the format of url_path=xxx&url_path=xxx. + UrlPath []string `q:"url_path"` + // Specifies the HTTP method. + // + // The value can be GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, or PATCH. + // + // Multiple methods can be queried in the format of http_method=xxx&http_method=xxx. + // + // This parameter is unsupported. Please do not use it. + HttpMethod []string `q:"http_method"` + // Specifies the enterprise project ID. + // + // If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project. + // + // If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried). + // + // Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx. + // + // This parameter is unsupported. Please do not use it. + EnterpriseProjectId []string `q:"enterprise_project_id"` } // ToMonitorListQuery formats a ListOpts into a query string. @@ -53,15 +140,33 @@ func (opts ListOpts) ToMonitorListQuery() (string, error) { // Default policy settings return only those health monitors that are owned by the // tenant who submits the request, unless an admin user submits the request. func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("healthmonitors") - if opts != nil { - query, err := opts.ToMonitorListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + + return pagination.NewPager(client, client.ServiceURL("healthmonitors")+query.String(), func(r pagination.PageResult) pagination.Page { return MonitorPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +// MonitorPage is the page returned by a pager when traversing over a +// collection of health monitors. +type MonitorPage struct { + pagination.PageWithInfo +} + +// IsEmpty checks whether a MonitorPage struct is empty. +func (r MonitorPage) IsEmpty() (bool, error) { + is, err := ExtractMonitors(r) + return len(is) == 0, err +} + +// ExtractMonitors accepts a Page struct, specifically a MonitorPage struct, +// and extracts the elements into a slice of Monitor structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractMonitors(r pagination.Page) ([]Monitor, error) { + var res []Monitor + err := extract.IntoSlicePtr(r.(MonitorPage).BodyReader(), &res, "healthmonitors") + return res, err +} diff --git a/openstack/elb/v3/monitors/requests.go b/openstack/elb/v3/monitors/requests.go deleted file mode 100644 index 505a2f77e..000000000 --- a/openstack/elb/v3/monitors/requests.go +++ /dev/null @@ -1,11 +0,0 @@ -package monitors - -type Type string - -// Constants that represent approved monitoring types. -const ( - TypePING Type = "PING" - TypeTCP Type = "TCP" - TypeHTTP Type = "HTTP" - TypeHTTPS Type = "HTTPS" -) diff --git a/openstack/elb/v3/monitors/results.go b/openstack/elb/v3/monitors/results.go index 1a8b785d6..9e7e3ee2b 100644 --- a/openstack/elb/v3/monitors/results.go +++ b/openstack/elb/v3/monitors/results.go @@ -3,103 +3,8 @@ package monitors import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// Monitor represents a load balancer health monitor. A health monitor is used -// to determine whether back-end members of the VIP's pool are usable -// for processing a request. A pool can have several health monitors associated -// with it. There are different types of health monitors supported: -// -// PING: used to ping the members using ICMP. -// TCP: used to connect to the members using TCP. -// HTTP: used to send an HTTP request to the member. -// HTTPS: used to send a secure HTTP request to the member. -// -// When a pool has several monitors associated with it, each member of the pool -// is monitored by all these monitors. If any monitor declares the member as -// unhealthy, then the member status is changed to INACTIVE and the member -// won't participate in its pool's load balancing. In other words, ALL monitors -// must declare the member to be healthy for it to stay ACTIVE. -type Monitor struct { - // The unique ID for the Monitor. - ID string `json:"id"` - - // The Name of the Monitor. - Name string `json:"name"` - - // Specifies the project ID. - ProjectID string `json:"project_id"` - - // The type of probe sent by the load balancer to verify the member state, - // which is PING, TCP, HTTP, or HTTPS. - Type Type `json:"type"` - - // The time, in seconds, between sending probes to members. - Delay int `json:"delay"` - - // The maximum number of seconds for a monitor to wait for a connection to be - // established before it times out. This value must be less than the delay - // value. - Timeout int `json:"timeout"` - - // Specifies the number of consecutive health checks when the health check result of a backend server changes - // from OFFLINE to ONLINE. - MaxRetries int `json:"max_retries"` - - // Specifies the number of consecutive health checks when the health check result of a backend server changes - // from ONLINE to OFFLINE. - MaxRetriesDown int `json:"max_retries_down"` - - // The HTTP method that the monitor uses for requests. - HTTPMethod string `json:"http_method"` - - // The HTTP path of the request sent by the monitor to test the health of a - // member. Must be a string beginning with a forward slash (/). - URLPath string `json:"url_path"` - - // Domain Name. - DomainName string `json:"domain_name"` - - // Expected HTTP codes for a passing HTTP(S) monitor. - ExpectedCodes string `json:"expected_codes"` - - // The administrative state of the health monitor, which is up (true) or - // down (false). - AdminStateUp bool `json:"admin_state_up"` - - // The Port of the Monitor. - MonitorPort int `json:"monitor_port"` - - // List of pools that are associated with the health monitor. - Pools []structs.ResourceRef `json:"pools"` -} - -// MonitorPage is the page returned by a pager when traversing over a -// collection of health monitors. -type MonitorPage struct { - pagination.PageWithInfo -} - -// IsEmpty checks whether a MonitorPage struct is empty. -func (r MonitorPage) IsEmpty() (bool, error) { - is, err := ExtractMonitors(r) - return len(is) == 0, err -} - -// ExtractMonitors accepts a Page struct, specifically a MonitorPage struct, -// and extracts the elements into a slice of Monitor structs. In other words, -// a generic collection is mapped into a relevant slice. -func ExtractMonitors(r pagination.Page) ([]Monitor, error) { - var s []Monitor - err := (r.(MonitorPage)).ExtractIntoSlicePtr(&s, "healthmonitors") - if err != nil { - return nil, err - } - return s, nil -} - type commonResult struct { golangsdk.Result } From 74f9f8ee7754da0e18dfecf11c21e277b1e69f51 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:25:55 +0200 Subject: [PATCH 37/54] Update --- acceptance/openstack/elb/v3/monitors_test.go | 10 +- openstack/elb/v3/monitors/Update.go | 173 ++++++++++++------- openstack/elb/v3/monitors/results.go | 41 ----- 3 files changed, 118 insertions(+), 106 deletions(-) delete mode 100644 openstack/elb/v3/monitors/results.go diff --git a/acceptance/openstack/elb/v3/monitors_test.go b/acceptance/openstack/elb/v3/monitors_test.go index efa4d3e88..bcf56d2d9 100644 --- a/acceptance/openstack/elb/v3/monitors_test.go +++ b/acceptance/openstack/elb/v3/monitors_test.go @@ -67,13 +67,13 @@ func TestMonitorLifecycle(t *testing.T) { t.Logf("Attempting to Update ELBv3 Monitor") monitorName = tools.RandomString("update-monitor-", 3) updateOpts := monitors.UpdateOpts{ - Delay: 3, - Timeout: 35, - MaxRetries: 5, - MaxRetriesDown: 3, + Delay: pointerto.Int(3), + Timeout: pointerto.Int(35), + MaxRetries: pointerto.Int(5), + MaxRetriesDown: pointerto.Int(3), Name: monitorName, } - _, err = monitors.Update(client, monitor.Id, updateOpts).Extract() + _, err = monitors.Update(client, monitor.Id, updateOpts) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 Monitor: %s", monitor.Id) diff --git a/openstack/elb/v3/monitors/Update.go b/openstack/elb/v3/monitors/Update.go index 2d40e5bae..41bd583d1 100644 --- a/openstack/elb/v3/monitors/Update.go +++ b/openstack/elb/v3/monitors/Update.go @@ -1,76 +1,129 @@ package monitors -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToMonitorUpdateMap() (map[string]interface{}, error) -} - -// UpdateOpts is the common options' struct used in this package's Update -// operation. +// UpdateOpts is the common options' struct used in this package's Update operation. type UpdateOpts struct { - // The time, in seconds, between sending probes to members. - Delay int `json:"delay,omitempty"` - - // Maximum number of seconds for a Monitor to wait for a ping reply - // before it times out. The value must be less than the delay value. - Timeout int `json:"timeout,omitempty"` - - // Number of permissible ping failures before changing the member's - // status to INACTIVE. Must be a number between 1 and 10. - MaxRetries int `json:"max_retries,omitempty"` - - MaxRetriesDown int `json:"max_retries_down,omitempty"` - - // URI path that will be accessed if Monitor type is HTTP or HTTPS. - // Required for HTTP(S) types. - URLPath string `json:"url_path,omitempty"` - - // Domain Name. + // Specifies the administrative status of the health check. + // + // true (default): Health check is enabled. + // + // false: Health check is disabled. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies the interval between health checks, in seconds. The value ranges from 1 to 50. + // + // Minimum: 1 + // + // Maximum: 50 + Delay *int `json:"delay,omitempty"` + // Specifies the domain name that HTTP requests are sent to during the health check. + // + // The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter. + // + // The value cannot be left blank, but can be specified as null or cannot be passed, indicating that the virtual IP address of the load balancer is used as the destination address of HTTP requests. + // + // This parameter is available only when type is set to HTTP. + // + // Minimum: 1 + // + // Maximum: 100 DomainName string `json:"domain_name,omitempty"` - - // The HTTP method used for requests by the Monitor. If this attribute - // is not specified, it defaults to "GET". Required for HTTP(S) types. - HTTPMethod string `json:"http_method,omitempty"` - - // Expected HTTP codes for a passing HTTP(S) Monitor. You can either specify - // a single status like "200", or a range like "200-202". Required for HTTP(S) - // types. + // Specifies the expected HTTP status code. This parameter will take effect only when type is set to HTTP or HTTPS. + // + // The value options are as follows: + // + // A specific value, for example, 200 + // + // A list of values that are separated with commas (,), for example, 200, 202 + // + // A value range, for example, 200-204 + // + // The default value is 200. Multiple status codes can be queried in the format of expected_codes=xxx&expected_codes=xxx. + // + // Minimum: 1 + // + // Maximum: 64 ExpectedCodes string `json:"expected_codes,omitempty"` - - // The Name of the Monitor. + // Specifies the HTTP method. + // + // The value can be GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, or PATCH. + // + // This parameter will take effect only when type is set to HTTP. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 16 + HttpMethod string `json:"http_method,omitempty"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. + // + // The value ranges from 1 to 10 + // + // Minimum: 1 + // + // Maximum: 10 + MaxRetries *int `json:"max_retries,omitempty"` + // Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE. The value ranges from 1 to 10. + // + // Minimum: 1 + // + // Maximum: 10 + MaxRetriesDown *int `json:"max_retries_down,omitempty"` + // Specifies the port used for the health check. This parameter cannot be left blank, but can be set to null, indicating that the port used by the backend server will be used. + // + // Minimum: 1 + // + // Maximum: 65535 + MonitorPort *int `json:"monitor_port,omitempty"` + // Specifies the health check name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // The administrative state of the Monitor. A valid value is true (UP) - // or false (DOWN). - AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // The Port of the Monitor. - MonitorPort int `json:"monitor_port,omitempty"` - - // The type of probe, which is PING, TCP, HTTP, or HTTPS, that is - // sent by the load balancer to verify the member state. + // Specifies the maximum time required for waiting for a response from the health check, in seconds. It is recommended that you set the value less than that of parameter delay. + // + // Minimum: 1 + // + // Maximum: 50 + Timeout *int `json:"timeout,omitempty"` + // Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /. Note: This parameter is available only when type is set to HTTP. + // + // Minimum: 1 + // + // Maximum: 80 + UrlPath string `json:"url_path,omitempty"` + // Specifies the health check protocol. The value can be TCP, UDP_CONNECT, HTTP, or HTTPS. + // + // Note: + // + // If the protocol of the backend server is QUIC, the value can only be UDP_CONNECT. + // + // If the protocol of the backend server is UDP, the value can only be UDP_CONNECT. + // + // If the protocol of the backend server is TCP, the value can only be TCP, HTTP, or HTTPS. + // + // If the protocol of the backend server is HTTP, the value can only be TCP, HTTP, or HTTPS. + // + // If the protocol of the backend server is HTTPS, the value can only be TCP, HTTP, or HTTPS. + // + // QUIC protocol is not supported in eu-nl region. Type string `json:"type,omitempty"` } -// Update is an operation which modifies the attributes of the specified -// Monitor. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToMonitorUpdateMap() +// Update is an operation which modifies the attributes of the specified Monitor. +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*Monitor, error) { + b, err := build.RequestBody(opts, "healthmonitor") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("healthmonitors", id), b, &r.Body, &golangsdk.RequestOpts{ + raw, err := client.Put(client.ServiceURL("healthmonitors", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 202}, }) - return -} - -// ToMonitorUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToMonitorUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "healthmonitor") + return extra(err, raw) } diff --git a/openstack/elb/v3/monitors/results.go b/openstack/elb/v3/monitors/results.go deleted file mode 100644 index 9e7e3ee2b..000000000 --- a/openstack/elb/v3/monitors/results.go +++ /dev/null @@ -1,41 +0,0 @@ -package monitors - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" -) - -type commonResult struct { - golangsdk.Result -} - -// Extract is a function that accepts a result and extracts a Monitor. -func (r commonResult) Extract() (*Monitor, error) { - var res Monitor - err := extract.IntoStructPtr(res, "healthmonitor") - return &res, err -} - -// CreateResult represents the result of a create operation. Call its Extract -// method to interpret it as a Monitor. -type CreateResult struct { - commonResult -} - -// GetResult represents the result of a get operation. Call its Extract -// method to interpret it as a Monitor. -type GetResult struct { - commonResult -} - -// UpdateResult represents the result of an update operation. Call its Extract -// method to interpret it as a Monitor. -type UpdateResult struct { - commonResult -} - -// DeleteResult represents the result of a delete operation. Call its -// ExtractErr method to determine if the result succeeded or failed. -type DeleteResult struct { - golangsdk.ErrResult -} From 6cd075eae67cee238e63d39c16c1636be8ee08f8 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:23:45 +0200 Subject: [PATCH 38/54] Create --- acceptance/openstack/elb/v3/policies_test.go | 6 +- acceptance/openstack/elb/v3/rules_test.go | 12 +- openstack/elb/v3/monitors/Get.go | 2 +- openstack/elb/v3/policies/Create.go | 385 ++++++++++++++++--- openstack/elb/v3/policies/Get.go | 146 ++++++- openstack/elb/v3/policies/requests.go | 94 ----- openstack/elb/v3/policies/results.go | 31 -- openstack/elb/v3/rules/requests.go | 21 - 8 files changed, 482 insertions(+), 215 deletions(-) delete mode 100644 openstack/elb/v3/policies/requests.go delete mode 100644 openstack/elb/v3/rules/requests.go diff --git a/acceptance/openstack/elb/v3/policies_test.go b/acceptance/openstack/elb/v3/policies_test.go index 8b4a51846..e42493e14 100644 --- a/acceptance/openstack/elb/v3/policies_test.go +++ b/acceptance/openstack/elb/v3/policies_test.go @@ -27,7 +27,7 @@ func TestPolicyWorkflow(t *testing.T) { t.Cleanup(func() { deletePool(t, client, poolID) }) createOpts := policies.CreateOpts{ - Action: policies.ActionRedirectToPool, + Action: "REDIRECT_TO_POOL", ListenerID: listenerID, RedirectPoolID: poolID, Description: "Go SDK test policy", @@ -94,7 +94,7 @@ func TestPolicyWorkflowFixedResponse(t *testing.T) { t.Cleanup(func() { deletePool(t, client, poolID) }) createOpts := policies.CreateOpts{ - Action: policies.ActionFixedResponse, + Action: "FIXED_RESPONSE", ListenerID: listener.ID, FixedResponseConfig: &policies.FixedResponseOptions{ StatusCode: "200", @@ -170,7 +170,7 @@ func TestPolicyWorkflowUlrRedirect(t *testing.T) { t.Cleanup(func() { deletePool(t, client, poolID) }) createOpts := policies.CreateOpts{ - Action: policies.ActionUrlRedirect, + Action: "REDIRECT_TO_URL", ListenerID: listener.ID, RedirectUrl: "https://www.bing.com:443", RedirectUrlConfig: &policies.RedirectUrlOptions{ diff --git a/acceptance/openstack/elb/v3/rules_test.go b/acceptance/openstack/elb/v3/rules_test.go index b898834e4..d381a233f 100644 --- a/acceptance/openstack/elb/v3/rules_test.go +++ b/acceptance/openstack/elb/v3/rules_test.go @@ -32,8 +32,8 @@ func TestRuleWorkflow(t *testing.T) { t.Cleanup(func() { deletePolicy(t, client, policyID) }) opts := rules.CreateOpts{ - Type: rules.Path, - CompareType: rules.Regex, + Type: "PATH", + CompareType: "REGEX", Value: "^.+$", } created, err := rules.Create(client, policyID, opts).Extract() @@ -101,8 +101,8 @@ func TestRuleWorkflowConditions(t *testing.T) { Value: "/", } opts := rules.CreateOpts{ - Type: rules.Path, - CompareType: rules.StartsWith, + Type: "PATH", + CompareType: "STARTS_WITH", Value: "/bbb.html", Conditions: []rules.Condition{condition}, } @@ -134,7 +134,7 @@ func TestRuleWorkflowConditions(t *testing.T) { Value: "/home", } updateOpts := rules.UpdateOpts{ - CompareType: rules.EqualTo, + CompareType: "EQUAL_TO", Conditions: []rules.Condition{conditionUpdate}, } updated, err := rules.Update(client, policyID, id, updateOpts).Extract() @@ -147,7 +147,7 @@ func TestRuleWorkflowConditions(t *testing.T) { func createPolicy(t *testing.T, client *golangsdk.ServiceClient, listenerID, poolID string) string { createOpts := policies.CreateOpts{ - Action: policies.ActionRedirectToPool, + Action: "REDIRECT_TO_POOL", ListenerID: listenerID, RedirectPoolID: poolID, Description: "Go SDK test policy", diff --git a/openstack/elb/v3/monitors/Get.go b/openstack/elb/v3/monitors/Get.go index 8e457f09e..f34eb8f3c 100644 --- a/openstack/elb/v3/monitors/Get.go +++ b/openstack/elb/v3/monitors/Get.go @@ -20,7 +20,7 @@ func extra(err error, raw *http.Response) (*Monitor, error) { } var res Monitor - err = extract.IntoStructPtr(raw.Body, res, "healthmonitor") + err = extract.IntoStructPtr(raw.Body, &res, "healthmonitor") return &res, err } diff --git a/openstack/elb/v3/policies/Create.go b/openstack/elb/v3/policies/Create.go index 7c8f7ef83..267442f21 100644 --- a/openstack/elb/v3/policies/Create.go +++ b/openstack/elb/v3/policies/Create.go @@ -2,88 +2,363 @@ package policies import ( "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/rules" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" ) type CreateOpts struct { // Specifies where requests will be forwarded. The value can be one of the following: // - // REDIRECT_TO_POOL: Requests will be forwarded to another backend server group. - // REDIRECT_TO_LISTENER: Requests will be redirected to an HTTPS listener. - Action Action `json:"action" required:"true"` - - // Specifies the conditions contained in a forwarding rule. - // This parameter will take effect when enhance_l7policy_enable is set to true. - // If conditions is specified, key and value will not take effect, - // and the value of this parameter will contain all conditions configured for the forwarding rule. - // The keys in the list must be the same, whereas each value must be unique. - Conditions []rules.Condition `json:"conditions,omitempty"` - + // REDIRECT_TO_POOL: Requests will be forwarded to another backend server group. + // + // REDIRECT_TO_LISTENER: Requests will be redirected to an HTTPS listener. + // + // REDIRECT_TO_URL: Requests will be redirected to another URL. + // + // FIXED_RESPONSE: A fixed response body will be returned. + // + // REDIRECT_TO_LISTENER has the highest priority. If requests are to be redirected to an HTTPS listener, other forwarding policies of the listener will become invalid. + // + // Note: + // + // If action is set to REDIRECT_TO_POOL, the listener's protocol must be HTTP or HTTPS. + // + // If action is set to REDIRECT_TO_LISTENER, the listener's protocol must be HTTP. + // + // Minimum: 1 + // + // Maximum: 255 + Action string `json:"action" required:"true"` + // Specifies the administrative status of the forwarding policy. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up,omitempty"` // Provides supplementary information about the forwarding policy. + // + // Minimum: 0 + // + // Maximum: 255 Description string `json:"description,omitempty"` - - // Specifies the configuration of the page that will be returned. - // This parameter will take effect when - FixedResponseConfig *FixedResponseOptions `json:"fixed_response_config,omitempty"` - // Specifies the ID of the listener to which the forwarding policy is added. - ListenerID string `json:"listener_id" required:"true"` - + // + // If action is set to REDIRECT_TO_POOL, the forwarding policy can be added to an HTTP or HTTPS listener. + // + // If action is set to REDIRECT_TO_LISTENER, the forwarding policy can be added to an HTTP listener. + ListenerId string `json:"listener_id" required:"true"` // Specifies the forwarding policy name. + // + // Minimum: 0 + // + // Maximum: 255 Name string `json:"name,omitempty"` - - // Specifies the forwarding policy priority. The value cannot be updated. - Position int `json:"position,omitempty"` - // Specifies the forwarding policy priority. The value cannot be updated. - Priority int `json:"priority,omitempty"` - + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 100 + Position *int `json:"position,omitempty"` + // Specifies the forwarding policy priority. A smaller value indicates a higher priority. The value must be unique for forwarding policies of the same listener. This parameter will take effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned. This parameter is unsupported for shared load balancers. + // + // If action is set to REDIRECT_TO_LISTENER, the value can only be 0, indicating REDIRECT_TO_LISTENER has the highest priority. + // + // If enhance_l7policy_enable is not enabled, forwarding policies are automatically prioritized based on the original policy sorting logic. The priorities of domain names are independent from each other. For the same domain name, the priorities are sorted in the order of exact match (EQUAL_TO), prefix match (STARTS_WITH), and regular expression match (REGEX). If the matching types are the same, the longer the URL is, the higher the priority is. If a forwarding policy contains only a domain name without a path specified, the path is /, and prefix match is used by default. + // + // If enhance_l7policy_enable is set to true and this parameter is not passed, the priority will be a sum of 1 and the highest priority of existing forwarding policy in the same listener by default. If the highest priority of existing forwarding policies is the maximum (10,000), the forwarding policy will fail to be created because the final priority for creating the forwarding policy is the sum of 1 and 10,000, which exceeds the maximum. In this case, specify a value or adjust the priorities of existing forwarding policies. If no forwarding policies exist, the highest priority of existing forwarding policies will be set to 1 by default. + // + // This parameter is invalid for shared load balancers. + // + // This parameter is not available in eu-nl region. Please do not use it. + // + // Minimum: 0 + // + // Maximum: 10000 + Priority *int `json:"priority,omitempty"` // Specifies the ID of the project where the forwarding policy is used. - ProjectID string `json:"project_id,omitempty"` - - // Specifies the ID of the listener to which requests are redirected. - // This parameter is mandatory when action is set to REDIRECT_TO_LISTENER. - RedirectListenerID string `json:"redirect_listener_id,omitempty"` - - // Specifies the ID of the backend server group that requests are forwarded to. // - // This parameter is valid and mandatory only when action is set to REDIRECT_TO_POOL. - // The specified backend server group cannot be the default one associated with the listener, - // or any backend server group associated with the forwarding policies of other listeners. - RedirectPoolID string `json:"redirect_pool_id,omitempty"` - + // Minimum: 1 + // + // Maximum: 32 + ProjectId string `json:"project_id,omitempty"` + // Specifies the ID of the listener to which requests are redirected. This parameter is mandatory when action is set to REDIRECT_TO_LISTENER. + // + // Note: + // + // The listener's protocol must be HTTPS. + // + // A listener added to another load balancer is not allowed. + // + // This parameter cannot be passed in the API for adding or updating a forwarding policy if action is set to REDIRECT_TO_POOL. + // + // This parameter is unsupported for shared load balancers. + RedirectListenerId string `json:"redirect_listener_id,omitempty"` + // Specifies the ID of the backend server group to which the requests are forwarded. This parameter is valid only when action is set to REDIRECT_TO_POOL. Note: + // + // If action is set to REDIRECT_TO_POOL, specify either redirect_pool_id or redirect_pools_config. If both are specified, only redirect_pools_config takes effect. + // + // This parameter cannot be specified when action is set to REDIRECT_TO_LISTENER. + RedirectPoolId string `json:"redirect_pool_id,omitempty"` + // Specifies the configuration of the backend server group that the requests are forwarded to. This parameter is valid only when action is set to REDIRECT_TO_POOL. + // + // Note: + // + // If action is set to REDIRECT_TO_POOL, specify either redirect_pool_id or redirect_pools_config. If both are specified, only redirect_pools_config takes effect. + // + // This parameter cannot be specified when action is set to REDIRECT_TO_LISTENER. + RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` // Specifies the URL to which requests are forwarded. // // Format: protocol://host:port/path?query + // + // Minimum: 1 + // + // Maximum: 255 RedirectUrl string `json:"redirect_url,omitempty"` - // Specifies the URL to which requests are forwarded. - // This parameter is mandatory when action is set to REDIRECT_TO_URL. - // It cannot be specified if the value of action is not REDIRECT_TO_URL. - RedirectUrlConfig *RedirectUrlOptions `json:"redirect_url_config,omitempty"` - + // + // For dedicated load balancers, this parameter will take effect only when advanced forwarding is enabled (enhance_l7policy_enable is set to true). If it is passed when enhance_l7policy_enable is set to false, an error will be returned. + // + // This parameter is mandatory when action is set to REDIRECT_TO_URL. It cannot be specified if the value of action is not REDIRECT_TO_URL. + // + // Format: protocol://host:port/path?query + // + // At least one of the four parameters (protocol, host, port, and path) must be passed, or their values cannot be set to ${xxx} at the same time. (${xxx} indicates that the value in the request will be inherited. For example, ${host} indicates the host in the URL to be redirected.) + // + // The values of protocol and port cannot be the same as those of the associated listener, and either host or path must be passed or their values cannot be ${xxx} at the same time. + // + // For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned. + // + // This parameter is not available in eu-nl region. Please do not use it. + RedirectUrlConfig RedirectUrlOptions `json:"redirect_url_config,omitempty"` + // Specifies the configuration of the page that will be returned. This parameter will take effect when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned. + // + // This parameter is mandatory when action is set to FIXED_RESPONSE. It cannot be specified if the value of action is not FIXED_RESPONSE. + // + // For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned. + // + // This parameter is not available in eu-nl region. Please do not use it. + FixedResponseConfig FixedResponseOptions `json:"fixed_response_config,omitempty"` // Lists the forwarding rules in the forwarding policy. + // // The list can contain a maximum of 10 forwarding rules (if conditions is specified, a condition is considered as a rule). - Rules []Rule `json:"rules,omitempty"` + // + // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. Note: + // + // The entire list will be replaced if you update it. + // + // If the action of 17policy is set to Redirect to another listener, 17rule cannot be created. + Rules []L7PolicyRuleOption `json:"rules,omitempty"` +} - // Specifies the configuration of the backend server group that the requests are forwarded to. This parameter is valid only when action is set to REDIRECT_TO_POOL. - RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` +type FixedResponseOptions struct { + // Specifies the fixed HTTP status code configured in the forwarding rule. The value can be any integer in the range of 200-299, 400-499, or 500-599. + // + // Minimum: 1 + // + // Maximum: 16 + StatusCode string `json:"status_code" required:"true"` + // Specifies the format of the response body. + // + // The value can be text/plain, text/css, text/html, application/javascript, or application/json. + // + // Default: text/plain + // + // Minimum: 0 + // + // Maximum: 32 + ContentType string `json:"content_type,omitempty"` + // Specifies the content of the response message body. + // + // Minimum: 0 + // + // Maximum: 1024 + MessageBody string `json:"message_body,omitempty"` +} + +type RedirectPoolOptions struct { + // Specifies the ID of the backend server group. + PoolId string `json:"pool_id" required:"true"` + // Specifies the weight of the backend server group. The value ranges from 0 to 100. + Weight *int `json:"weight" required:"true"` +} + +type RedirectUrlOptions struct { + // Specifies the protocol for redirection. + // + // The value can be HTTP, HTTPS, or ${protocol}. The default value is ${protocol}, indicating that the protocol of the request will be used. + // + // Default: ${protocol} + // + // Minimum: 1 + // + // Maximum: 36 + Protocol string `json:"protocol,omitempty"` + // Specifies the host name that requests are redirected to. The value can contain only letters, digits, hyphens (-), and periods (.) and must start with a letter or digit. The default value is ${host}, indicating that the host of the request will be used. + // + // Default: ${host} + // + // Minimum: 1 + // + // Maximum: 128 + Host string `json:"host,omitempty"` + // Specifies the port that requests are redirected to. The default value is ${port}, indicating that the port of the request will be used. + // + // Default: ${port} + // + // Minimum: 1 + // + // Maximum: 16 + Port string `json:"port,omitempty"` + // Specifies the path that requests are redirected to. The default value is ${path}, indicating that the path of the request will be used. + // + // The value can contain only letters, digits, and special characters _~';@^- %#&$.*+?,=!:|/()[]{} and must start with a slash (/). + // + // Default: ${path} + // + // Minimum: 1 + // + // Maximum: 128 + Path string `json:"path,omitempty"` + // Specifies the query string set in the URL for redirection. The default value is ${query}, indicating that the query string of the request will be used. + // + // For example, in the URL https://www.xxx.com:8080/elb?type=loadbalancer, ${query} indicates type=loadbalancer. If this parameter is set to ${query}&name=my_name, the URL will be redirected to https://www.xxx.com:8080/elb?type=loadbalancer&name=my_name. + // + // The value is case-sensitive and can contain only letters, digits, and special characters !$&'()*+,-./:;=?@^_` + // + // Default: ${query} + // + // Minimum: 0 + // + // Maximum: 128 + Query string `json:"query,omitempty"` + // Specifies the status code returned after the requests are redirected. + // + // The value can be 301, 302, 303, 307, or 308. + // + // Minimum: 1 + // + // Maximum: 16 + StatusCode string `json:"status_code" required:"true"` } -type CreateOptsBuilder interface { - ToPolicyCreateMap() (map[string]interface{}, error) +type L7PolicyRuleOption struct { + // Specifies the administrative status of the forwarding rule. The value can be true or false, and the default value is true. + // + // This parameter is unsupported. Please do not use it. + // + // Default: true + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies the type of the forwarding rule. The value can be one of the following: + // + // HOST_NAME: A domain name will be used for matching. + // + // PATH: A URL will be used for matching. + // + // METHOD: An HTTP request method will be used for matching. + // + // HEADER: The request header will be used for matching. + // + // QUERY_STRING: A query string will be used for matching. + // + // SOURCE_IP: The source IP address will be used for matching. + // + // If type is set to HOST_NAME, PATH, METHOD, and SOURCE_IP, only one forwarding rule can be created for each type. If type is set to HEADER and QUERY_STRING, multiple forwarding rules can be created for each type. + Type string `json:"type" required:"true"` + // Specifies how requests are matched with the forwarding rule. Values: + // + // EQUAL_TO: exact match. + // + // REGEX: regular expression match + // + // STARTS_WITH: prefix match + // + // Note: + // + // If type is set to HOST_NAME, the value can only be EQUAL_TO, and asterisks (*) can be used as wildcard characters. + // + // If type is set to PATH, the value can be REGEX, STARTS_WITH, or EQUAL_TO. + // + // If type is set to METHOD or SOURCE_IP, the value can only be EQUAL_TO. + // + // If type is set to HEADER or QUERY_STRING, the value can only be EQUAL_TO, asterisks (*) and question marks (?) can be used as wildcard characters. + CompareType string `json:"compare_type" required:"true"` + // Specifies whether reverse matching is supported. The value can be true or false, and the default value is false. + // + // This parameter is unsupported. Please do not use it. + // + // Default: false + Invert *bool `json:"invert,omitempty"` + // Specifies the key of the match item. For example, if an HTTP header is used for matching, key is the name of the HTTP header parameter. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 255 + Key string `json:"key,omitempty"` + // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. This parameter will take effect only when conditions is left blank. + // + // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name. + // + // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + // + // If type is set to METHOD, SOURCE_IP, HEADER, or QUERY_STRING, this parameter will not take effect, and conditions will be used to specify the key and value. + // + // Minimum: 1 + // + // Maximum: 128 + Value string `json:"value" required:"true"` + // Specifies the conditions contained in a forwarding rule. This parameter will take effect when enhance_l7policy_enable is set to true. + // + // If conditions is specified, key and value will not take effect, and the value of this parameter will contain all conditions configured for the forwarding rule. The keys in the list must be the same, whereas each value must be unique. + // + // This parameter is not available in eu-nl region. Please do not use it. + Conditions []RuleCondition `json:"conditions,omitempty"` } -func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "l7policy") +type RuleCondition struct { + // Specifies the key of match item. + // + // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, this parameter is left blank. + // + // If type is set to HEADER, key indicates the name of the HTTP header parameter. The value can contain 1 to 40 characters, including letters, digits, hyphens (-), and underscores (_). + // + // If type is set to QUERY_STRING, key indicates the name of the query parameter. The value is case sensitive and can contain 1 to 128 characters. Spaces, square brackets ([ ]), curly brackets ({ }), angle brackets (< >), backslashes (), double quotation marks (" "), pound signs (#), ampersands (&), vertical bars (|), percent signs (%), and tildes (~) are not supported. + // + // All keys in the conditions list in the same rule must be the same. + // + // Minimum: 1 + // + // Maximum: 128 + Key string `json:"key,omitempty"` + // Specifies the value of the match item. + // + // If type is set to HOST_NAME, key is left blank, and value indicates the domain name, which can contain 1 to 128 characters, including letters, digits, hyphens (-), periods (.), and asterisks (*), and must start with a letter, digit, or asterisk (*). If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name. + // + // If type is set to PATH, key is left blank, and value indicates the request path, which can contain 1 to 128 characters. If compare_type is set to STARTS_WITH or EQUAL_TO for the forwarding rule, the value must start with a slash (/) and can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + // + // If type is set to HEADER, key indicates the name of the HTTP header parameter, and value indicates the value of the HTTP header parameter. The value can contain 1 to 128 characters. Asterisks (*) and question marks (?) are allowed, but spaces and double quotation marks are not allowed. An asterisk can match zero or more characters, and a question mark can match 1 character. + // + // If type is set to QUERY_STRING, key indicates the name of the query parameter, and value indicates the value of the query parameter. The value is case sensitive and can contain 1 to 128 characters. Spaces, square brackets ([ ]), curly brackets ({ }), angle brackets (< >), backslashes (), double quotation marks (" "), pound signs (#), ampersands (&), vertical bars (|), percent signs (%), and tildes (~) are not supported. Asterisks (*) and question marks (?) are allowed. An asterisk can match zero or more characters, and a question mark can match 1 character. + // + // If type is set to METHOD, key is left blank, and value indicates the HTTP method. The value can be GET, PUT, POST, DELETE, PATCH, HEAD, or OPTIONS. + // + // If type is set to SOURCE_IP, key is left blank, and value indicates the source IP address of the request. The value is an IPv4 or IPv6 CIDR block, for example, 192.168.0.2/32 or 2049::49/64. + // + // All keys in the conditions list in the same rule must be the same. + // + // Minimum: 1 + // + // Maximum: 128 + Value string `json:"value" required:"true"` } -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToPolicyCreateMap() +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*L7Policy, error) { + b, err := build.RequestBody(opts, "l7policy") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("l7policies"), b, &r.Body, nil) - return + + raw, err := client.Post(client.ServiceURL("l7policies"), b, nil, nil) + return extra(err, raw) } diff --git a/openstack/elb/v3/policies/Get.go b/openstack/elb/v3/policies/Get.go index 9af14abba..5321ddc65 100644 --- a/openstack/elb/v3/policies/Get.go +++ b/openstack/elb/v3/policies/Get.go @@ -1,8 +1,146 @@ package policies -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "net/http" -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("l7policies", id), &r.Body, nil) - return + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func Get(client *golangsdk.ServiceClient, id string) (*L7Policy, error) { + raw, err := client.Get(client.ServiceURL("l7policies", id), nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*L7Policy, error) { + if err != nil { + return nil, err + } + + var res L7Policy + err = extract.IntoStructPtr(raw.Body, &res, "l7policy") + return &res, err +} + +type L7Policy struct { + // Specifies where requests will be forwarded. The value can be one of the following: + // + // REDIRECT_TO_POOL: Requests will be forwarded to another backend server group. + // + // REDIRECT_TO_LISTENER: Requests will be redirected to an HTTPS listener. + // + // REDIRECT_TO_URL: Requests will be redirected to another URL. + // + // FIXED_RESPONSE: A fixed response body will be returned. + // + // REDIRECT_TO_LISTENER has the highest priority. If requests are to be redirected to an HTTPS listener, other forwarding policies of the listener will become invalid. + // + // Note: + // + // If action is set to REDIRECT_TO_POOL, the listener's protocol must be HTTP, HTTPS, or TERMINATED_HTTPS. + // + // If action is set to REDIRECT_TO_LISTENER, the listener's protocol must be HTTP. + Action string `json:"action"` + // Specifies the administrative status of the forwarding policy. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up"` + // Provides supplementary information about the forwarding policy. + Description string `json:"description"` + // Specifies the forwarding policy ID. + Id string `json:"id"` + // Specifies the ID of the listener to which the forwarding policy is added. + ListenerId string `json:"listener_id"` + // Specifies the forwarding policy name. + // + // Minimum: 1 + // + // Maximum: 255 + Name string `json:"name"` + // Specifies the forwarding policy priority. This parameter cannot be updated. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 1 + // + // Maximum: 100 + Position *int `json:"position"` + // Specifies the forwarding policy priority. A smaller value indicates a higher priority. The value must be unique for forwarding policies of the same listener. This parameter will take effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned. This parameter is unsupported for shared load balancers. + // + // If action is set to REDIRECT_TO_LISTENER, the value can only be 0, indicating REDIRECT_TO_LISTENER has the highest priority. + // + // If enhance_l7policy_enable is not enabled, forwarding policies are automatically prioritized based on the original policy sorting logic. The priorities of domain names are independent from each other. For the same domain name, the priorities are sorted in the order of exact match (EQUAL_TO), prefix match (STARTS_WITH), and regular expression match (REGEX). If the matching types are the same, the longer the URL is, the higher the priority is. If a forwarding policy contains only a domain name without a path specified, the path is /, and prefix match is used by default. + // + // If enhance_l7policy_enable is set to true and this parameter is not passed, the priority will be a sum of 1 and the highest priority of existing forwarding policy in the same listener by default. If the highest priority of existing forwarding policies is the maximum (10,000), the forwarding policy will fail to be created because the final priority for creating the forwarding policy is the sum of 1 and 10,000, which exceeds the maximum. In this case, specify a value or adjust the priorities of existing forwarding policies. If no forwarding policies exist, the highest priority of existing forwarding policies will be set to 1 by default. + // + // This parameter is invalid for shared load balancers. + // + // This parameter is not available in eu-nl region. Please do not use it. + Priority *int `json:"priority"` + // Specifies the project ID of the forwarding policy. + ProjectId string `json:"project_id"` + // Specifies the provisioning status of the forwarding policy. + // + // The value can be ACTIVE or ERROR. + // + // ACTIVE (default): The forwarding policy is provisioned successfully. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies the ID of the backend server group that requests will be forwarded to. + // + // This parameter is valid and mandatory only when action is set to REDIRECT_TO_POOL. + // + // If both redirect_pools_config and redirect_pool_id are specified, redirect_pools_config will take effect. + RedirectPoolId string `json:"redirect_pool_id"` + // Specifies the configuration of the backend server group that the requests are forwarded to. This parameter is valid only when action is set to REDIRECT_TO_POOL. + RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config"` + // Specifies the ID of the listener to which requests are redirected. This parameter is mandatory when action is set to REDIRECT_TO_LISTENER. + // + // Note: + // + // The listener's protocol must be HTTPS or TERMINATED_HTTPS. + // + // A listener added to another load balancer is not allowed. + // + // This parameter cannot be passed in the API for adding or updating a forwarding policy if action is set to REDIRECT_TO_POOL. + RedirectListenerId string `json:"redirect_listener_id"` + // Specifies the URL to which requests are forwarded. + // + // Format: protocol://host:port/path?query + // + // This parameter is unsupported. Please do not use it. + RedirectUrl string `json:"redirect_url"` + // Lists the forwarding rules in the forwarding policy. + Rules []RuleCondition `json:"rules"` + // Specifies the URL to which requests are forwarded. + // + // For dedicated load balancers, this parameter will take effect only when advanced forwarding is enabled (enhance_l7policy_enable is set to true). If it is passed when enhance_l7policy_enable is set to false, an error will be returned. + // + // This parameter is mandatory when action is set to REDIRECT_TO_URL. It cannot be specified if the value of action is not REDIRECT_TO_URL. + // + // Format: protocol://host:port/path?query + // + // At least one of the four parameters (protocol, host, port, and path) must be passed, or their values cannot be set to ${xxx} at the same time. (${xxx} indicates that the value in the request will be inherited. For example, ${host} indicates the host in the URL to be redirected.) + // + // The values of protocol and port cannot be the same as those of the associated listener, and either host or path must be passed or their values cannot be ${xxx} at the same time. + // + // For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned. + // + // This parameter is not available in eu-nl region. Please do not use it. + RedirectUrlConfig RedirectUrlOptions `json:"redirect_url_config"` + // Specifies the configuration of the page that will be returned. This parameter will take effect when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned. + // + // This parameter is mandatory when action is set to FIXED_RESPONSE. It cannot be specified if the value of action is not FIXED_RESPONSE. + // + // For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned. + // + // This parameter is not available in eu-nl region. Please do not use it. + FixedResponseConfig FixedResponseOptions `json:"fixed_response_config"` + // Specifies the time when the forwarding policy was added. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + CreatedAt string `json:"created_at"` + // Specifies the time when the forwarding policy was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + UpdatedAt string `json:"updated_at"` } diff --git a/openstack/elb/v3/policies/requests.go b/openstack/elb/v3/policies/requests.go deleted file mode 100644 index a4c408d02..000000000 --- a/openstack/elb/v3/policies/requests.go +++ /dev/null @@ -1,94 +0,0 @@ -package policies - -import ( - "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/rules" -) - -type Action string - -const ( - ActionRedirectToPool Action = "REDIRECT_TO_POOL" - ActionRedirectToListener Action = "REDIRECT_TO_LISTENER" - ActionFixedResponse Action = "FIXED_RESPONSE" - ActionUrlRedirect Action = "REDIRECT_TO_URL" -) - -type Rule struct { - // Specifies the match content. The value can be one of the following: - // - // HOST_NAME: A domain name will be used for matching. - // PATH: A URL will be used for matching. - // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. - Type rules.RuleType `json:"type" required:"true"` - - // Specifies how requests are matched with the domain name or URL. - // - // If type is set to HOST_NAME, this parameter can only be set to EQUAL_TO (exact match). - // - // If type is set to PATH, this parameter can be set to REGEX (regular expression match), STARTS_WITH (prefix match), or EQUAL_TO (exact match). - CompareType rules.CompareType `json:"compare_type" required:"true"` - - // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. - // - // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must start with a letter or digit. - // If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name. - // - // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) - // and can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} - Value string `json:"value" required:"true"` -} - -type RedirectPoolOptions struct { - // Specifies the ID of the backend server group. - PoolId string `json:"pool_id" required:"true"` - - // Specifies the weight of the backend server group. The value ranges from 0 to 100. - Weight string `json:"weight" required:"true"` -} - -type FixedResponseOptions struct { - // Specifies the fixed HTTP status code configured in the forwarding rule. - // The value can be any integer in the range of 200-299, 400-499, or 500-599. - StatusCode string `json:"status_code" required:"true"` - - // Specifies the format of the response body. - // - // The value can be text/plain, text/css, text/html, application/javascript, or application/json. - ContentType string `json:"content_type"` - - // Specifies the content of the response message body. - MessageBody string `json:"message_body"` -} - -type RedirectUrlOptions struct { - // Specifies the protocol for redirection. - // The value can be HTTP, HTTPS, or ${protocol}. The default value is ${protocol}, indicating that the protocol of the request will be used. - Protocol string `json:"protocol"` - - // Specifies the host name that requests are redirected to. - // The value can contain only letters, digits, hyphens (-), and periods (.) and must start with a letter or digit. - // The default value is ${host}, indicating that the host of the request will be used. - Host string `json:"host"` - - // Specifies the port that requests are redirected to. - // The default value is ${port}, indicating that the port of the request will be used. - Port string `json:"port"` - - // Specifies the path that requests are redirected to. The default value is ${path}, indicating that the path of the request will be used. - // - // The value can contain only letters, digits, and special characters _~';@^- %#&$.*+?,=!:|/()[]{} and must start with a slash (/). - Path string `json:"path"` - - // Specifies the query string set in the URL for redirection. The default value is ${query}, indicating that the query string of the request will be used. - // - // For example, in the URL https://www.xxx.com:8080/elb?type=loadbalancer, ${query} indicates type=loadbalancer. - // If this parameter is set to ${query}&name=my_name, the URL will be redirected to https://www.xxx.com:8080/elb?type=loadbalancer&name=my_name. - // - // The value is case-sensitive and can contain only letters, digits, and special characters !$&'()*+,-./:;=?@^_` - Query string `json:"query"` - - // Specifies the status code returned after the requests are redirected. - // - // The value can be 301, 302, 303, 307, or 308. - StatusCode string `json:"status_code" required:"true"` -} diff --git a/openstack/elb/v3/policies/results.go b/openstack/elb/v3/policies/results.go index 14e24879e..576a271a2 100644 --- a/openstack/elb/v3/policies/results.go +++ b/openstack/elb/v3/policies/results.go @@ -2,44 +2,13 @@ package policies import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/rules" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -type Policy struct { - ID string `json:"id"` - Action Action `json:"action"` - Description string `json:"description"` - ListenerID string `json:"listener_id"` - Name string `json:"name"` - Position int `json:"position"` - Priority int `json:"priority"` - ProjectID string `json:"project_id"` - Status string `json:"provisioning_status"` - RedirectListenerID string `json:"redirect_listener_id"` - RedirectPoolID string `json:"redirect_pool_id"` - Rules []structs.ResourceRef `json:"rules"` - Conditions []rules.Condition `json:"conditions"` - FixedResponseConfig FixedResponseOptions `json:"fixed_response_config"` - RedirectUrl string `json:"redirect_url"` - RedirectUrlConfig RedirectUrlOptions `json:"redirect_url_config"` - RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config"` -} - type commonResult struct { golangsdk.Result } -func (r commonResult) Extract() (*Policy, error) { - p := &Policy{} - err := r.ExtractIntoStructPtr(p, "l7policy") - if err != nil { - return nil, err - } - return p, nil -} - type CreateResult struct { commonResult } diff --git a/openstack/elb/v3/rules/requests.go b/openstack/elb/v3/rules/requests.go deleted file mode 100644 index 7319e4c79..000000000 --- a/openstack/elb/v3/rules/requests.go +++ /dev/null @@ -1,21 +0,0 @@ -package rules - -type RuleType string -type CompareType string - -const ( - HostName RuleType = "HOST_NAME" - Path RuleType = "PATH" - - EqualTo CompareType = "EQUAL_TO" - Regex CompareType = "REGEX" - StartsWith CompareType = "STARTS_WITH" -) - -type Condition struct { - // Specifies the key of match item. - Key string `json:"key"` - - // Specifies the value of the match item. - Value string `json:"value" required:"true"` -} From 676e0739dab40e0ba0101f51ea6256b05574dc05 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:27:48 +0200 Subject: [PATCH 39/54] List --- openstack/elb/v3/monitors/List.go | 9 -- openstack/elb/v3/policies/List.go | 159 ++++++++++++++++++++++----- openstack/elb/v3/policies/results.go | 22 ---- 3 files changed, 130 insertions(+), 60 deletions(-) diff --git a/openstack/elb/v3/monitors/List.go b/openstack/elb/v3/monitors/List.go index d66ea010b..184d2a0fc 100644 --- a/openstack/elb/v3/monitors/List.go +++ b/openstack/elb/v3/monitors/List.go @@ -124,15 +124,6 @@ type ListOpts struct { EnterpriseProjectId []string `q:"enterprise_project_id"` } -// ToMonitorListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToMonitorListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), nil -} - // List returns a Pager which allows you to iterate over a collection of // health monitors. It accepts a ListOpts struct, which allows you to filter and sort // the returned collection for greater efficiency. diff --git a/openstack/elb/v3/policies/List.go b/openstack/elb/v3/policies/List.go index 4839b7690..31061c521 100644 --- a/openstack/elb/v3/policies/List.go +++ b/openstack/elb/v3/policies/List.go @@ -2,47 +2,148 @@ package policies import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -type ListOptsBuilder interface { - ToPolicyListQuery() (string, error) -} - type ListOpts struct { - Marker string `q:"marker"` - Limit int `q:"limit"` - PageReverse bool `q:"page_reverse"` - ID []string `q:"id"` - Name []string `q:"name"` - Description []string `q:"description"` - ListenerID []string `q:"listener_id"` - Action []string `q:"action"` - RedirectPoolID []string `q:"redirect_pool_id"` - RedirectListenerID []string `q:"redirect_listener_id"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit *int `q:"limit"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` + // Specifies the enterprise project ID. + // + // If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project. + // + // If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried). + // + // Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx. + // + // This parameter is unsupported. Please do not use it. + EnterpriseProjectId []string `q:"enterprise_project_id"` + // Specifies the forwarding policy ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + Id []string `q:"id"` + // Specifies the forwarding policy name. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Provides supplementary information about the forwarding policy. + // + // Multiple descriptions can be queried in the format of description=xxx&description=xxx. + Description []string `q:"description"` + // Specifies the administrative status of the forwarding policy. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the ID of the listener to which the forwarding policy is added. + // + // Multiple IDs can be queried in the format of listener_id=xxx&listener_id=xxx. + ListenerId []string `q:"listener_id"` + // Specifies the forwarding policy priority. + // + // Multiple priorities can be queried in the format of position=xxx&position=xxx. + // + // This parameter is unsupported. Please do not use it. + Position []string `q:"position"` + // Specifies where requests are forwarded. The value can be one of the following: + // + // REDIRECT_TO_POOL: Requests are forwarded to another backend server group. + // + // REDIRECT_TO_LISTENER: Requests are redirected to an HTTPS listener. + // + // REDIRECT_TO_URL: Requests are redirected to another URL. + // + // FIXED_RESPONSE: A fixed response body is returned. + // + // Multiple values can be queried in the format of action=xxx&action=xxx. + Action []string `q:"action"` + // Specifies the URL to which requests will be forwarded. The URL must be in the format of protocol://host:port/path?query. + // + // Multiple URLs can be queried in the format of redirect_url=xxx&redirect_url=xxx. + // + // This parameter is unsupported. Please do not use it. + RedirectUrl []string `q:"redirect_url"` + // Specifies the ID of the backend server group to which requests will be forwarded. + // + // Multiple IDs can be queried in the format of redirect_pool_id=xxx&redirect_pool_id=xxx. + RedirectPoolId []string `q:"redirect_pool_id"` + // Specifies the ID of the listener to which requests are redirected. + // + // Multiple IDs can be queried in the format of redirect_listener_id=xxx&redirect_listener_id=xxx. + RedirectListenerId []string `q:"redirect_listener_id"` + // Specifies the provisioning status of the forwarding policy. + // + // ACTIVE: The forwarding policy is provisioned successfully. + // + // ERROR: The forwarding policy has the same rule as another forwarding policy added to the same listener. + // + // Multiple provisioning statuses can be queried in the format of provisioning_status=xxx&provisioning_status=xxx. ProvisioningStatus []string `q:"provisioning_status"` - DisplayAllRules bool `q:"display_all_rules"` + // Specifies whether to display details about the forwarding rule in the forwarding policy. + // + // true: Details about the forwarding rule are displayed. + // + // false: Only the rule ID is displayed. + DisplayAllRules *bool `q:"display_all_rules"` + // Specifies the forwarding policy priority. A smaller value indicates a higher priority. + // + // Multiple priorities can be queried in the format of position=xxx&position=xxx. + Priority []string `q:"priority"` } -func (opts ListOpts) ToPolicyListQuery() (string, error) { +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { q, err := golangsdk.BuildQueryString(opts) if err != nil { - return "", err + return pagination.Pager{Err: err} } - return q.String(), nil + + return pagination.NewPager(client, client.ServiceURL("l7policies")+q.String(), func(r pagination.PageResult) pagination.Page { + return PolicyPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) } -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("l7policies") - if opts != nil { - q, err := opts.ToPolicyListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += q +type PolicyPage struct { + pagination.PageWithInfo +} + +func (p PolicyPage) IsEmpty() (bool, error) { + l, err := ExtractPolicies(p) + if err != nil { + return false, err } + return len(l) == 0, nil +} - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { - return PolicyPage{PageWithInfo: pagination.NewPageWithInfo(r)} - }) +func ExtractPolicies(p pagination.Page) ([]L7Policy, error) { + var res []L7Policy + err := extract.IntoSlicePtr(p.(PolicyPage).BodyReader(), &res, "l7policies") + return res, err } diff --git a/openstack/elb/v3/policies/results.go b/openstack/elb/v3/policies/results.go index 576a271a2..170464cd6 100644 --- a/openstack/elb/v3/policies/results.go +++ b/openstack/elb/v3/policies/results.go @@ -2,7 +2,6 @@ package policies import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type commonResult struct { @@ -24,24 +23,3 @@ type UpdateResult struct { type DeleteResult struct { golangsdk.ErrResult } - -type PolicyPage struct { - pagination.PageWithInfo -} - -func (p PolicyPage) IsEmpty() (bool, error) { - l, err := ExtractPolicies(p) - if err != nil { - return false, err - } - return len(l) == 0, nil -} - -func ExtractPolicies(p pagination.Page) ([]Policy, error) { - var policies []Policy - err := p.(PolicyPage).ExtractIntoSlicePtr(&policies, "l7policies") - if err != nil { - return nil, err - } - return policies, nil -} From ec306383b30740a96c8a488389ef9194c2e08463 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:36:47 +0200 Subject: [PATCH 40/54] Update --- acceptance/openstack/elb/v3/policies_test.go | 85 +++++++------ acceptance/openstack/elb/v3/rules_test.go | 12 +- openstack/elb/v3/policies/Update.go | 122 +++++++++++++++---- openstack/elb/v3/policies/results.go | 25 ---- 4 files changed, 146 insertions(+), 98 deletions(-) delete mode 100644 openstack/elb/v3/policies/results.go diff --git a/acceptance/openstack/elb/v3/policies_test.go b/acceptance/openstack/elb/v3/policies_test.go index e42493e14..e249d8cb0 100644 --- a/acceptance/openstack/elb/v3/policies_test.go +++ b/acceptance/openstack/elb/v3/policies_test.go @@ -28,47 +28,46 @@ func TestPolicyWorkflow(t *testing.T) { createOpts := policies.CreateOpts{ Action: "REDIRECT_TO_POOL", - ListenerID: listenerID, - RedirectPoolID: poolID, + ListenerId: listenerID, + RedirectPoolId: poolID, Description: "Go SDK test policy", Name: tools.RandomString("sdk-pol-", 5), - Position: 37, + Position: pointerto.Int(37), } - created, err := policies.Create(client, createOpts).Extract() + created, err := policies.Create(client, createOpts) th.AssertNoErr(t, err) t.Logf("Created L7 Policy") - id := created.ID + id := created.Id t.Cleanup(func() { - th.AssertNoErr(t, policies.Delete(client, id).ExtractErr()) + th.AssertNoErr(t, policies.Delete(client, id)) t.Log("Deleted L7 Policy") }) - got, err := policies.Get(client, id).Extract() + got, err := policies.Get(client, id) th.AssertNoErr(t, err) th.AssertDeepEquals(t, created, got) listOpts := policies.ListOpts{ - ListenerID: []string{listenerID}, + ListenerId: []string{listenerID}, } pages, err := policies.List(client, listOpts).AllPages() th.AssertNoErr(t, err) policySlice, err := policies.ExtractPolicies(pages) th.AssertNoErr(t, err) th.AssertEquals(t, 1, len(policySlice)) - th.AssertEquals(t, id, policySlice[0].ID) + th.AssertEquals(t, id, policySlice[0].Id) - nameUpdated := tools.RandomString("updated-", 5) updateOpts := policies.UpdateOpts{ - Name: &nameUpdated, + Name: tools.RandomString("updated-", 5), } - updated, err := policies.Update(client, id, updateOpts).Extract() + updated, err := policies.Update(client, id, updateOpts) th.AssertNoErr(t, err) t.Log("Updated l7 Policy") th.AssertEquals(t, created.Action, updated.Action) - th.AssertEquals(t, id, updated.ID) + th.AssertEquals(t, id, updated.Id) - got2, _ := policies.Get(client, id).Extract() + got2, _ := policies.Get(client, id) th.AssertDeepEquals(t, updated, got2) } @@ -95,56 +94,55 @@ func TestPolicyWorkflowFixedResponse(t *testing.T) { createOpts := policies.CreateOpts{ Action: "FIXED_RESPONSE", - ListenerID: listener.ID, - FixedResponseConfig: &policies.FixedResponseOptions{ + ListenerId: listener.ID, + FixedResponseConfig: policies.FixedResponseOptions{ StatusCode: "200", ContentType: "text/plain", MessageBody: "Fixed Response", }, Description: "Go SDK test policy", Name: tools.RandomString("sdk-pol-", 5), - Position: 37, + Position: pointerto.Int(37), } - created, err := policies.Create(client, createOpts).Extract() + created, err := policies.Create(client, createOpts) th.AssertNoErr(t, err) t.Logf("Created L7 Policy") - id := created.ID + id := created.Id t.Cleanup(func() { - th.AssertNoErr(t, policies.Delete(client, id).ExtractErr()) + th.AssertNoErr(t, policies.Delete(client, id)) t.Log("Deleted L7 Policy") }) - got, err := policies.Get(client, id).Extract() + got, err := policies.Get(client, id) th.AssertNoErr(t, err) th.AssertDeepEquals(t, created, got) listOpts := policies.ListOpts{ - ListenerID: []string{listener.ID}, + ListenerId: []string{listener.ID}, } pages, err := policies.List(client, listOpts).AllPages() th.AssertNoErr(t, err) policySlice, err := policies.ExtractPolicies(pages) th.AssertNoErr(t, err) th.AssertEquals(t, 1, len(policySlice)) - th.AssertEquals(t, id, policySlice[0].ID) + th.AssertEquals(t, id, policySlice[0].Id) - nameUpdated := tools.RandomString("updated-", 5) updateOpts := policies.UpdateOpts{ - Name: &nameUpdated, - FixedResponseConfig: &policies.FixedResponseOptions{ + Name: tools.RandomString("updated-", 5), + FixedResponseConfig: policies.FixedResponseOptions{ StatusCode: "200", ContentType: "text/plain", MessageBody: "Fixed Response Update", }, } - updated, err := policies.Update(client, id, updateOpts).Extract() + updated, err := policies.Update(client, id, updateOpts) th.AssertNoErr(t, err) t.Log("Updated l7 Policy") th.AssertEquals(t, created.Action, updated.Action) - th.AssertEquals(t, id, updated.ID) + th.AssertEquals(t, id, updated.Id) - got2, _ := policies.Get(client, id).Extract() + got2, _ := policies.Get(client, id) th.AssertDeepEquals(t, updated, got2) } @@ -171,9 +169,9 @@ func TestPolicyWorkflowUlrRedirect(t *testing.T) { createOpts := policies.CreateOpts{ Action: "REDIRECT_TO_URL", - ListenerID: listener.ID, + ListenerId: listener.ID, RedirectUrl: "https://www.bing.com:443", - RedirectUrlConfig: &policies.RedirectUrlOptions{ + RedirectUrlConfig: policies.RedirectUrlOptions{ StatusCode: "302", Protocol: "${protocol}", Port: "${port}", @@ -183,36 +181,35 @@ func TestPolicyWorkflowUlrRedirect(t *testing.T) { }, Description: "Go SDK test policy", Name: tools.RandomString("sdk-pol-", 5), - Position: 37, + Position: pointerto.Int(37), } - created, err := policies.Create(client, createOpts).Extract() + created, err := policies.Create(client, createOpts) th.AssertNoErr(t, err) t.Logf("Created L7 Policy") - id := created.ID + id := created.Id t.Cleanup(func() { - th.AssertNoErr(t, policies.Delete(client, id).ExtractErr()) + th.AssertNoErr(t, policies.Delete(client, id)) t.Log("Deleted L7 Policy") }) - got, err := policies.Get(client, id).Extract() + got, err := policies.Get(client, id) th.AssertNoErr(t, err) th.AssertDeepEquals(t, created, got) listOpts := policies.ListOpts{ - ListenerID: []string{listener.ID}, + ListenerId: []string{listener.ID}, } pages, err := policies.List(client, listOpts).AllPages() th.AssertNoErr(t, err) policySlice, err := policies.ExtractPolicies(pages) th.AssertNoErr(t, err) th.AssertEquals(t, 1, len(policySlice)) - th.AssertEquals(t, id, policySlice[0].ID) + th.AssertEquals(t, id, policySlice[0].Id) - nameUpdated := tools.RandomString("updated-", 5) updateOpts := policies.UpdateOpts{ - Name: &nameUpdated, - RedirectUrlConfig: &policies.RedirectUrlOptions{ + Name: tools.RandomString("updated-", 5), + RedirectUrlConfig: policies.RedirectUrlOptions{ StatusCode: "308", Protocol: "${protocol}", Port: "${port}", @@ -221,12 +218,12 @@ func TestPolicyWorkflowUlrRedirect(t *testing.T) { Host: "${host}", }, } - updated, err := policies.Update(client, id, updateOpts).Extract() + updated, err := policies.Update(client, id, updateOpts) th.AssertNoErr(t, err) t.Log("Updated l7 Policy") th.AssertEquals(t, created.Action, updated.Action) - th.AssertEquals(t, id, updated.ID) + th.AssertEquals(t, id, updated.Id) - got2, _ := policies.Get(client, id).Extract() + got2, _ := policies.Get(client, id) th.AssertDeepEquals(t, updated, got2) } diff --git a/acceptance/openstack/elb/v3/rules_test.go b/acceptance/openstack/elb/v3/rules_test.go index d381a233f..7754ebe7a 100644 --- a/acceptance/openstack/elb/v3/rules_test.go +++ b/acceptance/openstack/elb/v3/rules_test.go @@ -148,20 +148,20 @@ func TestRuleWorkflowConditions(t *testing.T) { func createPolicy(t *testing.T, client *golangsdk.ServiceClient, listenerID, poolID string) string { createOpts := policies.CreateOpts{ Action: "REDIRECT_TO_POOL", - ListenerID: listenerID, - RedirectPoolID: poolID, + ListenerId: listenerID, + RedirectPoolId: poolID, Description: "Go SDK test policy", Name: tools.RandomString("sdk-pol-", 5), - Position: 37, + Position: pointerto.Int(37), } - created, err := policies.Create(client, createOpts).Extract() + created, err := policies.Create(client, createOpts) th.AssertNoErr(t, err) - id := created.ID + id := created.Id t.Logf("Policy created: %s", id) return id } func deletePolicy(t *testing.T, client *golangsdk.ServiceClient, policyID string) { - th.AssertNoErr(t, policies.Delete(client, policyID).ExtractErr()) + th.AssertNoErr(t, policies.Delete(client, policyID)) t.Logf("Policy %s deleted", policyID) } diff --git a/openstack/elb/v3/policies/Update.go b/openstack/elb/v3/policies/Update.go index 231f4f8ca..78af2dfa8 100644 --- a/openstack/elb/v3/policies/Update.go +++ b/openstack/elb/v3/policies/Update.go @@ -1,35 +1,111 @@ package policies -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) type UpdateOpts struct { - Name *string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - RedirectListenerID string `json:"redirect_listener_id,omitempty"` - RedirectPoolID string `json:"redirect_pool_id,omitempty"` - Rules []Rule `json:"rules,omitempty"` - RedirectUrlConfig *RedirectUrlOptions `json:"redirect_url_config,omitempty"` - FixedResponseConfig *FixedResponseOptions `json:"fixed_response_config,omitempty"` - Priority int `json:"priority,omitempty"` + // Specifies the administrative status of the forwarding policy. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Provides supplementary information about the forwarding policy. + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Specifies the forwarding policy name. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Specifies the ID of the listener to which requests are redirected. + // + // Note: + // + // This parameter cannot be left blank or set to null when action is set to REDIRECT_TO_LISTENER. + // + // The listener's protocol must be HTTPS. + // + // A listener added to another load balancer is not allowed. + // + // This parameter cannot be passed in the API for adding or updating a forwarding policy if action is set to REDIRECT_TO_POOL. + RedirectListenerId string `json:"redirect_listener_id,omitempty"` + // Specifies the ID of the backend server group that requests will be forwarded to. + // + // This parameter is valid and mandatory only when action is set to REDIRECT_TO_POOL. The specified backend server group cannot be the default backend server group associated with the listener, or any backend server group associated with the forwarding policies of other listeners. + // + // This parameter cannot be specified when action is set to REDIRECT_TO_LISTENER. + RedirectPoolId string `json:"redirect_pool_id,omitempty"` + // Specifies the URL to which requests are forwarded. + // + // For dedicated load balancers, this parameter will take effect only when advanced forwarding is enabled (enhance_l7policy_enable is set to true). If it is passed when enhance_l7policy_enable is set to false, an error will be returned. + // + // This parameter is mandatory when action is set to REDIRECT_TO_URL. It cannot be specified if the value of action is not REDIRECT_TO_URL. + // + // Format: protocol://host:port/path?query + // + // At least one of the four parameters (protocol, host, port, and path) must be passed, or their values cannot be set to ${xxx} at the same time. (${xxx} indicates that the value in the request will be inherited. For example, ${host} indicates the host in the URL to be redirected.) + // + // The values of protocol and port cannot be the same as those of the associated listener, and either host or path must be passed or their values cannot be ${xxx} at the same time. + // + // For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned. + // + // This parameter is not available in eu-nl region. Please do not use it. + RedirectUrlConfig RedirectUrlOptions `json:"redirect_url_config,omitempty"` + // Specifies the configuration of the page that will be returned. This parameter will take effect when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned. + // + // This parameter is mandatory when action is set to FIXED_RESPONSE. It cannot be specified if the value of action is not FIXED_RESPONSE. + // + // For shared load balancers, this parameter is unsupported. If it is passed, an error will be returned. + // + // This parameter is not available in eu-nl region. Please do not use it. + FixedResponseConfig FixedResponseOptions `json:"fixed_response_config,omitempty"` + // Lists the forwarding rules in the forwarding policy. + // + // The list can contain a maximum of 10 forwarding rules (if conditions is specified, a condition is considered as a rule). + // + // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. + // + // For details, see the description of l7rule. + Rules []L7PolicyRuleOption `json:"rules,omitempty"` + // Specifies the forwarding policy priority. A smaller value indicates a higher priority. The value must be unique for forwarding policies of the same listener. This parameter will take effect only when enhance_l7policy_enable is set to true. If this parameter is passed and enhance_l7policy_enable is set to false, an error will be returned. This parameter is unsupported for shared load balancers. + // + // If action is set to REDIRECT_TO_LISTENER, the value can only be 0, indicating REDIRECT_TO_LISTENER has the highest priority. + // + // If enhance_l7policy_enable is not enabled, forwarding policies are automatically prioritized based on the original policy sorting logic. The priorities of domain names are independent from each other. For the same domain name, the priorities are sorted in the order of exact match (EQUAL_TO), prefix match (STARTS_WITH), and regular expression match (REGEX). If the matching types are the same, the longer the URL is, the higher the priority is. If a forwarding policy contains only a domain name without a path specified, the path is /, and prefix match is used by default. + // + // If enhance_l7policy_enable is set to true and this parameter is not passed, the priority will be a sum of 1 and the highest priority of existing forwarding policy in the same listener by default. If the highest priority of existing forwarding policies is the maximum (10,000), the forwarding policy will fail to be created because the final priority for creating the forwarding policy is the sum of 1 and 10,000, which exceeds the maximum. In this case, specify a value or adjust the priorities of existing forwarding policies. If no forwarding policies exist, the highest priority of existing forwarding policies will be set to 1 by default. + // + // This parameter is invalid for shared load balancers. + // + // This parameter is not available in eu-nl region. Please do not use it. + // + // Minimum: 0 + // + // Maximum: 10000 + Priority *int `json:"priority,omitempty"` + // Specifies the configuration of the backend server group that the requests are forwarded to. This parameter is valid only when action is set to REDIRECT_TO_POOL. + // + // Note: + // + // If action is set to REDIRECT_TO_POOL, specify either redirect_pool_id or redirect_pools_config. If both are specified, only redirect_pools_config takes effect. + // + // This parameter cannot be specified when action is set to REDIRECT_TO_LISTENER. All configuration will be overwritten. RedirectPoolsConfig []RedirectPoolOptions `json:"redirect_pools_config,omitempty"` } -type UpdateOptsBuilder interface { - ToPolicyUpdateMap() (map[string]interface{}, error) -} - -func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "l7policy") -} - -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToPolicyUpdateMap() +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*L7Policy, error) { + b, err := build.RequestBody(opts, "l7policy") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("l7policies", id), b, &r.Body, &golangsdk.RequestOpts{ + + raw, err := client.Put(client.ServiceURL("l7policies", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 201}, }) - return + return extra(err, raw) } diff --git a/openstack/elb/v3/policies/results.go b/openstack/elb/v3/policies/results.go deleted file mode 100644 index 170464cd6..000000000 --- a/openstack/elb/v3/policies/results.go +++ /dev/null @@ -1,25 +0,0 @@ -package policies - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -type commonResult struct { - golangsdk.Result -} - -type CreateResult struct { - commonResult -} - -type GetResult struct { - commonResult -} - -type UpdateResult struct { - commonResult -} - -type DeleteResult struct { - golangsdk.ErrResult -} From 9fd6f83064957b9b5695114dff24afe3e7508b50 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:48:58 +0200 Subject: [PATCH 41/54] Create --- .../elb/v3/policies/testing/requests_test.go | 36 +-- openstack/elb/v3/pools/Create.go | 234 +++++++++++++----- openstack/elb/v3/pools/Get.go | 127 +++++++++- openstack/elb/v3/pools/requests.go | 24 -- openstack/elb/v3/pools/results.go | 58 ----- 5 files changed, 318 insertions(+), 161 deletions(-) delete mode 100644 openstack/elb/v3/pools/requests.go diff --git a/openstack/elb/v3/policies/testing/requests_test.go b/openstack/elb/v3/policies/testing/requests_test.go index aff716728..b13023618 100644 --- a/openstack/elb/v3/policies/testing/requests_test.go +++ b/openstack/elb/v3/policies/testing/requests_test.go @@ -5,22 +5,22 @@ import ( "net/http" "testing" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/policies" th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" ) -func expectedResult() *policies.Policy { - return &policies.Policy{ - ID: "cf4360fd-8631-41ff-a6f5-b72c35da74be", +func expectedResult() *policies.L7Policy { + return &policies.L7Policy{ + Id: "cf4360fd-8631-41ff-a6f5-b72c35da74be", Action: "REDIRECT_TO_LISTENER", - ListenerID: "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - Position: 100, - ProjectID: "99a3fff0d03c428eac3678da6a7d0f24", - Status: "ACTIVE", - RedirectListenerID: "48a97732-449e-4aab-b561-828d29e45050", - Rules: []structs.ResourceRef{}, + ListenerId: "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", + Position: pointerto.Int(100), + ProjectId: "99a3fff0d03c428eac3678da6a7d0f24", + ProvisioningStatus: "ACTIVE", + RedirectListenerId: "48a97732-449e-4aab-b561-828d29e45050", + Rules: []policies.RuleCondition{}, } } @@ -40,10 +40,10 @@ func TestCreateRequest(t *testing.T) { opts := policies.CreateOpts{ Action: "REDIRECT_TO_LISTENER", - ListenerID: "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - RedirectListenerID: "48a97732-449e-4aab-b561-828d29e45050", + ListenerId: "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", + RedirectListenerId: "48a97732-449e-4aab-b561-828d29e45050", } - created, err := policies.Create(client.ServiceClient(), opts).Extract() + created, err := policies.Create(client.ServiceClient(), opts) th.AssertNoErr(t, err) th.AssertDeepEquals(t, expectedResult(), created) @@ -54,7 +54,7 @@ func TestGetRequest(t *testing.T) { defer th.TeardownHTTP() expected := expectedResult() - th.Mux.HandleFunc(fmt.Sprintf("/l7policies/%s", expected.ID), func(w http.ResponseWriter, r *http.Request) { + th.Mux.HandleFunc(fmt.Sprintf("/l7policies/%s", expected.Id), func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) @@ -63,7 +63,7 @@ func TestGetRequest(t *testing.T) { _, _ = fmt.Fprint(w, createResponseBody) }) - policy, err := policies.Get(client.ServiceClient(), expected.ID).Extract() + policy, err := policies.Get(client.ServiceClient(), expected.Id) th.AssertNoErr(t, err) th.AssertDeepEquals(t, expected, policy) @@ -82,7 +82,7 @@ func TestListRequest(t *testing.T) { _, _ = fmt.Fprint(w, listResponseBody) }) - pages, err := policies.List(client.ServiceClient(), nil).AllPages() + pages, err := policies.List(client.ServiceClient(), policies.ListOpts{}).AllPages() th.AssertNoErr(t, err) policySlice, err := policies.ExtractPolicies(pages) @@ -94,7 +94,7 @@ func TestDeleteRequest(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() - id := expectedResult().ID + id := expectedResult().Id th.Mux.HandleFunc(fmt.Sprintf("/l7policies/%s", id), func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "DELETE") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) @@ -103,5 +103,5 @@ func TestDeleteRequest(t *testing.T) { w.WriteHeader(http.StatusNoContent) }) - th.AssertNoErr(t, policies.Delete(client.ServiceClient(), id).ExtractErr()) + th.AssertNoErr(t, policies.Delete(client.ServiceClient(), id)) } diff --git a/openstack/elb/v3/pools/Create.go b/openstack/elb/v3/pools/Create.go index 712b1e160..9241ac2eb 100644 --- a/openstack/elb/v3/pools/Create.go +++ b/openstack/elb/v3/pools/Create.go @@ -1,78 +1,198 @@ package pools -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) -// CreateOptsBuilder allows extensions to add additional parameters to the -// Create request. -type CreateOptsBuilder interface { - ToPoolCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options' struct used in this package's Create -// operation. +// CreateOpts is the common options' struct used in this package's Create operation. type CreateOpts struct { - // The algorithm used to distribute load between the members of the pool. - LBMethod string `json:"lb_algorithm" required:"true"` - - // The protocol used by the pool members, you can use either - // ProtocolTCP, ProtocolHTTP, or ProtocolHTTPS. - Protocol string `json:"protocol" required:"true"` - - // The Loadbalancer on which the members of the pool will be associated with. - // Note: one of LoadbalancerID or ListenerID must be provided. - LoadbalancerID string `json:"loadbalancer_id,omitempty"` - - // The Listener on which the members of the pool will be associated with. - // Note: one of LoadbalancerID or ListenerID must be provided. - ListenerID string `json:"listener_id,omitempty"` - - // ProjectID is the UUID of the project who owns the Pool. - // Only administrative users can specify a project UUID other than their own. - ProjectID string `json:"project_id,omitempty"` - - // Name of the pool. - Name string `json:"name,omitempty"` - - // Human-readable description for the pool. - Description string `json:"description,omitempty"` - - // Persistence is the session persistence of the pool. - // Omit this field to prevent session persistence. - Persistence *SessionPersistence `json:"session_persistence,omitempty"` - - SlowStart *SlowStart `json:"slow_start,omitempty"` - - // The administrative state of the Pool. A valid value is true (UP) - // or false (DOWN). + // Specifies the administrative status of the backend server group. The value can only be updated to true. + // + // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // Specifies whether to enable deletion protection for the pool. - DeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` - + // Provides supplementary information about the backend server group. + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group. + // + // The value can be one of the following: + // + // ROUND_ROBIN: weighted round robin + // + // LEAST_CONNECTIONS: weighted least connections + // + // SOURCE_IP: source IP hash + // + // QUIC_CID: connection ID + // + // Note: + // + // If the value is SOURCE_IP, the weight parameter will not take effect for backend servers. + // + // QUIC_CID is supported only when the protocol of the backend server group is QUIC. + // + // QUIC_CID is not supported in eu-nl region. + LbAlgorithm string `json:"lb_algorithm" required:"true"` + // Specifies the ID of the listener with which the backend server group is associated. Specify either listener_id or loadbalancer_id, or both of them. + // + // Specify either listener_id or loadbalancer_id for shared loadbalancer. + // + // Minimum: 1 + // + // Maximum: 36 + ListenerId string `json:"listener_id,omitempty"` + // Specifies the ID of the load balancer with which the backend server group is associated. Specify either listener_id or loadbalancer_id, or both of them. + // + // Minimum: 1 + // + // Maximum: 36 + LoadbalancerId string `json:"loadbalancer_id,omitempty"` + // Specifies the backend server group name. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Specifies the project ID of the backend server group. + // + // Minimum: 32 + // + // Maximum: 32 + ProjectId string `json:"project_id,omitempty"` + // Specifies the protocol used by the backend server group to receive requests. The value can be TCP, UDP, HTTP, HTTPS, or QUIC. + // + // Note: + // + // If the listener's protocol is UDP, the protocol of the backend server group must be UDP or QUIC. + // + // If the listener's protocol is TCP, the protocol of the backend server group must be TCP. + // + // If the listener's protocol is HTTP, the protocol of the backend server group must be HTTP. + // + // If the listener's protocol is HTTPS, the protocol of the backend server group can be HTTP or HTTPS. + // + // If the listener's protocol is TERMINATED_HTTPS, the protocol of the backend server group must be HTTP. + // + // If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP. + // + // QUIC protocol is not supported in eu-nl region. + // + // Minimum: 1 + // + // Maximum: 255 + Protocol string `json:"protocol" required:"true"` + // Specifies the sticky session. + SessionPersistence SessionPersistence `json:"session_persistence,omitempty"` + // Specifies slow start details. After you enable slow start, new backend servers added to the backend server group are warmed up, and the number of requests they can receive increases linearly during the configured slow start duration. + // + // This parameter can be used when the protocol of the backend server group is HTTP or HTTPS. An error will be returned if the protocol is not HTTP or HTTPS. This parameter is not available in eu-nl region. Please do not use it. + SlowStart SlowStart `json:"slow_start,omitempty"` + // Specifies whether to enable removal protection for the load balancer. + // + // true: Enable removal protection. + // + // false (default): Disable removal protection. + // + // Disable removal protection for all your resources before deleting your account. + // + // This parameter is not available in eu-nl region. Please do not use it. + MemberDeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` // Specifies the ID of the VPC where the backend server group works. + // + // Note: + // + // The backend server group must be associated with the VPC. + // + // Only backend servers in the VPC or IP as Backend servers can be added. + // + // type must be set to instance. + // + // If vpc_id is not specified: vpc_id is determined by the VPC where the backend server works. + // + // Minimum: 0 + // + // Maximum: 36 VpcId string `json:"vpc_id,omitempty"` - // Specifies the type of the backend server group. + // // Values: + // // instance: Any type of backend servers can be added. vpc_id is mandatory. - // ip: Only cross-VPC backend servers can be added. vpc_id cannot be specified. + // + // ip: Only IP as Backend servers can be added. vpc_id cannot be specified. + // // "": Any type of backend servers can be added. + // + // Note: + // + // If this parameter is not passed, any type of backend servers can be added. type will be returned as an empty string. + // + // Specify one of listener_id, loadbalancer_id, or type. Shared load balancers can only can added to the backend server group with loadbalancer_id or listener_id specified. + // + // Minimum: 0 + // + // Maximum: 36 Type string `json:"type,omitempty"` } -// ToPoolCreateMap builds a request body from CreateOpts. -func (opts CreateOpts) ToPoolCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "pool") +// SessionPersistence represents the session persistence feature of the load +// balancing service. It attempts to force connections or requests in the same +// session to be processed by the same member as long as it is active. Three +// types of persistence are supported: +type SessionPersistence struct { + // Specifies the cookie name. The value can contain only letters, digits, hyphens (-), underscores (_), and periods (.). Note: This parameter will take effect only when type is set to APP_COOKIE. Otherwise, an error will be returned. + CookieName string `json:"cookie_name,omitempty"` + // Specifies the sticky session type. The value can be SOURCE_IP, HTTP_COOKIE, or APP_COOKIE.Note: + // + // If the protocol of the backend server group is TCP or UDP, only SOURCE_IP takes effect. + // + // For dedicated load balancers, if the protocol of the backend server group is HTTP or HTTPS, the value can only be HTTP_COOKIE. + // + // If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP. + // + // QUIC protocol is not supported in eu-nl region. + Type string `json:"type" required:"true"` + // Specifies the stickiness duration, in minutes. This parameter will not take effect when type is set to APP_COOKIE. + // + // If the protocol of the backend server group is TCP or UDP, the value ranges from 1 to 60, and the default value is 1. + // + // If the protocol of the backend server group is HTTP or HTTPS, the value ranges from 1 to 1440, and the default value is 1440. + PersistenceTimeout *int `json:"persistence_timeout,omitempty"` +} + +type SlowStart struct { + // Specifies whether to enable slow start. + // + // true: Enable slow start. + // + // false: Disable slow start. + // + // Default: false + Enable *bool `json:"enable,omitempty"` + // Specifies the slow start duration, in seconds. + // + // The value ranges from 30 to 1200, and the default value is 30. + // + // Minimum: 30 + // + // Maximum: 1200 + // + // Default: 30 + Duration *int `json:"duration,omitempty"` } // Create accepts a CreateOpts struct and uses the values to create a new // load balancer pool. -func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToPoolCreateMap() +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Pool, error) { + b, err := build.RequestBody(opts, "pool") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("pools"), b, &r.Body, nil) - return + + raw, err := client.Post(client.ServiceURL("pools"), b, nil, nil) + return extra(err, raw) } diff --git a/openstack/elb/v3/pools/Get.go b/openstack/elb/v3/pools/Get.go index 1d5a7709a..395220ab0 100644 --- a/openstack/elb/v3/pools/Get.go +++ b/openstack/elb/v3/pools/Get.go @@ -1,9 +1,128 @@ package pools -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "net/http" + + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" +) // Get retrieves a particular pool based on its unique ID. -func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("pools", id), &r.Body, nil) - return +func Get(client *golangsdk.ServiceClient, id string) (*Pool, error) { + raw, err := client.Get(client.ServiceURL("pools", id), nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*Pool, error) { + if err != nil { + return nil, err + } + + var res Pool + err = extract.IntoStructPtr(raw.Body, &res, "pool") + return &res, err +} + +// Pool represents a logical set of devices, such as web servers, that you +// group together to receive and process traffic. The load balancing function +// chooses a Member of the Pool according to the configured load balancing +// method to handle the new requests or connections received on the VIP address. +type Pool struct { + // Specifies the administrative status of the backend server group. The value can only be true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up"` + // Provides supplementary information about the backend server group. + Description string `json:"description"` + // Specifies the ID of the health check configured for the backend server group. + HealthmonitorId string `json:"healthmonitor_id"` + // Specifies the backend server group ID. + Id string `json:"id"` + // Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group. + // + // The value can be one of the following: + // + // ROUND_ROBIN: weighted round robin + // + // LEAST_CONNECTIONS: weighted least connections + // + // SOURCE_IP: source IP hash + // + // QUIC_CID: connection ID + // + // Note: + // + // If the value is SOURCE_IP, the weight parameter will not take effect for backend servers. + // + // QUIC_CID is supported only when the protocol of the backend server group is QUIC. + // + // QUIC_CID is not supported in eu-nl region. + LbAlgorithm string `json:"lb_algorithm"` + // Specifies the IDs of the listeners with which the backend server group is associated. + Listeners []structs.ResourceRef `json:"listeners"` + // Specifies the IDs of the load balancers with which the backend server group is associated. + Loadbalancers []structs.ResourceRef `json:"loadbalancers"` + // Specifies the IDs of the backend servers in the backend server group. + Members []structs.ResourceRef `json:"members"` + // Specifies the backend server group name. + Name string `json:"name"` + // Specifies the project ID. + ProjectId string `json:"project_id"` + // Specifies the protocol used by the backend server group to receive requests. The value can be TCP, UDP, HTTP, HTTPS, or QUIC. + // + // If the listener's protocol is UDP, the protocol of the backend server group must be UDP. + // + // If the listener's protocol is TCP, the protocol of the backend server group must be TCP. + // + // If the listener's protocol is HTTP, the protocol of the backend server group must be HTTP. + // + // If the listener's protocol is HTTPS, the protocol of the backend server group can be HTTP or HTTPS. + // + // If the listener's protocol is TERMINATED_HTTPS, the protocol of the backend server group must be HTTP. + // + // If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP. + // + // QUIC protocol is not supported in eu-nl region. + Protocol string `json:"protocol"` + // Specifies the sticky session. + SessionPersistence SessionPersistence `json:"session_persistence"` + // Specifies the IP address version supported by the backend server group. + // + // IPv6 is unsupported. Only v4 will be returned. + IpVersion string `json:"ip_version"` + // Specifies slow start details. After you enable slow start, new backend servers added to the backend server group are warmed up, and the number of requests they can receive increases linearly during the configured slow start duration. + // + // This parameter can be used when the protocol of the backend server group is HTTP or HTTPS. An error will be returned if the protocol is not HTTP or HTTPS. This parameter is not available in eu-nl region. Please do not use it. + SlowStart SlowStart `json:"slow_start"` + // Specifies whether to enable removal protection. + // + // true: Enable removal protection. + // + // false: Disable removal protection. + // + // Disable removal protection for all your resources before deleting your account. + // + // This parameter is not available in eu-nl region. Please do not use it. + MemberDeletionProtectionEnable *bool `json:"member_deletion_protection_enable"` + // Specifies the time when a backend server group was created. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + CreatedAt string `json:"created_at"` + // Specifies the time when when a backend server group was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + UpdatedAt string `json:"updated_at"` + // Specifies the ID of the VPC where the backend server group works. + VpcId string `json:"vpc_id"` + // Specifies the type of the backend server group. + // + // Values: + // + // instance: Any type of backend servers can be added. vpc_id is mandatory. + // + // ip: Only IP as Backend servers can be added. vpc_id cannot be specified. + // + // "": Any type of backend servers can be added. + Type string `json:"type"` } diff --git a/openstack/elb/v3/pools/requests.go b/openstack/elb/v3/pools/requests.go deleted file mode 100644 index fab4ab2cd..000000000 --- a/openstack/elb/v3/pools/requests.go +++ /dev/null @@ -1,24 +0,0 @@ -package pools - -// SessionPersistence represents the session persistence feature of the load -// balancing service. It attempts to force connections or requests in the same -// session to be processed by the same member as long as it is active. Three -// types of persistence are supported: -type SessionPersistence struct { - // The type of persistence mode. - Type string `json:"type" required:"true"` - - // Name of cookie if persistence mode is set appropriately. - CookieName string `json:"cookie_name,omitempty"` - - // PersistenceTimeout specifies the stickiness duration, in minutes. - PersistenceTimeout int `json:"persistence_timeout,omitempty"` -} - -type SlowStart struct { - // Specifies whether to Enable slow start. - Enable bool `json:"enable" required:"true"` - - // Specifies the slow start Duration, in seconds. - Duration int `json:"duration" required:"true"` -} diff --git a/openstack/elb/v3/pools/results.go b/openstack/elb/v3/pools/results.go index bcf2faaa6..ed0c1108f 100644 --- a/openstack/elb/v3/pools/results.go +++ b/openstack/elb/v3/pools/results.go @@ -2,67 +2,9 @@ package pools import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/structs" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// Pool represents a logical set of devices, such as web servers, that you -// group together to receive and process traffic. The load balancing function -// chooses a Member of the Pool according to the configured load balancing -// method to handle the new requests or connections received on the VIP address. -type Pool struct { - // The load-balancer algorithm, which is round-robin, least-connections, and - // so on. This value, which must be supported, is dependent on the provider. - // Round-robin must be supported. - LBMethod string `json:"lb_algorithm"` - - // The protocol of the Pool, which is TCP, HTTP, or HTTPS. - Protocol string `json:"protocol"` - - // Description for the Pool. - Description string `json:"description"` - - // A list of listeners objects IDs. - Listeners []structs.ResourceRef `json:"listeners"` - - // A list of member objects IDs. - Members []structs.ResourceRef `json:"members"` - - // The ID of associated health monitor. - MonitorID string `json:"healthmonitor_id"` - - // The administrative state of the Pool, which is up (true) or down (false). - AdminStateUp bool `json:"admin_state_up"` - - // Pool name. Does not have to be unique. - Name string `json:"name"` - - ProjectID string `json:"project_id"` - - // The unique ID for the Pool. - ID string `json:"id"` - - // A list of load balancer objects IDs. - Loadbalancers []structs.ResourceRef `json:"loadbalancers"` - - // Indicates whether connections in the same session will be processed by the - // same Pool member or not. - Persistence *SessionPersistence `json:"session_persistence"` - - IpVersion string `json:"ip_version"` - - SlowStart *SlowStart `json:"slow_start"` - - // Deletion protection for the pool. - DeletionProtectionEnable bool `json:"member_deletion_protection_enable"` - - // ID of the VPC where the backend server group works. - VpcId string `json:"vpc_id"` - - // Type of the backend server group. - Type string `json:"type"` -} - // PoolPage is the page returned by a pager when traversing over a // collection of pools. type PoolPage struct { From fe32c369b1b5652c1658171b76fdfdc9dd6ec3e7 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:52:07 +0200 Subject: [PATCH 42/54] List --- openstack/elb/v3/pools/List.go | 190 ++++++++++++++++++++++++------ openstack/elb/v3/pools/results.go | 68 ----------- 2 files changed, 154 insertions(+), 104 deletions(-) delete mode 100644 openstack/elb/v3/pools/results.go diff --git a/openstack/elb/v3/pools/List.go b/openstack/elb/v3/pools/List.go index ad88caa8f..ee68d3598 100644 --- a/openstack/elb/v3/pools/List.go +++ b/openstack/elb/v3/pools/List.go @@ -2,42 +2,142 @@ package pools import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToPoolListQuery() (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 Pool attributes you want to see returned. SortKey allows you to // sort by a particular Pool attribute. SortDir sets the direction, and is // either `asc` or `desc`. Marker and Limit are used for pagination. type ListOpts struct { - Description []string `q:"description"` - HealthMonitorID []string `q:"healthmonitor_id"` - LBMethod []string `q:"lb_algorithm"` - Protocol []string `q:"protocol"` - AdminStateUp *bool `q:"admin_state_up"` - Name []string `q:"name"` - ID []string `q:"id"` - LoadbalancerID []string `q:"loadbalancer_id"` - Limit int `q:"limit"` - Marker string `q:"marker"` - SortKey string `q:"sort_key"` - SortDir string `q:"sort_dir"` -} - -// ToPoolListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToPoolListQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), nil + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit *int `q:"limit"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` + // Provides supplementary information about the backend server group. + // + // Multiple descriptions can be queried in the format of description=xxx&description=xxx. + Description []string `q:"description"` + // Specifies the administrative status of the backend server group. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the ID of the health check configured for the backend server group. + // + // Multiple IDs can be queried in the format of healthmonitor_id=xxx&healthmonitor_id=xxx. + HealthmonitorId []string `q:"healthmonitor_id"` + // Specifies the ID of the backend server group. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + Id []string `q:"id"` + // Specifies the backend server group name. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Specifies the ID of the load balancer with which the backend server group is associated. + // + // Multiple IDs can be queried in the format of loadbalancer_id=xxx&loadbalancer_id=xxx. + LoadbalancerId []string `q:"loadbalancer_id"` + // Specifies the protocol used by the backend server group to receive requests from the load balancer. The value can be TCP, UDP, HTTP, HTTPS, or QUIC. + // + // Multiple protocols can be queried in the format of protocol=xxx&protocol=xxx. + // + // QUIC protocol is not supported in eu-nl region. + Protocol []string `q:"protocol"` + // Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group. + // + // The value can be one of the following: + // + // ROUND_ROBIN: weighted round robin + // + // LEAST_CONNECTIONS: weighted least connections + // + // SOURCE_IP: source IP hash + // + // QUIC_CID: connection ID + // + // Multiple algorithms can be queried in the format of lb_algorithm=xxx&lb_algorithm=xxx. + // + // QUIC_CID is not supported in eu-nl region. + LbAlgorithm []string `q:"lb_algorithm"` + // Specifies the enterprise project ID. + // + // If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project. + // + // If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried). + // + // Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx. + // + // This parameter is unsupported. Please do not use it. + EnterpriseProjectId []string `q:"enterprise_project_id"` + // Specifies the IP address version supported by the backend server group. + // + // Multiple versions can be queried in the format of ip_version=xxx&ip_version=xxx. + IpVersion []string `q:"ip_version"` + // Specifies the private IP address bound to the backend server. This is a query parameter and will not be included in the response. + // + // Multiple IP addresses can be queried in the format of member_address=xxx&member_address=xxx. + MemberAddress []string `q:"member_address"` + // Specifies the ID of the cloud server that serves as a backend server. This parameter is used only as a query condition and is not included in the response. + // + // Multiple IDs can be queried in the format of member_device_id=xxx&member_device_id=xxx. + MemberDeviceId []string `q:"member_device_id"` + // Specifies whether to enable removal protection on backend servers. + // + // true: Enable removal protection. + // + // false: Disable removal protection. + // + // All backend servers will be queried if this parameter is not passed. + // + // This parameter is not available in eu-nl region. Please do not use it. + MemberDeletionProtectionEnable *bool `q:"member_deletion_protection_enable"` + // Specifies the IDs of the associated listeners, including the listeners associated through forwarding policies. + // + // Multiple IDs can be queried in the format of listener_id=xxx&listener_id=xxx. + ListenerId []string `q:"listener_id"` + // Specifies the backend server ID. This parameter is used only as a query condition and is not included in the response. Multiple IDs can be queried in the format of member_instance_id=xxx&member_instance_id=xxx. + MemberInstanceId []string `q:"member_instance_id"` + // Specifies the ID of the VPC where the backend server group works. + VpcId []string `q:"vpc_id"` + // Specifies the type of the backend server group. + // + // Values: + // + // instance: Any type of backend servers can be added. vpc_id is mandatory. + // + // ip: Only IP as Backend servers can be added. vpc_id cannot be specified. + // + // "": Any type of backend servers can be added. + Type []string `q:"type"` } // List returns a Pager which allows you to iterate over a collection of @@ -46,16 +146,34 @@ func (opts ListOpts) ToPoolListQuery() (string, error) { // // Default policy settings return only those pools that are owned by the // tenant who submits the request, unless an admin user submits the request. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("pools") - if opts != nil { - query, err := opts.ToPoolListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + + return pagination.NewPager(client, client.ServiceURL("pools")+query.String(), func(r pagination.PageResult) pagination.Page { return PoolPage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +// PoolPage is the page returned by a pager when traversing over a +// collection of pools. +type PoolPage struct { + pagination.PageWithInfo +} + +// IsEmpty checks whether a PoolPage struct is empty. +func (r PoolPage) IsEmpty() (bool, error) { + is, err := ExtractPools(r) + return len(is) == 0, err +} + +// ExtractPools accepts a Page struct, specifically a PoolPage struct, +// and extracts the elements into a slice of Pool structs. In other words, +// a generic collection is mapped into a relevant slice. +func ExtractPools(r pagination.Page) ([]Pool, error) { + var res []Pool + err := extract.IntoSlicePtr(r.(PoolPage).BodyReader(), &res, "pools") + return res, err +} diff --git a/openstack/elb/v3/pools/results.go b/openstack/elb/v3/pools/results.go deleted file mode 100644 index ed0c1108f..000000000 --- a/openstack/elb/v3/pools/results.go +++ /dev/null @@ -1,68 +0,0 @@ -package pools - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" -) - -// PoolPage is the page returned by a pager when traversing over a -// collection of pools. -type PoolPage struct { - pagination.PageWithInfo -} - -// IsEmpty checks whether a PoolPage struct is empty. -func (r PoolPage) IsEmpty() (bool, error) { - is, err := ExtractPools(r) - return len(is) == 0, err -} - -// ExtractPools accepts a Page struct, specifically a PoolPage struct, -// and extracts the elements into a slice of Pool structs. In other words, -// a generic collection is mapped into a relevant slice. -func ExtractPools(r pagination.Page) ([]Pool, error) { - var s []Pool - err := (r.(PoolPage)).ExtractIntoSlicePtr(&s, "pools") - if err != nil { - return nil, err - } - return s, nil -} - -type commonResult struct { - golangsdk.Result -} - -// Extract is a function that accepts a result and extracts a pool. -func (r commonResult) Extract() (*Pool, error) { - s := new(Pool) - err := r.ExtractIntoStructPtr(s, "pool") - if err != nil { - return nil, err - } - return s, nil -} - -// CreateResult represents the result of a Create operation. Call its Extract -// method to interpret the result as a Pool. -type CreateResult struct { - commonResult -} - -// GetResult represents the result of a Get operation. Call its Extract -// method to interpret the result as a Pool. -type GetResult struct { - commonResult -} - -// UpdateResult represents the result of an Update operation. Call its Extract -// method to interpret the result as a Pool. -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 { - golangsdk.ErrResult -} From 055f3dabd53e7351c0a36ba2f0bfafd184e4b100 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:54:34 +0200 Subject: [PATCH 43/54] Update --- openstack/elb/v3/pools/Update.go | 112 +++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/openstack/elb/v3/pools/Update.go b/openstack/elb/v3/pools/Update.go index 532b5d27d..b502bc0f3 100644 --- a/openstack/elb/v3/pools/Update.go +++ b/openstack/elb/v3/pools/Update.go @@ -1,6 +1,9 @@ package pools -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) // UpdateOptsBuilder allows extensions to add additional parameters to the // Update request. @@ -11,56 +14,91 @@ type UpdateOptsBuilder interface { // UpdateOpts is the common options' struct used in this package's Update // operation. type UpdateOpts struct { - // Name of the pool. - Name *string `json:"name,omitempty"` - - // Human-readable description for the pool. - Description *string `json:"description,omitempty"` - - // The algorithm used to distribute load between the members of the pool. The - // current specification supports LBMethodRoundRobin, LBMethodLeastConnections - // and LBMethodSourceIp as valid values for this attribute. - LBMethod string `json:"lb_algorithm,omitempty"` - - // Specifies whether to enable sticky sessions. - Persistence *SessionPersistence `json:"session_persistence,omitempty"` - - // The administrative state of the Pool. The value can only be updated to true. + // Specifies the administrative status of the backend server group. The value can only be updated to true. + // // This parameter is unsupported. Please do not use it. AdminStateUp *bool `json:"admin_state_up,omitempty"` - - // Specifies whether to enable slow start. - // This parameter is unsupported. Please do not use it. - SlowStart *SlowStart `json:"slow_start,omitempty"` - - // Specifies whether to enable deletion protection for the load balancer. - DeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` - + // Provides supplementary information about the backend server group. + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group. + // + // The value can be one of the following: + // + // ROUND_ROBIN: weighted round robin + // + // LEAST_CONNECTIONS: weighted least connections + // + // SOURCE_IP: source IP hash + // + // QUIC_CID: connection ID + // + // Note: + // + // If the value is SOURCE_IP, the weight parameter will not take effect for backend servers. + // + // QUIC_CID is supported only when the protocol of the backend server group is QUIC. + // + // QUIC_CID is not supported in eu-nl region. + LbAlgorithm string `json:"lb_algorithm,omitempty"` + // Specifies the backend server group name. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Specifies the sticky session. + SessionPersistence SessionPersistence `json:"session_persistence,omitempty"` + // Specifies slow start details. After you enable slow start, new backend servers added to the backend server group are warmed up, and the number of requests they can receive increases linearly during the configured slow start duration. + // + // This parameter can be used when the protocol of the backend server group is HTTP or HTTPS. An error will be returned if the protocol is not HTTP or HTTPS. + // + // This parameter is not available in eu-nl region. Please do not use it. + SlowStart SlowStart `json:"slow_start,omitempty"` + // Specifies whether to enable removal protection for the load balancer. + // + // true: Enable removal protection. + // + // false: Disable removal protection. + // + // Disable removal protection for all your resources before deleting your account. + // + // This parameter is not available in eu-nl region. Please do not use it. + MemberDeletionProtectionEnable *bool `json:"member_deletion_protection_enable,omitempty"` // Specifies the ID of the VPC where the backend server group works. + // + // This parameter can be updated only when vpc_id is left blank. + // + // Minimum: 0 + // + // Maximum: 36 VpcId string `json:"vpc_id,omitempty"` - // Specifies the type of the backend server group. + // // Values: + // // instance: Any type of backend servers can be added. vpc_id is mandatory. - // ip: Only cross-VPC backend servers can be added. vpc_id cannot be specified. + // + // ip: Only IP as Backend servers can be added. vpc_id cannot be specified. + // // "": Any type of backend servers can be added. + // + // Note: This parameter can be updated only when type is left blank. Type string `json:"type,omitempty"` } -// ToPoolUpdateMap builds a request body from UpdateOpts. -func (opts UpdateOpts) ToPoolUpdateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "pool") -} - // Update allows pools to be updated. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToPoolUpdateMap() +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (*Pool, error) { + b, err := build.RequestBody(opts, "pool") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("pools", id), b, &r.Body, &golangsdk.RequestOpts{ + + raw, err := client.Put(client.ServiceURL("pools", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) - return + return extra(err, raw) } From 2a8dad052223ccbc1b291eee08fef0c84d7dcd80 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:56:45 +0200 Subject: [PATCH 44/54] Update --- acceptance/openstack/elb/v3/members_test.go | 4 ++-- acceptance/openstack/elb/v3/pools_test.go | 22 ++++++++++----------- openstack/elb/v3/pools/Update.go | 8 +------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/acceptance/openstack/elb/v3/members_test.go b/acceptance/openstack/elb/v3/members_test.go index 31f746c1d..db5907f3e 100644 --- a/acceptance/openstack/elb/v3/members_test.go +++ b/acceptance/openstack/elb/v3/members_test.go @@ -64,9 +64,9 @@ func TestMemberLifecycle(t *testing.T) { th.AssertEquals(t, updateOpts.Weight, newMember.Weight) updateOptsPool := pools.UpdateOpts{ - DeletionProtectionEnable: pointerto.Bool(false), + MemberDeletionProtectionEnable: pointerto.Bool(false), } - _, err = pools.Update(client, poolID, updateOptsPool).Extract() + _, err = pools.Update(client, poolID, updateOptsPool) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 Pool: %s", poolID) } diff --git a/acceptance/openstack/elb/v3/pools_test.go b/acceptance/openstack/elb/v3/pools_test.go index ed95e7808..8b6755b53 100644 --- a/acceptance/openstack/elb/v3/pools_test.go +++ b/acceptance/openstack/elb/v3/pools_test.go @@ -39,22 +39,20 @@ func TestPoolLifecycle(t *testing.T) { }) t.Logf("Attempting to update ELBv3 Pool: %s", poolID) - poolName := tools.RandomString("update-pool-", 3) - emptyDescription := "" updateOpts := pools.UpdateOpts{ - Name: &poolName, - Description: &emptyDescription, - LBMethod: "ROUND_ROBIN", - DeletionProtectionEnable: pointerto.Bool(false), + Name: tools.RandomString("update-pool-", 3), + Description: "", + LbAlgorithm: "ROUND_ROBIN", + MemberDeletionProtectionEnable: pointerto.Bool(false), } - _, err = pools.Update(client, poolID, updateOpts).Extract() + _, err = pools.Update(client, poolID, updateOpts) th.AssertNoErr(t, err) t.Logf("Updated ELBv3 Pool: %s", poolID) - newPool, err := pools.Get(client, poolID).Extract() + newPool, err := pools.Get(client, poolID) th.AssertNoErr(t, err) - th.AssertEquals(t, *updateOpts.Name, newPool.Name) - th.AssertEquals(t, emptyDescription, newPool.Description) - th.AssertEquals(t, updateOpts.LBMethod, newPool.LBMethod) - th.AssertEquals(t, false, newPool.DeletionProtectionEnable) + th.AssertEquals(t, updateOpts.Name, newPool.Name) + th.AssertEquals(t, "", newPool.Description) + th.AssertEquals(t, updateOpts.LbAlgorithm, newPool.LbAlgorithm) + th.AssertEquals(t, false, newPool.MemberDeletionProtectionEnable) } diff --git a/openstack/elb/v3/pools/Update.go b/openstack/elb/v3/pools/Update.go index b502bc0f3..ad3a4cab2 100644 --- a/openstack/elb/v3/pools/Update.go +++ b/openstack/elb/v3/pools/Update.go @@ -5,12 +5,6 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/internal/build" ) -// UpdateOptsBuilder allows extensions to add additional parameters to the -// Update request. -type UpdateOptsBuilder interface { - ToPoolUpdateMap() (map[string]interface{}, error) -} - // UpdateOpts is the common options' struct used in this package's Update // operation. type UpdateOpts struct { @@ -91,7 +85,7 @@ type UpdateOpts struct { } // Update allows pools to be updated. -func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (*Pool, error) { +func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*Pool, error) { b, err := build.RequestBody(opts, "pool") if err != nil { return nil, err From 12c50baa7a54a2ed041605432cb430c9ad627f72 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:16:31 +0200 Subject: [PATCH 45/54] Create --- openstack/elb/v3/rules/Create.go | 117 ++++++++++++++++++++---------- openstack/elb/v3/rules/Get.go | 97 ++++++++++++++++++++++++- openstack/elb/v3/rules/results.go | 9 --- 3 files changed, 170 insertions(+), 53 deletions(-) diff --git a/openstack/elb/v3/rules/Create.go b/openstack/elb/v3/rules/Create.go index 1d099d212..0957ee442 100644 --- a/openstack/elb/v3/rules/Create.go +++ b/openstack/elb/v3/rules/Create.go @@ -1,55 +1,92 @@ package rules -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/policies" +) type CreateOpts struct { - // Specifies the conditions contained in a forwarding rule. - // This parameter will take effect when enhance_l7policy_enable is set to true. - // If conditions is specified, key and value will not take effect, - // and the value of this parameter will contain all conditions configured for the forwarding rule. - // The keys in the list must be the same, whereas each value must be unique. - Conditions []Condition `json:"conditions,omitempty"` - // Specifies the match content. The value can be one of the following: + // Specifies the administrative status of the forwarding rule. The default value is true. // - // HOST_NAME: A domain name will be used for matching. - // PATH: A URL will be used for matching. - // If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. - Type RuleType `json:"type" required:"true"` - - // Specifies how requests are matched and forwarded. + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies how requests are matched with the forwarding rule. Values: // - // If type is set to HOST_NAME, this parameter can only be set to EQUAL_TO. Asterisks (*) can be used as wildcard characters. - // If type is set to PATH, this parameter can be set to REGEX, STARTS_WITH, or EQUAL_TO. - CompareType CompareType `json:"compare_type" required:"true"` - - // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. + // EQUAL_TO: exact match. + // + // REGEX: regular expression match + // + // STARTS_WITH: prefix match + // + // Note: + // + // If type is set to HOST_NAME, the value can only be EQUAL_TO, and asterisks (*) can be used as wildcard characters. + // + // If type is set to PATH, the value can be REGEX, STARTS_WITH, or EQUAL_TO. + // + // If type is set to METHOD or SOURCE_IP, the value can only be EQUAL_TO. // - // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must - // start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost - // label of the domain name. + // If type is set to HEADER or QUERY_STRING, the value can only be EQUAL_TO, asterisks (*) and question marks (?) can be used as wildcard characters. + CompareType string `json:"compare_type" required:"true"` + // Specifies the key of match content. For example, if the request header is used for forwarding, key is the request header. // - // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and - // can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + // This parameter is unsupported. Please do not use it. + // + // Minimum: 0 + // + // Maximum: 255 + Key string `json:"key,omitempty"` + // Specifies the value of the match content. For example, if a domain name is used for matching, value is the domain name. This parameter is valid only when conditions is left blank. + // + // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), periods (.), and asterisks (*) and must start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name. + // + // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + // + // If type is set to METHOD, SOURCE_IP, HEADER, or QUERY_STRING, this parameter will not take effect, and conditions will be used to specify the key and value. + // + // Minimum: 1 + // + // Maximum: 128 Value string `json:"value" required:"true"` - // Specifies the project ID. - ProjectID string `json:"project_id,omitempty"` -} - -type CreateOptsBuilder interface { - ToRuleCreateMap() (map[string]interface{}, error) -} - -func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "rule") + // + // Minimum: 32 + // + // Maximum: 32 + ProjectId string `json:"project_id,omitempty"` + // Specifies the match content. The value can be one of the following: + // + // HOST_NAME: A domain name will be used for matching. + // + // PATH: A URL will be used for matching. + // + // METHOD: An HTTP request method will be used for matching. + // + // HEADER: The request header will be used for matching. + // + // QUERY_STRING: A query string will be used for matching. + // + // SOURCE_IP: The source IP address will be used for matching. Note: If type is set to HOST_NAME, PATH, METHOD, or SOURCE_IP, only one forwarding rule can be created for each type. + Type string `json:"type" required:"true"` + // Specifies whether reverse matching is supported. The value can be true or false (default). + // + // This parameter is unsupported. Please do not use it. + Invert *bool `json:"invert,omitempty"` + // Specifies the matching conditions of the forwarding rule. This parameter is available only when enhance_l7policy_enable is set to true. + // + // If conditions is specified, parameters key and value will not take effect, and the conditions value will contain all conditions configured for the forwarding rule. The keys in the list must be the same, whereas each value must be unique. + // + // This parameter is not available in eu-nl region. Please do not use it. + Conditions []policies.RuleCondition `json:"conditions,omitempty"` } -func Create(client *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToRuleCreateMap() +func Create(client *golangsdk.ServiceClient, policyID string, opts CreateOpts) (*ForwardingRule, error) { + b, err := build.RequestBody(opts, "rule") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Post(client.ServiceURL("l7policies", policyID, "rules"), b, &r.Body, nil) - return + + raw, err := client.Post(client.ServiceURL("l7policies", policyID, "rules"), b, nil, nil) + return extra(err, raw) } diff --git a/openstack/elb/v3/rules/Get.go b/openstack/elb/v3/rules/Get.go index 624cc004e..c34897016 100644 --- a/openstack/elb/v3/rules/Get.go +++ b/openstack/elb/v3/rules/Get.go @@ -1,8 +1,97 @@ package rules -import "github.com/opentelekomcloud/gophertelekomcloud" +import ( + "net/http" -func Get(client *golangsdk.ServiceClient, policyID, id string) (r GetResult) { - _, r.Err = client.Get(client.ServiceURL("l7policies", policyID, "rules", id), &r.Body, nil) - return + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/policies" +) + +func Get(client *golangsdk.ServiceClient, policyID, id string) (*ForwardingRule, error) { + raw, err := client.Get(client.ServiceURL("l7policies", policyID, "rules", id), nil, nil) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*ForwardingRule, error) { + if err != nil { + return nil, err + } + + var rule ForwardingRule + err = extract.IntoStructPtr(raw.Body, &rule, "rule") + return &rule, err +} + +type ForwardingRule struct { + // Specifies the administrative status of the forwarding rule. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up"` + // Specifies how requests are matched with the domain name or URL. + // + // If type is set to HOST_NAME, this parameter can only be set to EQUAL_TO. + // + // If type is set to PATH, the value can be REGEX, STARTS_WITH, or EQUAL_TO. + CompareType string `json:"compare_type"` + // Specifies the key of the match content. This parameter will not take effect if type is set to HOST_NAME or PATH. + // + // Minimum: 1 + // + // Maximum: 255 + Key string `json:"key"` + // Specifies the project ID. + ProjectId string `json:"project_id"` + // Specifies the type of the forwarding rule. The value can be one of the following: + // + // HOST_NAME: A domain name will be used for matching. + // + // PATH: A URL will be used for matching. + // + // METHOD: An HTTP request method will be used for matching. + // + // HEADER: The request header will be used for matching. + // + // QUERY_STRING: A query string will be used for matching. + // + // SOURCE_IP: The source IP address will be used for matching. + // + // Note: + // + // If type is set to HOST_NAME, PATH, METHOD, and SOURCE_IP, only one forwarding rule can be created for each type. If type is set to HEADER and QUERY_STRING, multiple forwarding rules can be created for each type. + Type string `json:"type"` + // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. This parameter will take effect only when conditions is left blank. + // + // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name. + // + // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + // + // If type is set to METHOD, SOURCE_IP, HEADER, or QUERY_STRING, this parameter will not take effect, and condition_pair will be used to specify the key and value. + // + // Minimum: 1 + // + // Maximum: 128 + Value string `json:"value"` + // Specifies the provisioning status of the forwarding rule. + // + // The value can only be ACTIVE (default), PENDING_CREATE, or ERROR. + // + // This parameter is unsupported. Please do not use it. + ProvisioningStatus string `json:"provisioning_status"` + // Specifies whether reverse matching is supported. The value is fixed at false. This parameter can be updated but will not take effect. + Invert *bool `json:"invert"` + // Specifies the forwarding policy ID. + Id string `json:"id"` + // Specifies the matching conditions of the forwarding rule. This parameter will take effect when enhance_l7policy_enable is set to .true. If conditions is specified, key and value will not take effect, and the value of this parameter will contain all conditions configured for the forwarding rule. The keys in the list must be the same, whereas each value must be unique. + // + // This parameter is not available in eu-nl region. Please do not use it. + Conditions []policies.RuleCondition `json:"conditions"` + // Specifies the time when the forwarding rule was added. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + CreatedAt string `json:"created_at"` + // Specifies the time when the forwarding rule was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time). + // + // This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers. + UpdatedAt string `json:"updated_at"` } diff --git a/openstack/elb/v3/rules/results.go b/openstack/elb/v3/rules/results.go index b288a359c..99809196b 100644 --- a/openstack/elb/v3/rules/results.go +++ b/openstack/elb/v3/rules/results.go @@ -5,15 +5,6 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -type ForwardingRule struct { - ID string `json:"id"` - Type RuleType `json:"type"` - CompareType CompareType `json:"compare_type"` - Value string `json:"value"` - ProjectID string `json:"project_id"` - Conditions []Condition `json:"conditions"` -} - type commonResult struct { golangsdk.Result } From 837aa134ba855a587a26edcbf86f84a71d919759 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:19:29 +0200 Subject: [PATCH 46/54] ListOpts --- openstack/elb/v3/rules/Delete.go | 4 +- openstack/elb/v3/rules/List.go | 125 ++++++++++++++++++++++++------ openstack/elb/v3/rules/results.go | 19 ----- 3 files changed, 105 insertions(+), 43 deletions(-) diff --git a/openstack/elb/v3/rules/Delete.go b/openstack/elb/v3/rules/Delete.go index 8018c553f..92aa55e00 100644 --- a/openstack/elb/v3/rules/Delete.go +++ b/openstack/elb/v3/rules/Delete.go @@ -2,7 +2,7 @@ package rules import "github.com/opentelekomcloud/gophertelekomcloud" -func Delete(client *golangsdk.ServiceClient, policyID, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("l7policies", policyID, "rules", id), nil) +func Delete(client *golangsdk.ServiceClient, policyID, id string) (err error) { + _, err = client.Delete(client.ServiceURL("l7policies", policyID, "rules", id), nil) return } diff --git a/openstack/elb/v3/rules/List.go b/openstack/elb/v3/rules/List.go index 5bebfc0c5..46396d995 100644 --- a/openstack/elb/v3/rules/List.go +++ b/openstack/elb/v3/rules/List.go @@ -2,36 +2,117 @@ package rules import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -type ListOptsBuilder interface { - ToRuleListQuery() (string, error) -} - type ListOpts struct { - ID []string `q:"id"` - CompareType []CompareType `q:"compare_type"` - Value []string `q:"value"` - Type []RuleType `q:"type"` - - Limit int `q:"limit"` - Marker string `q:"marker"` - PageReverse bool `q:"page_reverse"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit *int `q:"limit"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` + // Specifies the forwarding rule ID. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + Id []string `q:"id"` + // Specifies how requests are matched with the domain names or URL. Values: + // + // EQUAL_TO: exact match. + // + // REGEX: regular expression match + // + // STARTS_WITH: prefix match + // + // Multiple values can be queried in the format of compare_type=xxx&compare_type=xxx. + CompareType []string `q:"compare_type"` + // Specifies the provisioning status of the forwarding rule. The value can only be ACTIVE, indicating that the forwarding rule is provisioned successfully. + // + // Multiple provisioning statuses can be queried in the format of provisioning_status=xxx&provisioning_status=xxx. + ProvisioningStatus []string `q:"provisioning_status"` + // Specifies whether reverse matching is supported. + // + // The value is fixed at false. This parameter can be updated but remains invalid. + Invert *bool `q:"invert"` + // Specifies the administrative status of the forwarding rule. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `q:"admin_state_up"` + // Specifies the value of the match content. + // + // Multiple values can be queried in the format of value=xxx&value=xxx. + Value []string `q:"value"` + // Specifies the key of the match content that is used to identify the forwarding rule. + // + // Multiple keys can be queried in the format of key=xxx&key=xxx. + // + // This parameter is unsupported. Please do not use it. + Key []string `q:"key"` + // Specifies the match type. The value can be HOST_NAME or PATH. + // + // The type of forwarding rules for the same forwarding policy cannot be the same. + // + // Multiple types can be queried in the format of type=xxx&type=xxx. + Type []string `q:"type"` + // Specifies the enterprise project ID. + // + // If this parameter is not passed, resources in the default enterprise project are queried, and authentication is performed based on the default enterprise project. + // + // If this parameter is passed, its value can be the ID of an existing enterprise project (resources in the specific enterprise project are required) or all_granted_eps (resources in all enterprise projects are queried). + // + // Multiple IDs can be queried in the format of enterprise_project_id=xxx&enterprise_project_id=xxx. + // + // This parameter is unsupported. Please do not use it. + EnterpriseProjectId []string `q:"enterprise_project_id"` } -func List(client *golangsdk.ServiceClient, policyID string, opts ListOptsBuilder) pagination.Pager { - url := client.ServiceURL("l7policies", policyID, "rules") - - if opts != nil { - q, err := opts.ToRuleListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += q +func List(client *golangsdk.ServiceClient, policyID string, opts ListOpts) pagination.Pager { + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return pagination.NewPager(client, client.ServiceURL("l7policies", policyID, "rules")+query.String(), func(r pagination.PageResult) pagination.Page { return RulePage{PageWithInfo: pagination.NewPageWithInfo(r)} }) } + +type RulePage struct { + pagination.PageWithInfo +} + +func (p RulePage) IsEmpty() (bool, error) { + rules, err := ExtractRules(p) + return len(rules) == 0, err +} + +func ExtractRules(p pagination.Page) ([]ForwardingRule, error) { + var res []ForwardingRule + err := extract.IntoSlicePtr(p.(RulePage).BodyReader(), &res, "rules") + return res, err +} diff --git a/openstack/elb/v3/rules/results.go b/openstack/elb/v3/rules/results.go index 99809196b..e531be601 100644 --- a/openstack/elb/v3/rules/results.go +++ b/openstack/elb/v3/rules/results.go @@ -2,7 +2,6 @@ package rules import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type commonResult struct { @@ -33,21 +32,3 @@ type UpdateResult struct { type DeleteResult struct { golangsdk.ErrResult } - -type RulePage struct { - pagination.PageWithInfo -} - -func (p RulePage) IsEmpty() (bool, error) { - rules, err := ExtractRules(p) - return len(rules) == 0, err -} - -func ExtractRules(p pagination.Page) ([]ForwardingRule, error) { - var policies []ForwardingRule - err := p.(RulePage).ExtractIntoSlicePtr(&policies, "rules") - if err != nil { - return nil, err - } - return policies, nil -} From 8c155acfda427c3e3720ab27127327cc9a8fe578 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:21:39 +0200 Subject: [PATCH 47/54] Update --- openstack/elb/v3/rules/Update.go | 79 ++++++++++++++++++++++++------- openstack/elb/v3/rules/results.go | 34 ------------- 2 files changed, 61 insertions(+), 52 deletions(-) delete mode 100644 openstack/elb/v3/rules/results.go diff --git a/openstack/elb/v3/rules/Update.go b/openstack/elb/v3/rules/Update.go index 0f8663cd8..b092038e6 100644 --- a/openstack/elb/v3/rules/Update.go +++ b/openstack/elb/v3/rules/Update.go @@ -1,29 +1,72 @@ package rules -import "github.com/opentelekomcloud/gophertelekomcloud" - -type UpdateOptsBuilder interface { - ToUpdateRuleMap() (map[string]interface{}, error) -} +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/policies" +) type UpdateOpts struct { - CompareType CompareType `json:"compare_type,omitempty"` - Value string `json:"value,omitempty"` - Conditions []Condition `json:"conditions,omitempty"` + // Specifies the administrative status of the forwarding rule. The default value is true. + // + // This parameter is unsupported. Please do not use it. + AdminStateUp *bool `json:"admin_state_up,omitempty"` + // Specifies how requests are matched with the forwarding rule. Values: + // + // EQUAL_TO: exact match. + // + // REGEX: regular expression match + // + // STARTS_WITH: prefix match + // + // Note: + // + // If type is set to HOST_NAME, the value can only be EQUAL_TO, and asterisks (*) can be used as wildcard characters. + // + // If type is set to PATH, the value can be REGEX, STARTS_WITH, or EQUAL_TO. + // + // If type is set to METHOD or SOURCE_IP, the value can only be EQUAL_TO. + // + // If type is set to HEADER or QUERY_STRING, the value can only be EQUAL_TO, asterisks (*) and question marks (?) can be used as wildcard characters. + CompareType string `json:"compare_type,omitempty"` + // Specifies whether reverse matching is supported. The value can be true or false. + // + // This parameter is unsupported. Please do not use it. + Invert *bool `json:"invert,omitempty"` + // Specifies the key of the match item. For example, if an HTTP header is used for matching, key is the name of the HTTP header parameter. + // + // This parameter is unsupported. Please do not use it. + // + // Minimum: 0 + // + // Maximum: 255 + Key string `json:"key,omitempty"` + // Specifies the value of the match item. For example, if a domain name is used for matching, value is the domain name. This parameter will take effect only when conditions is left blank. + // + // If type is set to HOST_NAME, the value can contain letters, digits, hyphens (-), and periods (.) and must start with a letter or digit. If you want to use a wildcard domain name, enter an asterisk (*) as the leftmost label of the domain name. + // + // If type is set to PATH and compare_type to STARTS_WITH or EQUAL_TO, the value must start with a slash (/) and can contain only letters, digits, and special characters _~';@^-%#&$.*+?,=!:|/()[]{} + // + // If type is set to METHOD, SOURCE_IP, HEADER, or QUERY_STRING, this parameter will not take effect, and conditions will be used to specify the key and value. + // + // Minimum: 1 + // + // Maximum: 128 + Value string `json:"value,omitempty"` + // Specifies the matching conditions of the forwarding rule. This parameter will take effect when enhance_l7policy_enable is set to .true. If conditions is specified, key and value will not take effect, and the value of this parameter will contain all conditions configured for the forwarding rule. The keys in the list must be the same, whereas each value must be unique. + // + // This parameter is not available in eu-nl region. Please do not use it. + Conditions []policies.RuleCondition `json:"conditions,omitempty"` } -func (opts UpdateOpts) ToUpdateRuleMap() (map[string]interface{}, error) { - return golangsdk.BuildRequestBody(opts, "rule") -} - -func Update(client *golangsdk.ServiceClient, policyID, id string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToUpdateRuleMap() +func Update(client *golangsdk.ServiceClient, policyID, id string, opts UpdateOpts) (*ForwardingRule, error) { + b, err := build.RequestBody(opts, "rule") if err != nil { - r.Err = err - return + return nil, err } - _, r.Err = client.Put(client.ServiceURL("l7policies", policyID, "rules", id), b, &r.Body, &golangsdk.RequestOpts{ + + raw, err := client.Put(client.ServiceURL("l7policies", policyID, "rules", id), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200, 201}, }) - return + return extra(err, raw) } diff --git a/openstack/elb/v3/rules/results.go b/openstack/elb/v3/rules/results.go deleted file mode 100644 index e531be601..000000000 --- a/openstack/elb/v3/rules/results.go +++ /dev/null @@ -1,34 +0,0 @@ -package rules - -import ( - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -type commonResult struct { - golangsdk.Result -} - -func (r commonResult) Extract() (*ForwardingRule, error) { - var rule ForwardingRule - err := r.ExtractIntoStructPtr(&rule, "rule") - if err != nil { - return nil, err - } - return &rule, nil -} - -type CreateResult struct { - commonResult -} - -type GetResult struct { - commonResult -} - -type UpdateResult struct { - commonResult -} - -type DeleteResult struct { - golangsdk.ErrResult -} From 13f337c88603329b0aa2c885b0af110c4c36557e Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:23:20 +0200 Subject: [PATCH 48/54] Update --- acceptance/openstack/elb/v3/rules_test.go | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/acceptance/openstack/elb/v3/rules_test.go b/acceptance/openstack/elb/v3/rules_test.go index 7754ebe7a..9cc146951 100644 --- a/acceptance/openstack/elb/v3/rules_test.go +++ b/acceptance/openstack/elb/v3/rules_test.go @@ -36,22 +36,22 @@ func TestRuleWorkflow(t *testing.T) { CompareType: "REGEX", Value: "^.+$", } - created, err := rules.Create(client, policyID, opts).Extract() + created, err := rules.Create(client, policyID, opts) th.AssertNoErr(t, err) - id := created.ID + id := created.Id t.Logf("Rule %s added to the policy %s", id, policyID) th.CheckEquals(t, opts.Type, created.Type) t.Cleanup(func() { - th.AssertNoErr(t, rules.Delete(client, policyID, id).ExtractErr()) + th.AssertNoErr(t, rules.Delete(client, policyID, id)) t.Log("Rule removed from policy") }) - got, err := rules.Get(client, policyID, id).Extract() + got, err := rules.Get(client, policyID, id) th.AssertNoErr(t, err) th.CheckDeepEquals(t, created, got) - pages, err := rules.List(client, policyID, nil).AllPages() + pages, err := rules.List(client, policyID, rules.ListOpts{}).AllPages() th.AssertNoErr(t, err) rulesSlice, err := rules.ExtractRules(pages) @@ -63,10 +63,10 @@ func TestRuleWorkflow(t *testing.T) { updateOpts := rules.UpdateOpts{ Value: "^.*$", } - updated, err := rules.Update(client, policyID, id, updateOpts).Extract() + updated, err := rules.Update(client, policyID, id, updateOpts) th.AssertNoErr(t, err) - got2, err := rules.Get(client, policyID, id).Extract() + got2, err := rules.Get(client, policyID, id) th.AssertNoErr(t, err) th.AssertDeepEquals(t, updated, got2) } @@ -96,7 +96,7 @@ func TestRuleWorkflowConditions(t *testing.T) { policyID := createPolicy(t, client, listener.ID, poolID) t.Cleanup(func() { deletePolicy(t, client, policyID) }) - condition := rules.Condition{ + condition := policies.RuleCondition{ Key: "", Value: "/", } @@ -104,24 +104,24 @@ func TestRuleWorkflowConditions(t *testing.T) { Type: "PATH", CompareType: "STARTS_WITH", Value: "/bbb.html", - Conditions: []rules.Condition{condition}, + Conditions: []policies.RuleCondition{condition}, } - created, err := rules.Create(client, policyID, opts).Extract() + created, err := rules.Create(client, policyID, opts) th.AssertNoErr(t, err) - id := created.ID + id := created.Id t.Logf("Rule %s added to the policy %s", id, policyID) th.CheckEquals(t, opts.Type, created.Type) t.Cleanup(func() { - th.AssertNoErr(t, rules.Delete(client, policyID, id).ExtractErr()) + th.AssertNoErr(t, rules.Delete(client, policyID, id)) t.Log("Rule removed from policy") }) - got, err := rules.Get(client, policyID, id).Extract() + got, err := rules.Get(client, policyID, id) th.AssertNoErr(t, err) th.CheckDeepEquals(t, created, got) - pages, err := rules.List(client, policyID, nil).AllPages() + pages, err := rules.List(client, policyID, rules.ListOpts{}).AllPages() th.AssertNoErr(t, err) rulesSlice, err := rules.ExtractRules(pages) @@ -129,18 +129,18 @@ func TestRuleWorkflowConditions(t *testing.T) { th.AssertEquals(t, 1, len(rulesSlice)) th.CheckDeepEquals(t, *got, rulesSlice[0]) - conditionUpdate := rules.Condition{ + conditionUpdate := policies.RuleCondition{ Key: "", Value: "/home", } updateOpts := rules.UpdateOpts{ CompareType: "EQUAL_TO", - Conditions: []rules.Condition{conditionUpdate}, + Conditions: []policies.RuleCondition{conditionUpdate}, } - updated, err := rules.Update(client, policyID, id, updateOpts).Extract() + updated, err := rules.Update(client, policyID, id, updateOpts) th.AssertNoErr(t, err) - got2, err := rules.Get(client, policyID, id).Extract() + got2, err := rules.Get(client, policyID, id) th.AssertNoErr(t, err) th.AssertDeepEquals(t, updated, got2) } From 7839e32f58487d35ea212ae4d473bf15a1eda59b Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:31:07 +0200 Subject: [PATCH 49/54] List --- openstack/elb/v3/security_policy/Create.go | 58 +++++++-------- openstack/elb/v3/security_policy/Get.go | 34 ++++++++- openstack/elb/v3/security_policy/List.go | 83 +++++++++++++++++----- openstack/elb/v3/security_policy/Update.go | 9 +-- 4 files changed, 126 insertions(+), 58 deletions(-) diff --git a/openstack/elb/v3/security_policy/Create.go b/openstack/elb/v3/security_policy/Create.go index b2e96cd76..fb455c8b4 100644 --- a/openstack/elb/v3/security_policy/Create.go +++ b/openstack/elb/v3/security_policy/Create.go @@ -3,14 +3,33 @@ package security_policy import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/build" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) type CreateOpts struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Protocols []string `json:"protocols" required:"true"` - Ciphers []string `json:"ciphers" required:"true"` + // Specifies the name of the custom security policy. The default value is "". + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Provides supplementary information about the custom security policy. The default value is "". + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Specifies the enterprise project ID. This parameter is unsupported. Please do not use it. + EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` + // Lists the TLS protocols supported by the custom security policy. Value options: TLSv1, TLSv1.1, TLSv1.2, and TLSv1.3. + Protocols []string `json:"protocols" required:"true"` + // Lists the cipher suites supported by the custom security policy. The following cipher suites are supported: ECDHE-RSA-AES256-GCM-SHA384,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-ECDSA-AES128-GCM-SHA256,AES128-GCM-SHA256,AES256-GCM-SHA384,ECDHE-ECDSA-AES128-SHA256,ECDHE-RSA-AES128-SHA256,AES128-SHA256,AES256-SHA256,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-AES128-SHA,ECDHE-RSA-AES128-SHA,ECDHE-RSA-AES256-SHA,ECDHE-ECDSA-AES256-SHA,AES128-SHA,AES256-SHA,CAMELLIA128-SHA,DES-CBC3-SHA,CAMELLIA256-SHA,ECDHE-RSA-CHACHA20-POLY1305,ECDHE-ECDSA-CHACHA20-POLY1305,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_CCM_SHA256,TLS_AES_128_CCM_8_SHA256 + // + // Note: + // + // The protocol and cipher suite must match. At least one cipher suite must match the protocol. + // + // You can match the protocol and cipher suite based on system security policy. + Ciphers []string `json:"ciphers" required:"true"` } func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*SecurityPolicy, error) { @@ -20,32 +39,5 @@ func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*SecurityPolicy, } raw, err := client.Post(client.ServiceURL("security-policies"), b, nil, &golangsdk.RequestOpts{OkCodes: []int{201}}) - if err != nil { - return nil, err - } - - var res SecurityPolicy - err = extract.Into(raw.Body, &res) - return &res, err -} - -type SecurityPolicy struct { - SecurityPolicy PolicyRef `json:"security_policy"` - RequestId string `json:"request_id"` -} - -type PolicyRef struct { - ID string `json:"id"` - ProjectId string `json:"project_id"` - Name string `json:"name"` - Description string `json:"description"` - Listeners []ListenerRef `json:"listeners"` - Protocols []string `json:"protocols"` - Ciphers []string `json:"ciphers"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` -} - -type ListenerRef struct { - ID string `json:"id"` + return extra(err, raw) } diff --git a/openstack/elb/v3/security_policy/Get.go b/openstack/elb/v3/security_policy/Get.go index 101cb327b..081a16c64 100644 --- a/openstack/elb/v3/security_policy/Get.go +++ b/openstack/elb/v3/security_policy/Get.go @@ -1,17 +1,49 @@ package security_policy import ( + "net/http" + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) func Get(client *golangsdk.ServiceClient, id string) (*SecurityPolicy, error) { raw, err := client.Get(client.ServiceURL("security-policies", id), nil, &golangsdk.RequestOpts{OkCodes: []int{200}}) + return extra(err, raw) +} + +func extra(err error, raw *http.Response) (*SecurityPolicy, error) { if err != nil { return nil, err } var res SecurityPolicy - err = extract.Into(raw.Body, &res) + err = extract.IntoStructPtr(raw.Body, &res, "security_policy") return &res, err } + +type SecurityPolicy struct { + // Specifies the ID of the custom security policy. + Id string `json:"id"` + // Specifies the project ID of the custom security policy. + ProjectId string `json:"project_id"` + // Specifies the name of the custom security policy. + Name string `json:"name"` + // Provides supplementary information about the custom security policy. + Description string `json:"description"` + // Specifies the listeners that use the custom security policies. + Listeners []ListenerRef `json:"listeners"` + // Lists the TLS protocols supported by the custom security policy. + Protocols []string `json:"protocols"` + // Lists the cipher suites supported by the custom security policy. + Ciphers []string `json:"ciphers"` + // Specifies the time when the custom security policy was created. + CreatedAt string `json:"created_at"` + // Specifies the time when the custom security policy was updated. + UpdatedAt string `json:"updated_at"` +} + +type ListenerRef struct { + // Specifies the listener ID. + Id string `json:"id"` +} diff --git a/openstack/elb/v3/security_policy/List.go b/openstack/elb/v3/security_policy/List.go index 2491a8bb9..54bf6c9fd 100644 --- a/openstack/elb/v3/security_policy/List.go +++ b/openstack/elb/v3/security_policy/List.go @@ -3,33 +3,84 @@ package security_policy import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" + "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) type ListOpts struct { - Marker string `q:"marker"` - Limit string `q:"limit"` - PageReverse bool `q:"page_reverse"` - ID []string `q:"id"` - Name []string `q:"name"` + // Specifies the ID of the last record on the previous page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If this parameter is not specified, the first page will be queried. + // + // This parameter cannot be left blank or set to an invalid ID. + Marker string `q:"marker"` + // Specifies the number of records on each page. + // + // Minimum: 0 + // + // Maximum: 2000 + // + // Default: 2000 + Limit *int `q:"limit"` + // Specifies whether to use reverse query. Values: + // + // true: Query the previous page. + // + // false (default): Query the next page. + // + // Note: + // + // This parameter must be used together with limit. + // + // If page_reverse is set to true and you want to query the previous page, set the value of marker to the value of previous_marker. + PageReverse *bool `q:"page_reverse"` + // Specifies the ID of the custom security policy. + // + // Multiple IDs can be queried in the format of id=xxx&id=xxx. + Id []string `q:"id"` + // Specifies the name of the custom security policy. + // + // Multiple names can be queried in the format of name=xxx&name=xxx. + Name []string `q:"name"` + // Provides supplementary information about the custom security policy. + // + // Multiple descriptions can be queried in the format of description=xxx&description=xxx. Description []string `q:"description"` - Protocols []string `q:"protocols"` - Ciphers []string `q:"ciphers"` + // Specifies the TLS protocols supported by the custom security policy. (Multiple protocols are separated using spaces.) + // + // Multiple protocols can be queried in the format of protocols=xxx&protocols=xxx. + Protocols []string `q:"protocols"` + // Specifies the cipher suites supported by the custom security policy. (Multiple cipher suites are separated using colons.) + // + // Multiple cipher suites can be queried in the format of ciphers=xxx&ciphers=xxx. + Ciphers []string `q:"ciphers"` } -func List(client *golangsdk.ServiceClient, opts ListOpts) ([]PolicyRef, error) { +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { q, err := golangsdk.BuildQueryString(&opts) if err != nil { - return nil, err + return pagination.Pager{Err: err} } - raw, err := client.Get(client.ServiceURL("security-policies")+q.String(), nil, &golangsdk.RequestOpts{OkCodes: []int{200}}) - if err != nil { - return nil, err - } + return pagination.NewPager(client, client.ServiceURL("security-policies")+q.String(), func(r pagination.PageResult) pagination.Page { + return SecurityPage{PageWithInfo: pagination.NewPageWithInfo(r)} + }) +} - var res []PolicyRef +type SecurityPage struct { + pagination.PageWithInfo +} - err = extract.IntoSlicePtr(raw.Body, &res, "security_policies") - return res, err +func (p SecurityPage) IsEmpty() (bool, error) { + rules, err := ExtractSecurity(p) + return len(rules) == 0, err +} +func ExtractSecurity(p pagination.Page) ([]SecurityPolicy, error) { + var res []SecurityPolicy + err := extract.IntoSlicePtr(p.(SecurityPage).BodyReader(), &res, "security_policies") + return res, err } diff --git a/openstack/elb/v3/security_policy/Update.go b/openstack/elb/v3/security_policy/Update.go index 8a7c08384..2106c3b43 100644 --- a/openstack/elb/v3/security_policy/Update.go +++ b/openstack/elb/v3/security_policy/Update.go @@ -3,7 +3,6 @@ package security_policy import ( golangsdk "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/build" - "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) type UpdateOpts struct { @@ -20,11 +19,5 @@ func Update(client *golangsdk.ServiceClient, opts UpdateOpts, id string) (*Secur } raw, err := client.Put(client.ServiceURL("security-policies", id), b, nil, &golangsdk.RequestOpts{OkCodes: []int{200}}) - if err != nil { - return nil, err - } - - var res SecurityPolicy - err = extract.Into(raw.Body, &res) - return &res, err + return extra(err, raw) } From c3048aef02a9b268dd2ed908a9312faa54c94055 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:32:26 +0200 Subject: [PATCH 50/54] ListSystemPolicies --- .../v3/security_policy/ListSystemPolicies.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/openstack/elb/v3/security_policy/ListSystemPolicies.go b/openstack/elb/v3/security_policy/ListSystemPolicies.go index e52911305..2df43ce47 100644 --- a/openstack/elb/v3/security_policy/ListSystemPolicies.go +++ b/openstack/elb/v3/security_policy/ListSystemPolicies.go @@ -5,21 +5,24 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -func ListSystemPolicies(client *golangsdk.ServiceClient) ([]SystemPolicy, error) { +func ListSystemPolicies(client *golangsdk.ServiceClient) ([]SystemSecurityPolicy, error) { raw, err := client.Get(client.ServiceURL("system-security-policies"), nil, &golangsdk.RequestOpts{OkCodes: []int{200}}) if err != nil { return nil, err } - var res []SystemPolicy - + var res []SystemSecurityPolicy err = extract.IntoSlicePtr(raw.Body, &res, "system_security_policies") return res, err } -type SystemPolicy struct { - ProjectId string `json:"project_id"` - Name string `json:"name"` +type SystemSecurityPolicy struct { + // Specifies the name of the system security policy. + Name string `json:"name"` + // Lists the TLS protocols supported by the system security policy. Protocols string `json:"protocols"` - Ciphers string `json:"ciphers"` + // Lists the cipher suites supported by the system security policy. + Ciphers string `json:"ciphers"` + // Specifies the project ID. + ProjectId string `json:"project_id"` } From 1f0a4c19353b25c43b48790c0ca05447f55badea Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:39:35 +0200 Subject: [PATCH 51/54] Test --- acceptance/openstack/elb/v3/helpers.go | 28 ++++++------- .../openstack/elb/v3/security_policy_test.go | 42 ++++++++----------- openstack/elb/v3/monitors/List.go | 8 +--- openstack/elb/v3/security_policy/List.go | 4 +- openstack/elb/v3/security_policy/Update.go | 28 +++++++++++-- 5 files changed, 59 insertions(+), 51 deletions(-) diff --git a/acceptance/openstack/elb/v3/helpers.go b/acceptance/openstack/elb/v3/helpers.go index 4932802b3..e7a2c341b 100644 --- a/acceptance/openstack/elb/v3/helpers.go +++ b/acceptance/openstack/elb/v3/helpers.go @@ -151,32 +151,32 @@ func createPool(t *testing.T, client *golangsdk.ServiceClient, loadbalancerID st vpcID := clients.EnvOS.GetEnv("VPC_ID") poolName := tools.RandomString("create-pool-", 3) createOpts := pools.CreateOpts{ - LBMethod: "LEAST_CONNECTIONS", - Protocol: "HTTP", - LoadbalancerID: loadbalancerID, - Name: poolName, - Description: "some interesting description", - VpcId: vpcID, - Type: "instance", - DeletionProtectionEnable: pointerto.Bool(true), + LbAlgorithm: "LEAST_CONNECTIONS", + Protocol: "HTTP", + LoadbalancerId: loadbalancerID, + Name: poolName, + Description: "some interesting description", + VpcId: vpcID, + Type: "instance", + MemberDeletionProtectionEnable: pointerto.Bool(true), } - pool, err := pools.Create(client, createOpts).Extract() + pool, err := pools.Create(client, createOpts) th.AssertNoErr(t, err) th.AssertEquals(t, createOpts.Name, pool.Name) th.AssertEquals(t, createOpts.Description, pool.Description) - th.AssertEquals(t, createOpts.LBMethod, pool.LBMethod) - th.AssertEquals(t, true, pool.DeletionProtectionEnable) + th.AssertEquals(t, createOpts.LbAlgorithm, pool.LbAlgorithm) + th.AssertEquals(t, true, pool.MemberDeletionProtectionEnable) th.AssertEquals(t, createOpts.Type, pool.Type) th.AssertEquals(t, createOpts.VpcId, pool.VpcId) - t.Logf("Created ELBv3 Pool: %s", pool.ID) + t.Logf("Created ELBv3 Pool: %s", pool.Id) - return pool.ID + return pool.Id } func deletePool(t *testing.T, client *golangsdk.ServiceClient, poolID string) { t.Logf("Attempting to delete ELBv3 Pool: %s", poolID) - err := pools.Delete(client, poolID).ExtractErr() + err := pools.Delete(client, poolID) th.AssertNoErr(t, err) t.Logf("Deleted ELBv3 Pool: %s", poolID) } diff --git a/acceptance/openstack/elb/v3/security_policy_test.go b/acceptance/openstack/elb/v3/security_policy_test.go index c488daff7..a93bc7f62 100644 --- a/acceptance/openstack/elb/v3/security_policy_test.go +++ b/acceptance/openstack/elb/v3/security_policy_test.go @@ -21,16 +21,6 @@ func TestSystemSecurityPolicy(t *testing.T) { tools.PrintResource(t, systemPolicies) } -func TestSecurityPolicyList(t *testing.T) { - client, err := clients.NewElbV3Client() - th.AssertNoErr(t, err) - - allPolicies, err := security_policy.List(client, security_policy.ListOpts{}) - th.AssertNoErr(t, err) - - tools.PrintResource(t, allPolicies) -} - func TestSecurityPolicyLifecycle(t *testing.T) { client, err := clients.NewElbV3Client() th.AssertNoErr(t, err) @@ -40,7 +30,7 @@ func TestSecurityPolicyLifecycle(t *testing.T) { secPolicy := createSecurityPolicy(t, client, policyName) tools.PrintResource(t, secPolicy) - t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicy.SecurityPolicy.ID) }) + t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicy.Id) }) updatedName := tools.RandomString("update-policy-", 3) @@ -48,27 +38,31 @@ func TestSecurityPolicyLifecycle(t *testing.T) { Name: updatedName, } - putPolicy, err := security_policy.Update(client, updateOpts, secPolicy.SecurityPolicy.ID) + putPolicy, err := security_policy.Update(client, updateOpts, secPolicy.Id) th.AssertNoErr(t, err) - th.AssertEquals(t, putPolicy.SecurityPolicy.Name, updatedName) + th.AssertEquals(t, putPolicy.Name, updatedName) - getPolicy, err := security_policy.Get(client, secPolicy.SecurityPolicy.ID) + getPolicy, err := security_policy.Get(client, secPolicy.Id) th.AssertNoErr(t, err) tools.PrintResource(t, getPolicy) - th.AssertEquals(t, getPolicy.SecurityPolicy.ID, secPolicy.SecurityPolicy.ID) - th.AssertEquals(t, getPolicy.SecurityPolicy.Name, putPolicy.SecurityPolicy.Name) - th.AssertEquals(t, getPolicy.SecurityPolicy.ProjectId, secPolicy.SecurityPolicy.ProjectId) + th.AssertEquals(t, getPolicy.Id, secPolicy.Id) + th.AssertEquals(t, getPolicy.Name, putPolicy.Name) + th.AssertEquals(t, getPolicy.ProjectId, secPolicy.ProjectId) - listOpts := security_policy.ListOpts{ + allPages, err := security_policy.List(client, security_policy.ListOpts{ Name: []string{ updatedName, }, - } + }).AllPages() + th.AssertNoErr(t, err) - listPolicy, err := security_policy.List(client, listOpts) + allPolicies, err := security_policy.ExtractSecurities(allPages) th.AssertNoErr(t, err) - tools.PrintResource(t, listPolicy) + + for _, pool := range allPolicies { + tools.PrintResource(t, pool) + } } func TestPolicyAssignment(t *testing.T) { @@ -84,7 +78,7 @@ func TestPolicyAssignment(t *testing.T) { t.Cleanup(func() { deleteCertificate(t, client, certificateID) }) t.Run("AssignSecurityPolicyListenerCreation", func(t *testing.T) { - secPolicyID := createSecurityPolicy(t, client, policyName).SecurityPolicy.ID + secPolicyID := createSecurityPolicy(t, client, policyName).Id t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicyID) }) listenerName := tools.RandomString("create-listener-", 3) @@ -111,7 +105,7 @@ func TestPolicyAssignment(t *testing.T) { }) t.Run("AssignSecurityPolicyListenerUpdate", func(t *testing.T) { - secPolicyUpdatedID := createSecurityPolicy(t, client, policyName).SecurityPolicy.ID + secPolicyUpdatedID := createSecurityPolicy(t, client, policyName).Id t.Cleanup(func() { deleteSecurityPolicy(t, client, secPolicyUpdatedID) }) listenerName := tools.RandomString("create-listener-", 3) @@ -167,7 +161,7 @@ func createSecurityPolicy(t *testing.T, client *golangsdk.ServiceClient, policyN secPolicy, err := security_policy.Create(client, secOpts) th.AssertNoErr(t, err) - t.Logf("Created ELBv3 security policy: %s", secPolicy.SecurityPolicy.ID) + t.Logf("Created ELBv3 security policy: %s", secPolicy.Id) return secPolicy } diff --git a/openstack/elb/v3/monitors/List.go b/openstack/elb/v3/monitors/List.go index 184d2a0fc..6a5d47789 100644 --- a/openstack/elb/v3/monitors/List.go +++ b/openstack/elb/v3/monitors/List.go @@ -6,12 +6,6 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/pagination" ) -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToMonitorListQuery() (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 Monitor attributes you want to see returned. SortKey allows you to @@ -130,7 +124,7 @@ type ListOpts struct { // // Default policy settings return only those health monitors that are owned by the // tenant who submits the request, unless an admin user submits the request. -func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { +func List(client *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { query, err := golangsdk.BuildQueryString(opts) if err != nil { return pagination.Pager{Err: err} diff --git a/openstack/elb/v3/security_policy/List.go b/openstack/elb/v3/security_policy/List.go index 54bf6c9fd..f17bd5ac1 100644 --- a/openstack/elb/v3/security_policy/List.go +++ b/openstack/elb/v3/security_policy/List.go @@ -75,11 +75,11 @@ type SecurityPage struct { } func (p SecurityPage) IsEmpty() (bool, error) { - rules, err := ExtractSecurity(p) + rules, err := ExtractSecurities(p) return len(rules) == 0, err } -func ExtractSecurity(p pagination.Page) ([]SecurityPolicy, error) { +func ExtractSecurities(p pagination.Page) ([]SecurityPolicy, error) { var res []SecurityPolicy err := extract.IntoSlicePtr(p.(SecurityPage).BodyReader(), &res, "security_policies") return res, err diff --git a/openstack/elb/v3/security_policy/Update.go b/openstack/elb/v3/security_policy/Update.go index 2106c3b43..f9b5ff1b5 100644 --- a/openstack/elb/v3/security_policy/Update.go +++ b/openstack/elb/v3/security_policy/Update.go @@ -6,10 +6,30 @@ import ( ) type UpdateOpts struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Protocols []string `json:"protocols,omitempty"` - Ciphers []string `json:"ciphers,omitempty"` + // Specifies the name of the custom security policy. + // + // Minimum: 0 + // + // Maximum: 255 + Name string `json:"name,omitempty"` + // Provides supplementary information about the custom security policy. + // + // Minimum: 0 + // + // Maximum: 255 + Description string `json:"description,omitempty"` + // Lists the TLS protocols supported by the custom security policy. Value options: TLSv1, TLSv1.1, TLSv1.2, and TLSv1.3 + Protocols []string `json:"protocols,omitempty"` + // Lists the cipher suites supported by the custom security policy. The following cipher suites are supported: + // + // ECDHE-RSA-AES256-GCM-SHA384,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-ECDSA-AES128-GCM-SHA256,AES128-GCM-SHA256,AES256-GCM-SHA384,ECDHE-ECDSA-AES128-SHA256,ECDHE-RSA-AES128-SHA256,AES128-SHA256,AES256-SHA256,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-AES128-SHA,ECDHE-RSA-AES128-SHA,ECDHE-RSA-AES256-SHA,ECDHE-ECDSA-AES256-SHA,AES128-SHA,AES256-SHA,CAMELLIA128-SHA,DES-CBC3-SHA,CAMELLIA256-SHA,ECDHE-RSA-CHACHA20-POLY1305,ECDHE-ECDSA-CHACHA20-POLY1305,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_CCM_SHA256,TLS_AES_128_CCM_8_SHA256 + // + // Note: + // + // The protocol and cipher suite must match. At least one cipher suite must match the protocol. + // + // You can match the protocol and cipher suite based on system security policy. + Ciphers []string `json:"ciphers,omitempty"` } func Update(client *golangsdk.ServiceClient, opts UpdateOpts, id string) (*SecurityPolicy, error) { From d298f7191ddec474e1b35c53d6b40d5830f6ddfc Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:44:47 +0200 Subject: [PATCH 52/54] clean --- acceptance/openstack/elb/v3/certificates_test.go | 9 +++++---- acceptance/openstack/elb/v3/ipgroups_test.go | 4 +++- openstack/elb/v3/policies/Delete.go | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/acceptance/openstack/elb/v3/certificates_test.go b/acceptance/openstack/elb/v3/certificates_test.go index 0eabc71ba..dbe2e4ace 100644 --- a/acceptance/openstack/elb/v3/certificates_test.go +++ b/acceptance/openstack/elb/v3/certificates_test.go @@ -30,14 +30,15 @@ func TestCertificateLifecycle(t *testing.T) { th.AssertNoErr(t, err) certificateID := createCertificate(t, client) - defer deleteCertificate(t, client, certificateID) + t.Cleanup(func() { + deleteCertificate(t, client, certificateID) + }) t.Logf("Attempting to update ELBv3 certificate: %s", certificateID) certName := tools.RandomString("update-cert-", 3) - emptyDescription := "" updateOpts := certificates.UpdateOpts{ Name: certName, - Description: emptyDescription, + Description: "", } _, err = certificates.Update(client, certificateID, updateOpts) @@ -47,5 +48,5 @@ func TestCertificateLifecycle(t *testing.T) { newCertificate, err := certificates.Get(client, certificateID) th.AssertNoErr(t, err) th.AssertEquals(t, updateOpts.Name, newCertificate.Name) - th.AssertEquals(t, emptyDescription, newCertificate.Description) + th.AssertEquals(t, "", newCertificate.Description) } diff --git a/acceptance/openstack/elb/v3/ipgroups_test.go b/acceptance/openstack/elb/v3/ipgroups_test.go index a5c697744..752782895 100644 --- a/acceptance/openstack/elb/v3/ipgroups_test.go +++ b/acceptance/openstack/elb/v3/ipgroups_test.go @@ -30,7 +30,9 @@ func TestIpGroupsLifecycle(t *testing.T) { th.AssertNoErr(t, err) loadbalancerID := createLoadBalancer(t, client) - defer deleteLoadbalancer(t, client, loadbalancerID) + t.Cleanup(func() { + deleteLoadbalancer(t, client, loadbalancerID) + }) t.Logf("Attempting to create ELBv3 IpGroup") ipGroup, err := ipgroups.Create(client, ipgroups.CreateOpts{ diff --git a/openstack/elb/v3/policies/Delete.go b/openstack/elb/v3/policies/Delete.go index 672d2a4b6..990be4837 100644 --- a/openstack/elb/v3/policies/Delete.go +++ b/openstack/elb/v3/policies/Delete.go @@ -2,7 +2,7 @@ package policies import "github.com/opentelekomcloud/gophertelekomcloud" -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("l7policies", id), nil) +func Delete(client *golangsdk.ServiceClient, id string) (err error) { + _, err = client.Delete(client.ServiceURL("l7policies", id), nil) return } From 997986b22a4837aeb2e46b1570805ff02ab896b9 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:49:01 +0200 Subject: [PATCH 53/54] clean --- openstack/elb/v3/pools/Delete.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openstack/elb/v3/pools/Delete.go b/openstack/elb/v3/pools/Delete.go index 572f6151c..8a5fc7092 100644 --- a/openstack/elb/v3/pools/Delete.go +++ b/openstack/elb/v3/pools/Delete.go @@ -3,7 +3,7 @@ package pools import "github.com/opentelekomcloud/gophertelekomcloud" // Delete will permanently delete a particular pool based on its unique ID. -func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { - _, r.Err = client.Delete(client.ServiceURL("pools", id), nil) +func Delete(client *golangsdk.ServiceClient, id string) (err error) { + _, err = client.Delete(client.ServiceURL("pools", id), nil) return } From 8ba0e6f27ab602646f48ff5426d1b0440fae0ac1 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 29 Jun 2023 23:53:45 +0200 Subject: [PATCH 54/54] clean --- openstack/elb/v3/policies/testing/fixtures.go | 69 ----------- .../elb/v3/policies/testing/requests_test.go | 107 ------------------ 2 files changed, 176 deletions(-) delete mode 100644 openstack/elb/v3/policies/testing/fixtures.go delete mode 100644 openstack/elb/v3/policies/testing/requests_test.go diff --git a/openstack/elb/v3/policies/testing/fixtures.go b/openstack/elb/v3/policies/testing/fixtures.go deleted file mode 100644 index cd590deaf..000000000 --- a/openstack/elb/v3/policies/testing/fixtures.go +++ /dev/null @@ -1,69 +0,0 @@ -package testing - -const ( - createRequestBody = ` -{ - "l7policy" : { - "action" : "REDIRECT_TO_LISTENER", - "listener_id" : "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - "redirect_listener_id" : "48a97732-449e-4aab-b561-828d29e45050" - } -} -` - createResponseBody = ` -{ - "request_id" : "b60d1d9a-5263-45b0-b1d6-2810ac7c52a1", - "l7policy" : { - "description" : "", - "admin_state_up" : true, - "rules" : [ ], - "project_id" : "99a3fff0d03c428eac3678da6a7d0f24", - "listener_id" : "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - "redirect_listener_id" : "48a97732-449e-4aab-b561-828d29e45050", - "action" : "REDIRECT_TO_LISTENER", - "position" : 100, - "provisioning_status" : "ACTIVE", - "id" : "cf4360fd-8631-41ff-a6f5-b72c35da74be", - "name" : "" - } -} -` - listResponseBody = ` -{ - "request_id" : "d3c67339-be91-4813-bb24-85728a5d326a", - "l7policies" : [ { - "redirect_pool_id" : "3b34340d-59e8-4c70-9ef5-b41b12023dc9", - "description" : "", - "admin_state_up" : true, - "rules" : [ { - "id" : "1e5f17df-feec-427e-a162-8e4e05e91085" - } ], - "project_id" : "99a3fff0d03c428eac3678da6a7d0f24", - "listener_id" : "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - "action" : "REDIRECT_TO_POOL", - "position" : 100, - "provisioning_status" : "ACTIVE", - "id" : "0d7bf316-2e03-411f-bf29-c403c04e52bf", - "name" : "elbv3" - }, { - "redirect_pool_id" : "3b34340d-59e8-4c70-9ef5-b41b12023dc9", - "description" : "", - "admin_state_up" : true, - "rules" : [ { - "id" : "0f5e8c34-09d1-4588-8459-f9b9add0be05" - } ], - "project_id" : "99a3fff0d03c428eac3678da6a7d0f24", - "listener_id" : "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - "action" : "REDIRECT_TO_POOL", - "position" : 100, - "provisioning_status" : "ERROR", - "id" : "2587d8b1-9e8d-459c-9081-7bccaa075d2b", - "name" : "elbv3" - } ], - "page_info" : { - "previous_marker" : "0d7bf316-2e03-411f-bf29-c403c04e52bf", - "current_count" : 2 - } -} -` -) diff --git a/openstack/elb/v3/policies/testing/requests_test.go b/openstack/elb/v3/policies/testing/requests_test.go deleted file mode 100644 index b13023618..000000000 --- a/openstack/elb/v3/policies/testing/requests_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package testing - -import ( - "fmt" - "net/http" - "testing" - - "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" - "github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/policies" - th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" - "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" -) - -func expectedResult() *policies.L7Policy { - return &policies.L7Policy{ - Id: "cf4360fd-8631-41ff-a6f5-b72c35da74be", - Action: "REDIRECT_TO_LISTENER", - ListenerId: "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - Position: pointerto.Int(100), - ProjectId: "99a3fff0d03c428eac3678da6a7d0f24", - ProvisioningStatus: "ACTIVE", - RedirectListenerId: "48a97732-449e-4aab-b561-828d29e45050", - Rules: []policies.RuleCondition{}, - } -} - -func TestCreateRequest(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - th.Mux.HandleFunc("/l7policies", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "POST") - th.TestHeader(t, r, "X-Auth-Token", client.TokenID) - th.TestJSONRequest(t, r, createRequestBody) - - w.Header().Add("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - _, _ = fmt.Fprint(w, createResponseBody) - }) - - opts := policies.CreateOpts{ - Action: "REDIRECT_TO_LISTENER", - ListenerId: "e2220d2a-3faf-44f3-8cd6-0c42952bd0ab", - RedirectListenerId: "48a97732-449e-4aab-b561-828d29e45050", - } - created, err := policies.Create(client.ServiceClient(), opts) - th.AssertNoErr(t, err) - - th.AssertDeepEquals(t, expectedResult(), created) -} - -func TestGetRequest(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - expected := expectedResult() - th.Mux.HandleFunc(fmt.Sprintf("/l7policies/%s", expected.Id), func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", client.TokenID) - - w.Header().Add("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = fmt.Fprint(w, createResponseBody) - }) - - policy, err := policies.Get(client.ServiceClient(), expected.Id) - th.AssertNoErr(t, err) - - th.AssertDeepEquals(t, expected, policy) -} - -func TestListRequest(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - th.Mux.HandleFunc("/l7policies", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", client.TokenID) - - w.Header().Add("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = fmt.Fprint(w, listResponseBody) - }) - - pages, err := policies.List(client.ServiceClient(), policies.ListOpts{}).AllPages() - th.AssertNoErr(t, err) - - policySlice, err := policies.ExtractPolicies(pages) - th.AssertNoErr(t, err) - th.AssertEquals(t, 2, len(policySlice)) -} - -func TestDeleteRequest(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - id := expectedResult().Id - th.Mux.HandleFunc(fmt.Sprintf("/l7policies/%s", id), func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "DELETE") - th.TestHeader(t, r, "X-Auth-Token", client.TokenID) - - w.Header().Add("Content-Type", "application/json") - w.WriteHeader(http.StatusNoContent) - }) - - th.AssertNoErr(t, policies.Delete(client.ServiceClient(), id)) -}