Skip to content

Commit

Permalink
add loadbalancer additional vips feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic Lamarche committed Jul 19, 2023
1 parent 7137f08 commit ec22e01
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions openstack/loadbalancer/v2/loadbalancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ type CreateOpts struct {

// Tags is a set of resource tags.
Tags []string `json:"tags,omitempty"`

// The additional ips of the loadbalancer. Subnets must all belong to the same network as the primary VIP.
// New in version 2.26
AdditionalVIps []AdditionalVip `json:"additional_vips,omitempty"`
}

// ToLoadBalancerCreateMap builds a request body from CreateOpts.
Expand Down
10 changes: 10 additions & 0 deletions openstack/loadbalancer/v2/loadbalancers/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ type LoadBalancer struct {
// Tags is a list of resource tags. Tags are arbitrarily defined strings
// attached to the resource.
Tags []string `json:"tags"`

// The additional ips of the loadbalancer. Subnets must all belong to the same network as the primary VIP.
// New in version 2.26
AdditionalVIps []AdditionalVip `json:"additional_vips"`
}

// AdditionalVip represent additional ip of a loadbalancer. IpAddress field is optional.
type AdditionalVip struct {
SubnetID string `json:"subnet_id"`
IPAddress string `json:"ip_address,omitempty"`
}

func (r *LoadBalancer) UnmarshalJSON(b []byte) error {
Expand Down
18 changes: 13 additions & 5 deletions openstack/loadbalancer/v2/loadbalancers/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
const LoadbalancersListBody = `
{
"loadbalancers":[
{
{
"id": "c331058c-6a40-4144-948e-b9fb1df9db4b",
"project_id": "54030507-44f7-473c-9342-b4d14a95f692",
"created_at": "2019-06-30T04:15:37",
Expand Down Expand Up @@ -52,7 +52,8 @@ const LoadbalancersListBody = `
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE",
"tags": ["test", "stage"]
"tags": ["test", "stage"],
"additional_vips": [{"subnet_id": "0d4f6a08-60b7-44ab-8903-f7d76ec54095", "ip_address" : "192.168.10.10"}]
}
]
}
Expand All @@ -77,7 +78,8 @@ const SingleLoadbalancerBody = `
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE",
"tags": ["test", "stage"]
"tags": ["test", "stage"],
"additional_vips": [{"subnet_id": "0d4f6a08-60b7-44ab-8903-f7d76ec54095", "ip_address" : "192.168.10.10"}]
}
}
`
Expand Down Expand Up @@ -287,7 +289,12 @@ var (
ProvisioningStatus: "PENDING_CREATE",
OperatingStatus: "OFFLINE",
Tags: []string{"test", "stage"},
}
AdditionalVIps: []loadbalancers.AdditionalVip{
{
SubnetID: "0d4f6a08-60b7-44ab-8903-f7d76ec54095",
IPAddress: "192.168.10.10",
},
}}
LoadbalancerUpdated = loadbalancers.LoadBalancer{
ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
ProjectID: "54030507-44f7-473c-9342-b4d14a95f692",
Expand Down Expand Up @@ -540,7 +547,8 @@ func HandleLoadbalancerCreationSuccessfully(t *testing.T, response string) {
"flavor_id": "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4",
"provider": "haproxy",
"admin_state_up": true,
"tags": ["test", "stage"]
"tags": ["test", "stage"],
"additional_vips": [{"subnet_id": "0d4f6a08-60b7-44ab-8903-f7d76ec54095", "ip_address" : "192.168.10.10"}]
}
}`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func TestCreateLoadbalancer(t *testing.T) {
FlavorID: "bba40eb2-ee8c-11e9-81b4-2a2ae2dbcce4",
Provider: "haproxy",
Tags: []string{"test", "stage"},
AdditionalVIps: []loadbalancers.AdditionalVip{
{
SubnetID: "0d4f6a08-60b7-44ab-8903-f7d76ec54095",
IPAddress: "192.168.10.10",
},
},
}).Extract()
th.AssertNoErr(t, err)

Expand Down

0 comments on commit ec22e01

Please sign in to comment.