Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions v2/ecl/managed_load_balancer/v1/load_balancers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ Example to perform system-update action on a load balancer
panic(err)
}

Example to perform system-update action with rollback on a load balancer

rollback := true
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
Rollback: &rollback,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NITS] doc.go の追記例の桁を揃える

修正しました

}
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 change-plan action on a load balancer

changePlan := load_balancers.ActionOptsChangePlan{
PlanID: "00713021-9aea-41da-9a88-87760c08fa72",
}
actionOpts := load_balancers.ActionOpts{
ChangePlan: &changePlan,
}

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{
Expand Down
28 changes: 27 additions & 1 deletion v2/ecl/managed_load_balancer/v1/load_balancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ type ActionOptsSystemUpdate struct {

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

// - Rollback the load balancer to the version prior to the specified system update
// - The target system update must allow rollback (is_rollback_allowed: true)
Rollback *bool `json:"rollback,omitempty"`
}

// ActionOptsChangePlan represents change-plan information in the load balancer action.
type ActionOptsChangePlan struct {

// - ID of the plan that the load balancer will be changed to
PlanID string `json:"plan_id"`
}

// ActionOpts represents options used to perform action on a existing load balancer.
Expand All @@ -331,6 +342,9 @@ type ActionOpts struct {

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

// - Change the plan of the load balancer
ChangePlan *ActionOptsChangePlan `json:"change-plan,omitempty"`
}

// ToLoadBalancerActionMap builds a request body from ActionOpts.
Expand All @@ -342,9 +356,21 @@ func (opts ActionOpts) ToLoadBalancerActionMap() map[string]interface{} {
}

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

if opts.SystemUpdate.Rollback != nil {
systemUpdateMap["rollback"] = *opts.SystemUpdate.Rollback
}

optsMap["system-update"] = systemUpdateMap
}

if opts.ChangePlan != nil {
optsMap["change-plan"] = map[string]interface{}{
"plan_id": opts.ChangePlan.PlanID,
}
}

return optsMap
Expand Down
15 changes: 15 additions & 0 deletions v2/ecl/managed_load_balancer/v1/load_balancers/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ var systemUpdateRequest = fmt.Sprintf(`
}
}`)

var systemUpdateWithRollbackRequest = fmt.Sprintf(`
{
"system-update": {
"system_update_id": "31746df7-92f9-4b5e-ad05-59f6684a54eb",
"rollback": true
}
}`)

var applyConfigurationsAndSystemUpdateRequest = fmt.Sprintf(`
{
"apply-configurations": null,
Expand All @@ -430,6 +438,13 @@ var applyConfigurationsAndSystemUpdateRequest = fmt.Sprintf(`
}
}`)

var changePlanRequest = fmt.Sprintf(`
{
"change-plan": {
"plan_id": "00713021-9aea-41da-9a88-87760c08fa72"
}
}`)

var cancelConfigurationsRequest = fmt.Sprintf(`
{
"cancel-configurations": null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,68 @@ func TestSystemUpdateLoadBalancer(t *testing.T) {
th.AssertNoErr(t, err)
}

func TestSystemUpdateWithRollbackLoadBalancer(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, systemUpdateWithRollbackRequest)

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

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

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

th.AssertNoErr(t, err)
}

func TestChangePlanLoadBalancer(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, changePlanRequest)

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

cli := ServiceClient()
changePlan := load_balancers.ActionOptsChangePlan{
PlanID: "00713021-9aea-41da-9a88-87760c08fa72",
}
actionOpts := load_balancers.ActionOpts{
ChangePlan: &changePlan,
}

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

th.AssertNoErr(t, err)
}

