func getPool(t *testing.T, poolID string) { pool, err := pools.Get(base.Client, poolID).Extract() th.AssertNoErr(t, err) t.Logf("Getting Pool, ID [%s]: ", pool.ID) }
func waitForPoolDelete(networkingClient *gophercloud.ServiceClient, poolID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { log.Printf("[DEBUG] Attempting to delete OpenStack LBaaSV2 Pool %s", poolID) pool, err := pools.Get(networkingClient, poolID).Extract() if err != nil { errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError) if !ok { return pool, "ACTIVE", err } if errCode.Actual == 404 { log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Pool %s", poolID) return pool, "DELETED", nil } } log.Printf("[DEBUG] Openstack LBaaSV2 Pool: %+v", pool) err = pools.Delete(networkingClient, poolID).ExtractErr() if err != nil { errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError) if !ok { return pool, "ACTIVE", err } if errCode.Actual == 404 { log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Pool %s", poolID) return pool, "DELETED", nil } } log.Printf("[DEBUG] OpenStack LBaaSV2 Pool %s still active.", poolID) return pool, "ACTIVE", nil } }
func resourcePoolV2Read(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) } pool, err := pools.Get(networkingClient, d.Id()).Extract() if err != nil { return CheckDeleted(d, err, "LBV2 Pool") } log.Printf("[DEBUG] Retreived OpenStack LBaaSV2 Pool %s: %+v", d.Id(), pool) d.Set("lb_method", pool.LBMethod) d.Set("protocol", pool.Protocol) d.Set("description", pool.Description) d.Set("tenant_id", pool.TenantID) d.Set("admin_state_up", pool.AdminStateUp) d.Set("name", pool.Name) d.Set("id", pool.ID) d.Set("persistence", pool.Persistence) return nil }
func testAccCheckLBV2PoolExists(t *testing.T, n string, pool *pools.Pool) 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("(testAccCheckLBV2PoolExists) Error creating OpenStack networking client: %s", err) } found, err := pools.Get(networkingClient, rs.Primary.ID).Extract() if err != nil { return err } if found.ID != rs.Primary.ID { return fmt.Errorf("Member not found") } *pool = *found return nil } }
func waitForPoolActive(networkingClient *gophercloud.ServiceClient, poolID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { pool, err := pools.Get(networkingClient, poolID).Extract() if err != nil { return nil, "", err } // The pool resource has no Status attribute, so a successful Get is the best we can do log.Printf("[DEBUG] OpenStack LBaaSV2 Pool: %+v", pool) return pool, "ACTIVE", nil } }
func testAccCheckLBV2PoolDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { return fmt.Errorf("(testAccCheckLBV2PoolDestroy) Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { log.Printf("[FINDME] rs TYPE is: %T", rs) if rs.Type != "openstack_lb_pool_v2" { continue } _, err := pools.Get(networkingClient, rs.Primary.ID).Extract() if err == nil { return fmt.Errorf("Pool still exists: %s", rs.Primary.ID) } } return nil }