func waitForFloatingIPDelete(networkingClient *gophercloud.ServiceClient, fId string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		log.Printf("[DEBUG] Attempting to delete OpenStack Floating IP %s.\n", fId)

		f, err := floatingips.Get(networkingClient, fId).Extract()
		if err != nil {
			if _, ok := err.(gophercloud.ErrDefault404); ok {
				log.Printf("[DEBUG] Successfully deleted OpenStack Floating IP %s", fId)
				return f, "DELETED", nil
			}
			return f, "ACTIVE", err
		}

		err = floatingips.Delete(networkingClient, fId).ExtractErr()
		if err != nil {
			if _, ok := err.(gophercloud.ErrDefault404); ok {
				log.Printf("[DEBUG] Successfully deleted OpenStack Floating IP %s", fId)
				return f, "DELETED", nil
			}
			return f, "ACTIVE", err
		}

		log.Printf("[DEBUG] OpenStack Floating IP %s still active.\n", fId)
		return f, "ACTIVE", nil
	}
}
Ejemplo n.º 2
0
// Unbind an port from external
func (os *OpenStack) UnbindPortFromExternal(portName string) error {
	port, err := os.GetPort(portName)
	if err != nil {
		glog.Errorf("get port failed: %v", err)
		return err
	}

	fip, err := os.getFloatingIPByPort(port.ID)
	if err != nil {
		glog.Errorf("get floatingip failed: %v", err)
		return err
	}

	if fip != nil {
		err = floatingips.Delete(os.network, fip.ID).ExtractErr()
		if err != nil {
			glog.Errorf("delete floatingip failed: %v", err)
			return err
		}
	}

	err = ports.Delete(os.network, port.ID).ExtractErr()
	if err != nil {
		glog.Errorf("delete port failed: %v", err)
		return err
	}

	return nil
}
Ejemplo n.º 3
0
// Bind an port to external network, return floatingip binded
func (os *OpenStack) BindPortToExternal(portName, tenantID string) (string, error) {
	port, err := os.GetPort(portName)
	if err != nil {
		glog.Errorf("Get openstack port failed: %v", err)
		return "", err
	}

	opts := floatingips.CreateOpts{
		FloatingNetworkID: os.ExtNetID,
		TenantID:          tenantID,
	}
	ip, err := floatingips.Create(os.network, opts).Extract()
	if err != nil {
		glog.Errorf("Create openstack flaotingip failed: %v", err)
		return "", err
	}

	floatOpts := floatingips.UpdateOpts{PortID: port.ID}
	_, err = floatingips.Update(os.network, ip.ID, floatOpts).Extract()
	if err != nil {
		glog.Errorf("Associate floatingip failed: %v", err)
		e := floatingips.Delete(os.network, ip.ID).ExtractErr()
		if e != nil {
			glog.Errorf("Delete floatingip error: %v", e)
		}
		return "", err
	}

	return ip.FloatingIP, nil
}
Ejemplo n.º 4
0
// DeleteFloatingIP deletes a floatingIP of a specified ID. A fatal error will
// occur if the deletion failed. This works best when used as a deferred
// function.
func DeleteFloatingIP(t *testing.T, client *gophercloud.ServiceClient, floatingIPID string) {
	t.Logf("Attempting to delete floating IP: %s", floatingIPID)

	err := floatingips.Delete(client, floatingIPID).ExtractErr()
	if err != nil {
		t.Fatalf("Failed to delete floating IP: %v", err)
	}

	t.Logf("Deleted floating IP: %s", floatingIPID)
}
Ejemplo n.º 5
0
func TestDelete(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/v2.0/floatingips/2f245a7b-796b-4f26-9cf9-9e82d248fda7", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		w.WriteHeader(http.StatusNoContent)
	})

	res := floatingips.Delete(fake.ServiceClient(), "2f245a7b-796b-4f26-9cf9-9e82d248fda7")
	th.AssertNoErr(t, res.Err)
}