Skip to content

Commit

Permalink
Fix Action in ecl/managed_load_balancer/v1/load_balancers/requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hico-horiuchi committed May 10, 2024
1 parent 2106209 commit 7487058
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 58 deletions.
29 changes: 26 additions & 3 deletions v2/ecl/managed_load_balancer/v1/load_balancers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,43 @@ Example to delete a load balancer
Example to perform apply-configurations action on a load balancer
actionOpts := load_balancers.ActionOpts{
ApplyConfigurations: true,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := load_balancers.ApplyConfigurations(managedLoadBalancerClient, id).ExtractErr()
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()
if err != nil {
panic(err)
}
Example to perform system-update action on a load balancer
systemUpdateOpts := load_balancers.SystemUpdateOpts{
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
}
actionOpts := load_balancers.ActionOpts{
SystemUpdate: &systemUpdate,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()
if err != nil {
panic(err)
}
Example to perform apply-configurations and system-update action on a load balancer
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
}
actionOpts := load_balancers.ActionOpts{
ApplyConfigurations: true,
SystemUpdate: &systemUpdate,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := load_balancers.SystemUpdate(managedLoadBalancerClient, id, systemUpdateOpts).ExtractErr()
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()
if err != nil {
panic(err)
}
Expand Down
52 changes: 32 additions & 20 deletions v2/ecl/managed_load_balancer/v1/load_balancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,36 +299,48 @@ func Delete(c *eclcloud.ServiceClient, id string) (r DeleteResult) {
Action Load Balancer
*/

// ApplyConfigurations performs action on a existing load balancer.
func ApplyConfigurations(c *eclcloud.ServiceClient, id string) (r ActionResult) {
b := map[string]interface{}{"apply-configurations": nil}
_, r.Err = c.Post(actionURL(c, id), b, nil, &eclcloud.RequestOpts{
OkCodes: []int{204},
})
// ActionOptsSystemUpdate represents system-update information in the load balancer action.
type ActionOptsSystemUpdate struct {

return
// - ID of the system update that will be applied to the load balancer
SystemUpdateID string `json:"system_update_id"`
}

// SystemUpdateOpts represents options used to perform action on a existing load balancer.
type SystemUpdateOpts struct {
// ActionOpts represents options used to perform action on a existing load balancer.
type ActionOpts struct {

// - ID of the system update that will be applied to the load balancer
SystemUpdateID string `json:"system_update_id"`
// - Added or changed configurations of the load balancer and related resources will be applied
ApplyConfigurations bool `json:"apply-configurations,omitempty"`

// - Apply the system update to the load balancer
SystemUpdate *ActionOptsSystemUpdate `json:"system-update,omitempty"`
}

// ToLoadBalancerSystemUpdateMap builds a request body from SystemUpdateOpts.
func (opts SystemUpdateOpts) ToLoadBalancerSystemUpdateMap() (map[string]interface{}, error) {
return eclcloud.BuildRequestBody(opts, "system-update")
// ToLoadBalancerActionMap builds a request body from ActionOpts.
func (opts ActionOpts) ToLoadBalancerActionMap() (map[string]interface{}, error) {
optsMap := make(map[string]interface{})

if opts.ApplyConfigurations {
optsMap["apply-configurations"] = nil
}

if opts.SystemUpdate != nil {
optsMap["system-update"] = map[string]interface{}{
"system_update_id": opts.SystemUpdate.SystemUpdateID,
}
}

return optsMap, nil
}

// SystemUpdateOptsBuilder allows extensions to add additional parameters to the SystemUpdate request.
type SystemUpdateOptsBuilder interface {
ToLoadBalancerSystemUpdateMap() (map[string]interface{}, error)
// ActionOptsBuilder allows extensions to add additional parameters to the Action request.
type ActionOptsBuilder interface {
ToLoadBalancerActionMap() (map[string]interface{}, error)
}

// SystemUpdate accepts a SystemUpdateOpts struct and performs action on a existing load balancer using the values provided.
func SystemUpdate(c *eclcloud.ServiceClient, id string, opts SystemUpdateOptsBuilder) (r ActionResult) {
b, err := opts.ToLoadBalancerSystemUpdateMap()
// Action accepts a ActionOpts struct and performs action on a existing load balancer using the values provided.
func Action(c *eclcloud.ServiceClient, id string, opts ActionOptsBuilder) (r ActionResult) {
b, err := opts.ToLoadBalancerActionMap()
if err != nil {
r.Err = err

Expand Down
14 changes: 11 additions & 3 deletions v2/ecl/managed_load_balancer/v1/load_balancers/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,26 @@ var applyConfigurationsRequest = fmt.Sprintf(`
"apply-configurations": null
}`)

var cancelConfigurationsRequest = fmt.Sprintf(`
var systemUpdateRequest = fmt.Sprintf(`
{
"cancel-configurations": null
"system-update": {
"system_update_id": "31746df7-92f9-4b5e-ad05-59f6684a54eb"
}
}`)

var systemUpdateRequest = fmt.Sprintf(`
var applyConfigurationsAndSystemUpdateRequest = fmt.Sprintf(`
{
"apply-configurations": null,
"system-update": {
"system_update_id": "31746df7-92f9-4b5e-ad05-59f6684a54eb"
}
}`)

var cancelConfigurationsRequest = fmt.Sprintf(`
{
"cancel-configurations": null
}`)

var createStagedRequest = fmt.Sprintf(`
{
"load_balancer": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ func TestApplyConfigurationsLoadBalancer(t *testing.T) {
})

cli := ServiceClient()
err := load_balancers.ApplyConfigurations(cli, id).ExtractErr()
actionOpts := load_balancers.ActionOpts{
ApplyConfigurations: true,
}
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()

th.AssertNoErr(t, err)
}
Expand All @@ -253,11 +256,45 @@ func TestSystemUpdateLoadBalancer(t *testing.T) {
})

cli := ServiceClient()
systemUpdateOpts := load_balancers.SystemUpdateOpts{
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
}
actionOpts := load_balancers.ActionOpts{
SystemUpdate: &systemUpdate,
}

err := load_balancers.Action(cli, id, actionOpts).ExtractErr()

th.AssertNoErr(t, err)
}

func TestApplyConfigurationsAndSystemUpdateLoadBalancer(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()

th.Mux.HandleFunc(
fmt.Sprintf("/v1.0/load_balancers/%s/action", id),
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", TokenID)
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestHeader(t, r, "Accept", "application/json")
th.TestJSONRequest(t, r, applyConfigurationsAndSystemUpdateRequest)

w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusNoContent)
})

cli := ServiceClient()
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
}
actionOpts := load_balancers.ActionOpts{
ApplyConfigurations: true,
SystemUpdate: &systemUpdate,
}

err := load_balancers.SystemUpdate(cli, id, systemUpdateOpts).ExtractErr()
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()

th.AssertNoErr(t, err)
}
Expand Down
29 changes: 26 additions & 3 deletions v3/ecl/managed_load_balancer/v1/load_balancers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,43 @@ Example to delete a load balancer
Example to perform apply-configurations action on a load balancer
actionOpts := load_balancers.ActionOpts{
ApplyConfigurations: true,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := load_balancers.ApplyConfigurations(managedLoadBalancerClient, id).ExtractErr()
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()
if err != nil {
panic(err)
}
Example to perform system-update action on a load balancer
systemUpdateOpts := load_balancers.SystemUpdateOpts{
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
}
actionOpts := load_balancers.ActionOpts{
SystemUpdate: &systemUpdate,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()
if err != nil {
panic(err)
}
Example to perform apply-configurations and system-update action on a load balancer
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
}
actionOpts := load_balancers.ActionOpts{
ApplyConfigurations: true,
SystemUpdate: &systemUpdate,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := load_balancers.SystemUpdate(managedLoadBalancerClient, id, systemUpdateOpts).ExtractErr()
err := load_balancers.Action(cli, id, actionOpts).ExtractErr()
if err != nil {
panic(err)
}
Expand Down
52 changes: 32 additions & 20 deletions v3/ecl/managed_load_balancer/v1/load_balancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,36 +299,48 @@ func Delete(c *eclcloud.ServiceClient, id string) (r DeleteResult) {
Action Load Balancer
*/

// ApplyConfigurations performs action on a existing load balancer.
func ApplyConfigurations(c *eclcloud.ServiceClient, id string) (r ActionResult) {
b := map[string]interface{}{"apply-configurations": nil}
_, r.Err = c.Post(actionURL(c, id), b, nil, &eclcloud.RequestOpts{
OkCodes: []int{204},
})
// ActionOptsSystemUpdate represents system-update information in the load balancer action.
type ActionOptsSystemUpdate struct {

return
// - ID of the system update that will be applied to the load balancer
SystemUpdateID string `json:"system_update_id"`
}

// SystemUpdateOpts represents options used to perform action on a existing load balancer.
type SystemUpdateOpts struct {
// ActionOpts represents options used to perform action on a existing load balancer.
type ActionOpts struct {

// - ID of the system update that will be applied to the load balancer
SystemUpdateID string `json:"system_update_id"`
// - Added or changed configurations of the load balancer and related resources will be applied
ApplyConfigurations bool `json:"apply-configurations,omitempty"`

// - Apply the system update to the load balancer
SystemUpdate *ActionOptsSystemUpdate `json:"system-update,omitempty"`
}

// ToLoadBalancerSystemUpdateMap builds a request body from SystemUpdateOpts.
func (opts SystemUpdateOpts) ToLoadBalancerSystemUpdateMap() (map[string]interface{}, error) {
return eclcloud.BuildRequestBody(opts, "system-update")
// ToLoadBalancerActionMap builds a request body from ActionOpts.
func (opts ActionOpts) ToLoadBalancerActionMap() (map[string]interface{}, error) {
optsMap := make(map[string]interface{})

if opts.ApplyConfigurations {
optsMap["apply-configurations"] = nil
}

if opts.SystemUpdate != nil {
optsMap["system-update"] = map[string]interface{}{
"system_update_id": opts.SystemUpdate.SystemUpdateID,
}
}

return optsMap, nil
}

// SystemUpdateOptsBuilder allows extensions to add additional parameters to the SystemUpdate request.
type SystemUpdateOptsBuilder interface {
ToLoadBalancerSystemUpdateMap() (map[string]interface{}, error)
// ActionOptsBuilder allows extensions to add additional parameters to the Action request.
type ActionOptsBuilder interface {
ToLoadBalancerActionMap() (map[string]interface{}, error)
}

// SystemUpdate accepts a SystemUpdateOpts struct and performs action on a existing load balancer using the values provided.
func SystemUpdate(c *eclcloud.ServiceClient, id string, opts SystemUpdateOptsBuilder) (r ActionResult) {
b, err := opts.ToLoadBalancerSystemUpdateMap()
// Action accepts a ActionOpts struct and performs action on a existing load balancer using the values provided.
func Action(c *eclcloud.ServiceClient, id string, opts ActionOptsBuilder) (r ActionResult) {
b, err := opts.ToLoadBalancerActionMap()
if err != nil {
r.Err = err

Expand Down
14 changes: 11 additions & 3 deletions v3/ecl/managed_load_balancer/v1/load_balancers/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,26 @@ var applyConfigurationsRequest = fmt.Sprintf(`
"apply-configurations": null
}`)

var cancelConfigurationsRequest = fmt.Sprintf(`
var systemUpdateRequest = fmt.Sprintf(`
{
"cancel-configurations": null
"system-update": {
"system_update_id": "31746df7-92f9-4b5e-ad05-59f6684a54eb"
}
}`)

var systemUpdateRequest = fmt.Sprintf(`
var applyConfigurationsAndSystemUpdateRequest = fmt.Sprintf(`
{
"apply-configurations": null,
"system-update": {
"system_update_id": "31746df7-92f9-4b5e-ad05-59f6684a54eb"
}
}`)

var cancelConfigurationsRequest = fmt.Sprintf(`
{
"cancel-configurations": null
}`)

var createStagedRequest = fmt.Sprintf(`
{
"load_balancer": {
Expand Down
Loading

0 comments on commit 7487058

Please sign in to comment.