func TestApplyConfigurationsAndSystemUpdateLoadBalancer(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down
3 changes: 3 additions & 0 deletions v2/ecl/managed_load_balancer/v1/system_updates/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type ListOpts struct {
// - Whether the system update can be applied to the load balancer
Applicable bool `q:"applicable"`

// - Whether the system update allows rollback
IsRollbackAllowed bool `q:"is_rollback_allowed"`

// - If `true` is set, only the latest resource is displayed
Latest bool `q:"latest"`
}
Expand Down
3 changes: 3 additions & 0 deletions v2/ecl/managed_load_balancer/v1/system_updates/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type SystemUpdate struct {

// - Whether the system update can be applied to the load balancer
Applicable bool `json:"applicable"`

// - Whether the system update allows rollback
IsRollbackAllowed bool `json:"is_rollback_allowed"`
}

// ExtractInto interprets any commonResult as a system update, if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var listResponse = fmt.Sprintf(`
"limit_datetime": "2022-10-11 12:59:59",
"current_revision": 1,
"next_revision": 2,
"applicable": true
"applicable": true,
"is_rollback_allowed": true
}
]
}`)
Expand All @@ -37,6 +38,7 @@ func listResult() []system_updates.SystemUpdate {
systemUpdate1.CurrentRevision = 1
systemUpdate1.NextRevision = 2
systemUpdate1.Applicable = true
systemUpdate1.IsRollbackAllowed = true

return []system_updates.SystemUpdate{systemUpdate1}
}
Expand All @@ -52,7 +54,8 @@ var showResponse = fmt.Sprintf(`
"limit_datetime": "2022-10-11 12:59:59",
"current_revision": 1,
"next_revision": 2,
"applicable": true
"applicable": true,
"is_rollback_allowed": true
}
}`)

Expand All @@ -68,6 +71,7 @@ func showResult() *system_updates.SystemUpdate {
systemUpdate.CurrentRevision = 1
systemUpdate.NextRevision = 2
systemUpdate.Applicable = true
systemUpdate.IsRollbackAllowed = true

return &systemUpdate
}
32 changes: 32 additions & 0 deletions v3/ecl/managed_load_balancer/v1/load_balancers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ Example to perform system-update action on a load balancer
panic(err)
}

Example to perform system-update action with rollback on a load balancer

rollback := true
systemUpdate := load_balancers.ActionOptsSystemUpdate{
SystemUpdateID: "31746df7-92f9-4b5e-ad05-59f6684a54eb",
Rollback: &rollback,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NITS] doc.go の追記例の桁を揃える

修正しました

}
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 change-plan action on a load balancer

changePlan := load_balancers.ActionOptsChangePlan{
PlanID: "00713021-9aea-41da-9a88-87760c08fa72",
}
actionOpts := load_balancers.ActionOpts{
ChangePlan: &changePlan,
}

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{
Expand Down
28 changes: 27 additions & 1 deletion v3/ecl/managed_load_balancer/v1/load_balancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ type ActionOptsSystemUpdate struct {

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

// - Rollback the load balancer to the version prior to the specified system update
// - The target system update must allow rollback (is_rollback_allowed: true)
Rollback *bool `json:"rollback,omitempty"`
}

// ActionOptsChangePlan represents change-plan information in the load balancer action.
type ActionOptsChangePlan struct {

// - ID of the plan that the load balancer will be changed to
PlanID string `json:"plan_id"`
}

// ActionOpts represents options used to perform action on a existing load balancer.
Expand All @@ -331,6 +342,9 @@ type ActionOpts struct {

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

// - Change the plan of the load balancer
ChangePlan *ActionOptsChangePlan `json:"change-plan,omitempty"`
}

// ToLoadBalancerActionMap builds a request body from ActionOpts.
Expand All @@ -342,9 +356,21 @@ func (opts ActionOpts) ToLoadBalancerActionMap() map[string]interface{} {
}

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

if opts.SystemUpdate.Rollback != nil {
systemUpdateMap["rollback"] = *opts.SystemUpdate.Rollback
}

optsMap["system-update"] = systemUpdateMap
}

if opts.ChangePlan != nil {
optsMap["change-plan"] = map[string]interface{}{
"plan_id": opts.ChangePlan.PlanID,
}
}

return optsMap
Expand Down
15 changes: 15 additions & 0 deletions v3/ecl/managed_load_balancer/v1/load_balancers/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ var systemUpdateRequest = fmt.Sprintf(`
}
}`)

var systemUpdateWithRollbackRequest = fmt.Sprintf(`
{
"system-update": {
"system_update_id": "31746df7-92f9-4b5e-ad05-59f6684a54eb",
"rollback": true
}
}`)

var applyConfigurationsAndSystemUpdateRequest = fmt.Sprintf(`
{
"apply-configurations": null,
Expand All @@ -430,6 +438,13 @@ var applyConfigurationsAndSystemUpdateRequest = fmt.Sprintf(`
}
}`)

var changePlanRequest = fmt.Sprintf(`
{
"change-plan": {
"plan_id": "00713021-9aea-41da-9a88-87760c08fa72"
}
}`)

var cancelConfigurationsRequest = fmt.Sprintf(`
{
"cancel-configurations": null
Expand Down
Loading
Loading