provider/openstack: gophercloud migration: lbaas v1
This commit is contained in:
parent
a1d76c8d07
commit
e2526002ff
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
)
|
||||
|
||||
func resourceLBMemberV1() *schema.Resource {
|
||||
|
@ -104,8 +104,9 @@ func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error {
|
|||
d.SetId(m.ID)
|
||||
|
||||
// Due to the way Gophercloud is currently set up, AdminStateUp must be set post-create
|
||||
asu := d.Get("admin_state_up").(bool)
|
||||
updateOpts := members.UpdateOpts{
|
||||
AdminStateUp: d.Get("admin_state_up").(bool),
|
||||
AdminStateUp: &asu,
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] OpenStack LB Member Update Options: %#v", createOpts)
|
||||
|
@ -150,7 +151,7 @@ func resourceLBMemberV1Update(d *schema.ResourceData, meta interface{}) error {
|
|||
var updateOpts members.UpdateOpts
|
||||
if d.HasChange("admin_state_up") {
|
||||
asu := d.Get("admin_state_up").(bool)
|
||||
updateOpts.AdminStateUp = asu
|
||||
updateOpts.AdminStateUp = &asu
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updating LB member %s with options: %+v", d.Id(), updateOpts)
|
||||
|
@ -215,7 +216,7 @@ func waitForLBMemberDelete(networkingClient *gophercloud.ServiceClient, memberId
|
|||
|
||||
m, err := members.Get(networkingClient, memberId).Extract()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return m, "ACTIVE", err
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
)
|
||||
|
||||
func TestAccLBV1Member_basic(t *testing.T) {
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
)
|
||||
|
||||
func resourceLBMonitorV1() *schema.Resource {
|
||||
|
@ -90,7 +90,6 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
createOpts := monitors.CreateOpts{
|
||||
TenantID: d.Get("tenant_id").(string),
|
||||
Type: d.Get("type").(string),
|
||||
Delay: d.Get("delay").(int),
|
||||
Timeout: d.Get("timeout").(int),
|
||||
MaxRetries: d.Get("max_retries").(int),
|
||||
|
@ -99,6 +98,11 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error {
|
|||
HTTPMethod: d.Get("http_method").(string),
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("type"); ok {
|
||||
monitorType := resourceLBMonitorV1DetermineType(v.(string))
|
||||
createOpts.Type = monitorType
|
||||
}
|
||||
|
||||
asuRaw := d.Get("admin_state_up").(string)
|
||||
if asuRaw != "" {
|
||||
asu, err := strconv.ParseBool(asuRaw)
|
||||
|
@ -225,6 +229,22 @@ func resourceLBMonitorV1Delete(d *schema.ResourceData, meta interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func resourceLBMonitorV1DetermineType(t string) monitors.MonitorType {
|
||||
var monitorType monitors.MonitorType
|
||||
switch t {
|
||||
case "PING":
|
||||
monitorType = monitors.TypePING
|
||||
case "TCP":
|
||||
monitorType = monitors.TypeTCP
|
||||
case "HTTP":
|
||||
monitorType = monitors.TypeHTTP
|
||||
case "HTTPS":
|
||||
monitorType = monitors.TypeHTTPS
|
||||
}
|
||||
|
||||
return monitorType
|
||||
}
|
||||
|
||||
func waitForLBMonitorActive(networkingClient *gophercloud.ServiceClient, monitorId string) resource.StateRefreshFunc {
|
||||
return func() (interface{}, string, error) {
|
||||
m, err := monitors.Get(networkingClient, monitorId).Extract()
|
||||
|
@ -244,7 +264,7 @@ func waitForLBMonitorDelete(networkingClient *gophercloud.ServiceClient, monitor
|
|||
|
||||
m, err := monitors.Get(networkingClient, monitorId).Extract()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return m, "ACTIVE", err
|
||||
}
|
||||
|
@ -261,7 +281,7 @@ func waitForLBMonitorDelete(networkingClient *gophercloud.ServiceClient, monitor
|
|||
log.Printf("[DEBUG] OpenStack LB Monitor: %+v", m)
|
||||
err = monitors.Delete(networkingClient, monitorId).ExtractErr()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return m, "ACTIVE", err
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
)
|
||||
|
||||
func TestAccLBV1Monitor_basic(t *testing.T) {
|
||||
|
|
|
@ -10,10 +10,10 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools"
|
||||
"github.com/rackspace/gophercloud/pagination"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools"
|
||||
"github.com/gophercloud/gophercloud/pagination"
|
||||
)
|
||||
|
||||
func resourceLBPoolV1() *schema.Resource {
|
||||
|
@ -122,13 +122,21 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
createOpts := pools.CreateOpts{
|
||||
Name: d.Get("name").(string),
|
||||
Protocol: d.Get("protocol").(string),
|
||||
SubnetID: d.Get("subnet_id").(string),
|
||||
LBMethod: d.Get("lb_method").(string),
|
||||
TenantID: d.Get("tenant_id").(string),
|
||||
Provider: d.Get("lb_provider").(string),
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("protocol"); ok {
|
||||
protocol := resourceLBPoolV1DetermineProtocol(v.(string))
|
||||
createOpts.Protocol = protocol
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("lb_method"); ok {
|
||||
lbMethod := resourceLBPoolV1DetermineLBMethod(v.(string))
|
||||
createOpts.LBMethod = lbMethod
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Create Options: %#v", createOpts)
|
||||
p, err := pools.Create(networkingClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
|
@ -213,7 +221,9 @@ func resourceLBPoolV1Update(d *schema.ResourceData, meta interface{}) error {
|
|||
// Gophercloud complains if one is empty.
|
||||
if d.HasChange("name") || d.HasChange("lb_method") {
|
||||
updateOpts.Name = d.Get("name").(string)
|
||||
updateOpts.LBMethod = d.Get("lb_method").(string)
|
||||
|
||||
lbMethod := resourceLBPoolV1DetermineLBMethod(d.Get("lb_method").(string))
|
||||
updateOpts.LBMethod = lbMethod
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updating OpenStack LB Pool %s with options: %+v", d.Id(), updateOpts)
|
||||
|
@ -379,6 +389,32 @@ func resourceLBMemberV1Hash(v interface{}) int {
|
|||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func resourceLBPoolV1DetermineProtocol(v string) pools.LBProtocol {
|
||||
var protocol pools.LBProtocol
|
||||
switch v {
|
||||
case "TCP":
|
||||
protocol = pools.ProtocolTCP
|
||||
case "HTTP":
|
||||
protocol = pools.ProtocolHTTP
|
||||
case "HTTPS":
|
||||
protocol = pools.ProtocolHTTPS
|
||||
}
|
||||
|
||||
return protocol
|
||||
}
|
||||
|
||||
func resourceLBPoolV1DetermineLBMethod(v string) pools.LBMethod {
|
||||
var lbMethod pools.LBMethod
|
||||
switch v {
|
||||
case "ROUND_ROBIN":
|
||||
lbMethod = pools.LBMethodRoundRobin
|
||||
case "LEAST_CONNECTIONS":
|
||||
lbMethod = pools.LBMethodLeastConnections
|
||||
}
|
||||
|
||||
return lbMethod
|
||||
}
|
||||
|
||||
func waitForLBPoolActive(networkingClient *gophercloud.ServiceClient, poolId string) resource.StateRefreshFunc {
|
||||
return func() (interface{}, string, error) {
|
||||
p, err := pools.Get(networkingClient, poolId).Extract()
|
||||
|
@ -401,7 +437,7 @@ func waitForLBPoolDelete(networkingClient *gophercloud.ServiceClient, poolId str
|
|||
|
||||
p, err := pools.Get(networkingClient, poolId).Extract()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return p, "ACTIVE", err
|
||||
}
|
||||
|
@ -414,7 +450,7 @@ func waitForLBPoolDelete(networkingClient *gophercloud.ServiceClient, poolId str
|
|||
log.Printf("[DEBUG] OpenStack LB Pool: %+v", p)
|
||||
err = pools.Delete(networkingClient, poolId).ExtractErr()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return p, "ACTIVE", err
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups"
|
||||
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/networks"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/subnets"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
||||
)
|
||||
|
||||
func TestAccLBV1Pool_basic(t *testing.T) {
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
)
|
||||
|
||||
func resourceLBVipV1() *schema.Resource {
|
||||
|
@ -207,20 +207,28 @@ func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
var updateOpts vips.UpdateOpts
|
||||
if d.HasChange("name") {
|
||||
updateOpts.Name = d.Get("name").(string)
|
||||
v := d.Get("name").(string)
|
||||
updateOpts.Name = &v
|
||||
}
|
||||
|
||||
if d.HasChange("pool_id") {
|
||||
updateOpts.PoolID = d.Get("pool_id").(string)
|
||||
v := d.Get("pool_id").(string)
|
||||
updateOpts.PoolID = &v
|
||||
}
|
||||
|
||||
if d.HasChange("description") {
|
||||
updateOpts.Description = d.Get("description").(string)
|
||||
v := d.Get("description").(string)
|
||||
updateOpts.Description = &v
|
||||
}
|
||||
|
||||
if d.HasChange("persistence") {
|
||||
updateOpts.Persistence = resourceVipPersistenceV1(d)
|
||||
}
|
||||
|
||||
if d.HasChange("conn_limit") {
|
||||
updateOpts.ConnLimit = gophercloud.MaybeInt(d.Get("conn_limit").(int))
|
||||
}
|
||||
|
||||
if d.HasChange("floating_ip") {
|
||||
portID := d.Get("port_id").(string)
|
||||
|
||||
|
@ -254,6 +262,7 @@ func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error {
|
|||
lbVipV1AssignFloatingIP(floatingIP, portID, networkingClient)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("admin_state_up") {
|
||||
asu := d.Get("admin_state_up").(bool)
|
||||
updateOpts.AdminStateUp = &asu
|
||||
|
@ -361,7 +370,7 @@ func waitForLBVIPDelete(networkingClient *gophercloud.ServiceClient, vipId strin
|
|||
|
||||
p, err := vips.Get(networkingClient, vipId).Extract()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return p, "ACTIVE", err
|
||||
}
|
||||
|
@ -374,7 +383,7 @@ func waitForLBVIPDelete(networkingClient *gophercloud.ServiceClient, vipId strin
|
|||
log.Printf("[DEBUG] OpenStack LB VIP: %+v", p)
|
||||
err = vips.Delete(networkingClient, vipId).ExtractErr()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return p, "ACTIVE", err
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips"
|
||||
)
|
||||
|
||||
func TestAccLBV1VIP_basic(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue