func waitForLoadBalancerDelete(networkingClient *gophercloud.ServiceClient, lbID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { log.Printf("[DEBUG] Attempting to delete OpenStack LoadBalancerV2 %s", lbID) lb, err := loadbalancers.Get(networkingClient, lbID).Extract() if err != nil { errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError) if !ok { return lb, "ACTIVE", err } if errCode.Actual == 404 { log.Printf("[DEBUG] Successfully deleted OpenStack LoadBalancerV2 %s", lbID) return lb, "DELETED", nil } } log.Printf("[DEBUG] Openstack LoadBalancerV2: %+v", lb) err = loadbalancers.Delete(networkingClient, lbID).ExtractErr() if err != nil { errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError) if !ok { return lb, "ACTIVE", err } if errCode.Actual == 404 { log.Printf("[DEBUG] Successfully deleted OpenStack LoadBalancerV2 %s", lbID) return lb, "DELETED", nil } } log.Printf("[DEBUG] OpenStack LoadBalancerV2 %s still active.", lbID) return lb, "ACTIVE", nil } }
func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) networkingClient, err := config.networkingV2Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack networking client: %s", err) } lb, err := loadbalancers.Get(networkingClient, d.Id()).Extract() if err != nil { return CheckDeleted(d, err, "LoadBalancerV2") } log.Printf("[DEBUG] Retreived OpenStack LoadBalancerV2 %s: %+v", d.Id(), lb) d.Set("name", lb.Name) d.Set("description", lb.Description) d.Set("vip_subnet_id", lb.VipSubnetID) d.Set("tenant_id", lb.TenantID) d.Set("vip_address", lb.VipAddress) d.Set("admin_state_up", lb.AdminStateUp) d.Set("flavor", lb.Flavor) d.Set("provider", lb.Provider) return nil }
func testAccCheckLBV2LoadBalancerExists(t *testing.T, n string, lb *loadbalancers.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } if rs.Primary.ID == "" { return fmt.Errorf("No ID is set") } config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { return fmt.Errorf("(testAccCheckLBV2LoadBalancerExists) Error creating OpenStack networking client: %s", err) } found, err := loadbalancers.Get(networkingClient, rs.Primary.ID).Extract() if err != nil { return err } if found.ID != rs.Primary.ID { return fmt.Errorf("Member not found") } *lb = *found return nil } }
func waitForLoadBalancerActive(networkingClient *gophercloud.ServiceClient, lbID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { lb, err := loadbalancers.Get(networkingClient, lbID).Extract() if err != nil { return nil, "", err } log.Printf("[DEBUG] OpenStack LoadBalancer: %+v", lb) if lb.ProvisioningStatus == "ACTIVE" { return lb, "ACTIVE", nil } return lb, lb.ProvisioningStatus, nil } }
func getLoadbalancerWaitActive(t *testing.T, loadbalancerID string) { start := time.Now().Second() for { time.Sleep(1 * time.Second) if time.Now().Second()-start >= loadbalancerActiveTimeoutSeconds { t.Errorf("Loadbalancer failed to go into ACTIVE provisioning status") return } loadbalancer, err := loadbalancers.Get(base.Client, loadbalancerID).Extract() th.AssertNoErr(t, err) if loadbalancer.ProvisioningStatus == "ACTIVE" { t.Logf("Retrieved Loadbalancer, ID [%s]: OperatingStatus [%s]", loadbalancer.ID, loadbalancer.ProvisioningStatus) return } } }
func waitLoadbalancerActiveProvisioningStatus(client *gophercloud.ServiceClient, loadbalancerID string) error { start := time.Now().Second() for { loadbalancer, err := loadbalancers.Get(client, loadbalancerID).Extract() if err != nil { return err } if loadbalancer.ProvisioningStatus == "ACTIVE" { return nil } time.Sleep(1 * time.Second) if time.Now().Second()-start >= loadbalancerActiveTimeoutSeconds { return fmt.Errorf("Loadbalancer failed to go into ACTIVE provisioning status within alloted time") } } }
func waitLoadbalancerDeleted(client *gophercloud.ServiceClient, loadbalancerID string) error { start := time.Now().Second() for { _, err := loadbalancers.Get(client, loadbalancerID).Extract() if err != nil { if err == ErrNotFound { return nil } else { return err } } time.Sleep(1 * time.Second) if time.Now().Second()-start >= loadbalancerDeleteTimeoutSeconds { return fmt.Errorf("Loadbalancer failed to delete within the alloted time") } } }
func getLoadbalancerWaitDeleted(t *testing.T, loadbalancerID string) { start := time.Now().Second() for { time.Sleep(1 * time.Second) if time.Now().Second()-start >= loadbalancerDeleteTimeoutSeconds { t.Errorf("Loadbalancer failed to delete") return } _, err := loadbalancers.Get(base.Client, loadbalancerID).Extract() if err != nil { if errData, ok := err.(*(gophercloud.UnexpectedResponseCodeError)); ok { if errData.Actual == 404 { return } } else { th.AssertNoErr(t, err) } } } }
func testAccCheckLBV2LoadBalancerDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { return fmt.Errorf("(testAccCheckLBV2LoadBalancerDestroy) Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { log.Printf("[FINDME] rs TYPE is: %#v", rs.Type) if rs.Type != "openstack_lb_loadbalancer_v2" { continue } _, err := loadbalancers.Get(networkingClient, rs.Primary.ID).Extract() if err == nil { return fmt.Errorf("LoadBalancer still exists: %s", rs.Primary.ID) } } return nil }