func testAccCheckLBV1MemberExists(t *testing.T, n string, member *members.Member) 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("(testAccCheckLBV1MemberExists) Error creating OpenStack networking client: %s", err)
		}

		found, err := members.Get(networkingClient, rs.Primary.ID).Extract()
		if err != nil {
			return err
		}

		if found.ID != rs.Primary.ID {
			return fmt.Errorf("Member not found")
		}

		*member = *found

		return nil
	}
}
Beispiel #2
0
func getMember(t *testing.T, memberID string) {
	m, err := members.Get(base.Client, memberID).Extract()

	th.AssertNoErr(t, err)

	t.Logf("Getting member ID [%s]", m.ID)
}
func waitForLBMemberActive(networkingClient *gophercloud.ServiceClient, memberId string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		m, err := members.Get(networkingClient, memberId).Extract()
		if err != nil {
			return nil, "", err
		}

		log.Printf("[DEBUG] OpenStack LB member: %+v", m)
		if m.Status == "ACTIVE" {
			return m, "ACTIVE", nil
		}

		return m, m.Status, nil
	}
}
func resourceLBMemberV1Read(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)
	}

	m, err := members.Get(networkingClient, d.Id()).Extract()
	if err != nil {
		return CheckDeleted(d, err, "LB member")
	}

	log.Printf("[DEBUG] Retreived OpenStack LB member %s: %+v", d.Id(), m)

	d.Set("weight", m.Weight)
	d.Set("admin_state_up", m.AdminStateUp)

	return nil
}
func testAccCheckLBV1MemberDestroy(s *terraform.State) error {
	config := testAccProvider.Meta().(*Config)
	networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
	if err != nil {
		return fmt.Errorf("(testAccCheckLBV1MemberDestroy) Error creating OpenStack networking client: %s", err)
	}

	for _, rs := range s.RootModule().Resources {
		if rs.Type != "openstack_lb_member_v1" {
			continue
		}

		_, err := members.Get(networkingClient, rs.Primary.ID).Extract()
		if err == nil {
			return fmt.Errorf("LB Member still exists")
		}
	}

	return nil
}
func waitForLBMemberDelete(networkingClient *gophercloud.ServiceClient, memberId string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		log.Printf("[DEBUG] Attempting to delete OpenStack LB member %s", memberId)

		m, err := members.Get(networkingClient, memberId).Extract()
		if err != nil {
			errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
			if !ok {
				return m, "ACTIVE", err
			}
			if errCode.Actual == 404 {
				log.Printf("[DEBUG] Successfully deleted OpenStack LB member %s", memberId)
				return m, "DELETED", nil
			}
		}

		log.Printf("[DEBUG] OpenStack LB member %s still active.", memberId)
		return m, "ACTIVE", nil
	}

}