provider/openstack: gophercloud migration: updating error responses

This commit is contained in:
Joe Topjian 2016-09-04 04:57:25 +00:00
parent 9ffef951c5
commit c11a4ef214
31 changed files with 133 additions and 298 deletions

View File

@ -306,11 +306,7 @@ func VolumeV1StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string
return func() (interface{}, string, error) {
v, err := volumes.Get(client, volumeID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return nil, "", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return v, "deleted", nil
}
return nil, "", err

View File

@ -117,13 +117,10 @@ func testAccCheckBlockStorageV1VolumeDoesNotExist(t *testing.T, n string, volume
_, err = volumes.Get(blockStorageClient, volume.ID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return nil
}
return err
}

View File

@ -318,11 +318,7 @@ func VolumeV2StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string
return func() (interface{}, string, error) {
v, err := volumes.Get(client, volumeID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return nil, "", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return v, "deleted", nil
}
return nil, "", err

View File

@ -130,11 +130,7 @@ func testAccCheckBlockStorageV2VolumeDoesNotExist(t *testing.T, n string, volume
_, err = volumes.Get(blockStorageClient, volume.ID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return nil
}
return err

View File

@ -617,15 +617,11 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
for _, g := range secgroupsToRemove.List() {
err := secgroups.RemoveServer(computeClient, d.Id(), g.(string)).ExtractErr()
if err != nil && err.Error() != "EOF" {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error removing security group (%s) from OpenStack server (%s): %s", g, d.Id(), err)
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
continue
} else {
return fmt.Errorf("Error removing security group (%s) from OpenStack server (%s): %s", g, d.Id(), err)
}
return fmt.Errorf("Error removing security group (%s) from OpenStack server (%s): %s", g, d.Id(), err)
} else {
log.Printf("[DEBUG] Removed security group (%s) from instance (%s)", g, d.Id())
}
@ -875,11 +871,7 @@ func ServerV2StateRefreshFunc(client *gophercloud.ServiceClient, instanceID stri
return func() (interface{}, string, error) {
s, err := servers.Get(client, instanceID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return nil, "", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return s, "DELETED", nil
}
return nil, "", err
@ -972,16 +964,19 @@ func getInstanceNetworks(computeClient *gophercloud.ServiceClient, d *schema.Res
allPages, err := tenantnetworks.List(computeClient).AllPages()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
if _, ok := err.(gophercloud.ErrDefault404); ok {
tenantNetworkExt = false
}
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
if errCode.Actual == 403 {
tenantNetworkExt = false
}
return nil, err
}
if errCode.Actual == 404 || errCode.Actual == 403 {
tenantNetworkExt = false
} else {
return nil, err
}
return nil, err
}
networkID := ""
@ -1290,19 +1285,14 @@ func setImageInformation(computeClient *gophercloud.ServiceClient, server *serve
if imageId != "" {
d.Set("image_id", imageId)
if image, err := images.Get(computeClient, imageId).Extract(); err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
// If the image name can't be found, set the value to "Image not found".
// The most likely scenario is that the image no longer exists in the Image Service
// but the instance still has a record from when it existed.
d.Set("image_name", "Image not found")
return nil
} else {
return err
}
return err
} else {
d.Set("image_name", image.Name)
}

View File

@ -1098,11 +1098,7 @@ func testAccCheckComputeV2InstanceDoesNotExist(t *testing.T, n string, instance
_, err = servers.Get(computeClient, instance.ID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return nil
}
return err

View File

@ -197,15 +197,11 @@ func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) e
rule := resourceSecGroupRuleV2(d, r)
err := secgroups.DeleteRule(computeClient, rule.ID).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error removing rule (%s) from OpenStack security group (%s): %s", rule.ID, d.Id(), err)
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
continue
} else {
return fmt.Errorf("Error removing rule (%s) from OpenStack security group (%s)", rule.ID, d.Id())
}
return fmt.Errorf("Error removing rule (%s) from OpenStack security group (%s)", rule.ID, d.Id())
} else {
log.Printf("[DEBUG] Removed rule (%s) from OpenStack security group (%s): %s", rule.ID, d.Id(), err)
}

View File

@ -231,14 +231,11 @@ func waitForFirewallDeletion(networkingClient *gophercloud.ServiceClient, id str
log.Printf("[DEBUG] Get firewall %s => %#v", id, fw)
if err != nil {
httpStatus := err.(*gophercloud.ErrUnexpectedResponseCode)
log.Printf("[DEBUG] Get firewall %s status is %d", id, httpStatus.Actual)
if httpStatus.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Firewall %s is actually deleted", id)
return "", "DELETED", nil
}
return nil, "", fmt.Errorf("Unexpected status code %d", httpStatus.Actual)
return nil, "", fmt.Errorf("Unexpected error: %s", err)
}
log.Printf("[DEBUG] Firewall %s deletion is pending", id)

View File

@ -47,13 +47,13 @@ func testAccCheckFWFirewallV1Destroy(s *terraform.State) error {
if rs.Type != "openstack_firewall" {
continue
}
_, err = firewalls.Get(networkingClient, rs.Primary.ID).Extract()
if err == nil {
return fmt.Errorf("Firewall (%s) still exists.", rs.Primary.ID)
}
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 404 {
return httpError
if _, ok := err.(gophercloud.ErrDefault404); !ok {
return err
}
}
return nil
@ -84,19 +84,15 @@ func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string,
// if we get a 404 error. Fail on any other error.
found, err = firewalls.Get(networkingClient, rs.Primary.ID).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
time.Sleep(time.Second)
continue
}
return err
}
break
}
if err != nil {
return err
}
if found.Name != expectedName {
return fmt.Errorf("Expected Name to be <%s> but found <%s>", expectedName, found.Name)
}

View File

@ -186,8 +186,7 @@ func resourceFWPolicyV1Delete(d *schema.ResourceData, meta interface{}) error {
break
}
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 409 {
if _, ok := err.(gophercloud.ErrDefault404); !ok {
return err
}

View File

@ -80,9 +80,8 @@ func testAccCheckFWPolicyV1Destroy(s *terraform.State) error {
if err == nil {
return fmt.Errorf("Firewall policy (%s) still exists.", rs.Primary.ID)
}
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 404 {
return httpError
if _, ok := err.(gophercloud.ErrDefault404); !ok {
return err
}
}
return nil
@ -113,19 +112,15 @@ func testAccCheckFWPolicyV1Exists(n, name, description string, ruleCount int) re
// if we get a 404 error. Fail on any other error.
found, err = policies.Get(networkingClient, rs.Primary.ID).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
time.Sleep(time.Second)
continue
}
return err
}
break
}
if err != nil {
return err
}
if name != found.Name {
return fmt.Errorf("Expected name <%s>, but found <%s>", name, found.Name)
}

View File

@ -88,9 +88,8 @@ func testAccCheckFWRuleV1Destroy(s *terraform.State) error {
if err == nil {
return fmt.Errorf("Firewall rule (%s) still exists.", rs.Primary.ID)
}
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 404 {
return httpError
if _, ok := err.(gophercloud.ErrDefault404); !ok {
return err
}
}
return nil
@ -121,19 +120,15 @@ func testAccCheckFWRuleV1Exists(n string, expected *rules.Rule) resource.TestChe
// if we get a 404 error. Fail on any other error.
found, err = rules.Get(networkingClient, rs.Primary.ID).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok || httpError.Actual != 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
time.Sleep(time.Second)
continue
}
return err
}
break
}
if err != nil {
return err
}
expected.ID = found.ID
// Erase the tenant id because we don't want to compare
// it as long it is not present in the expected

View File

@ -285,27 +285,21 @@ func waitForListenerDelete(networkingClient *gophercloud.ServiceClient, listener
listener, err := listeners.Get(networkingClient, listenerID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return listener, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 listener %s", listenerID)
return listener, "DELETED", nil
}
return listener, "ACTIVE", err
}
log.Printf("[DEBUG] Openstack LBaaSV2 listener: %+v", listener)
err = listeners.Delete(networkingClient, listenerID).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return listener, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 listener %s", listenerID)
return listener, "DELETED", nil
}
return listener, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LBaaSV2 listener %s still active.", listenerID)

View File

@ -228,27 +228,21 @@ func waitForLoadBalancerDelete(networkingClient *gophercloud.ServiceClient, lbID
lb, err := loadbalancers.Get(networkingClient, lbID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return lb, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LoadBalancerV2 %s", lbID)
return lb, "DELETED", nil
}
return lb, "ACTIVE", err
}
log.Printf("[DEBUG] Openstack LoadBalancerV2: %+v", lb)
err = loadbalancers.Delete(networkingClient, lbID).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return lb, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LoadBalancerV2 %s", lbID)
return lb, "DELETED", nil
}
return lb, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LoadBalancerV2 %s still active.", lbID)

View File

@ -216,14 +216,11 @@ func waitForLBMemberDelete(networkingClient *gophercloud.ServiceClient, memberId
m, err := members.Get(networkingClient, memberId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return m, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB member %s", memberId)
return m, "DELETED", nil
}
return m, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB member %s still active.", memberId)

View File

@ -243,27 +243,21 @@ func waitForMemberDelete(networkingClient *gophercloud.ServiceClient, poolID str
member, err := pools.GetMember(networkingClient, poolID, memberID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return member, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Member %s", memberID)
return member, "DELETED", nil
}
return member, "ACTIVE", err
}
log.Printf("[DEBUG] Openstack LBaaSV2 Member: %+v", member)
err = pools.DeleteMember(networkingClient, poolID, memberID).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return member, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Member %s", memberID)
return member, "DELETED", nil
}
return member, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LBaaSV2 Member %s still active.", memberID)

View File

@ -264,35 +264,37 @@ func waitForLBMonitorDelete(networkingClient *gophercloud.ServiceClient, monitor
m, err := monitors.Get(networkingClient, monitorId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return m, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB Monitor %s", monitorId)
return m, "DELETED", nil
}
if errCode.Actual == 409 {
log.Printf("[DEBUG] OpenStack LB Monitor (%s) is waiting for Pool to delete.", monitorId)
return m, "PENDING", nil
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
if errCode.Actual == 409 {
log.Printf("[DEBUG] OpenStack LB Monitor (%s) is waiting for Pool to delete.", monitorId)
return m, "PENDING", nil
}
}
return m, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB Monitor: %+v", m)
err = monitors.Delete(networkingClient, monitorId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return m, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB Monitor %s", monitorId)
return m, "DELETED", nil
}
if errCode.Actual == 409 {
log.Printf("[DEBUG] OpenStack LB Monitor (%s) is waiting for Pool to delete.", monitorId)
return m, "PENDING", nil
if errCode, ok := err.(gophercloud.ErrUnexpectedResponseCode); ok {
if errCode.Actual == 409 {
log.Printf("[DEBUG] OpenStack LB Monitor (%s) is waiting for Pool to delete.", monitorId)
return m, "PENDING", nil
}
}
return m, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB Monitor %s still active.", monitorId)

View File

@ -258,27 +258,21 @@ func waitForMonitorDelete(networkingClient *gophercloud.ServiceClient, monitorID
monitor, err := monitors.Get(networkingClient, monitorID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return monitor, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Monitor %s", monitorID)
return monitor, "DELETED", nil
}
return monitor, "ACTIVE", err
}
log.Printf("[DEBUG] Openstack LBaaSV2 Monitor: %+v", monitor)
err = monitors.Delete(networkingClient, monitorID).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return monitor, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Monitor %s", monitorID)
return monitor, "DELETED", nil
}
return monitor, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LBaaSV2 Monitor %s still active.", monitorID)

View File

@ -437,27 +437,21 @@ func waitForLBPoolDelete(networkingClient *gophercloud.ServiceClient, poolId str
p, err := pools.Get(networkingClient, poolId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB Pool %s", poolId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB Pool: %+v", p)
err = pools.Delete(networkingClient, poolId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB Pool %s", poolId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB Pool %s still active.", poolId)

View File

@ -291,27 +291,21 @@ func waitForPoolDelete(networkingClient *gophercloud.ServiceClient, poolID strin
pool, err := pools.Get(networkingClient, poolID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return pool, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Pool %s", poolID)
return pool, "DELETED", nil
}
return pool, "ACTIVE", err
}
log.Printf("[DEBUG] Openstack LBaaSV2 Pool: %+v", pool)
err = pools.Delete(networkingClient, poolID).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return pool, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LBaaSV2 Pool %s", poolID)
return pool, "DELETED", nil
}
return pool, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LBaaSV2 Pool %s still active.", poolID)

View File

@ -370,27 +370,21 @@ func waitForLBVIPDelete(networkingClient *gophercloud.ServiceClient, vipId strin
p, err := vips.Get(networkingClient, vipId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB VIP %s", vipId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB VIP: %+v", p)
err = vips.Delete(networkingClient, vipId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack LB VIP %s", vipId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack LB VIP %s still active.", vipId)

View File

@ -259,26 +259,20 @@ func waitForFloatingIPDelete(networkingClient *gophercloud.ServiceClient, fId st
f, err := floatingips.Get(networkingClient, fId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return f, "ACTIVE", err
}
if errCode.Actual == 404 {
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 {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return f, "ACTIVE", err
}
if errCode.Actual == 404 {
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)

View File

@ -264,26 +264,20 @@ func waitForNetworkDelete(networkingClient *gophercloud.ServiceClient, networkId
n, err := networks.Get(networkingClient, networkId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return n, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Network %s", networkId)
return n, "DELETED", nil
}
return n, "ACTIVE", err
}
err = networks.Delete(networkingClient, networkId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return n, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Network %s", networkId)
return n, "DELETED", nil
}
return n, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Network %s still active.\n", networkId)

View File

@ -359,26 +359,20 @@ func waitForNetworkPortDelete(networkingClient *gophercloud.ServiceClient, portI
p, err := ports.Get(networkingClient, portId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Port %s", portId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
err = ports.Delete(networkingClient, portId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return p, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Port %s", portId)
return p, "DELETED", nil
}
return p, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Port %s still active.\n", portId)

View File

@ -91,15 +91,11 @@ func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interf
n, err := ports.Get(networkingClient, d.Id()).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router Interface: %s", err)
}
if httpError.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router Interface: %s", err)
}
@ -159,26 +155,20 @@ func waitForRouterInterfaceDelete(networkingClient *gophercloud.ServiceClient, d
r, err := ports.Get(networkingClient, routerInterfaceId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Router Interface %s", routerInterfaceId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
_, err = routers.RemoveInterface(networkingClient, routerId, removeOpts).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Router Interface %s", routerInterfaceId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Router Interface %s still active.\n", routerInterfaceId)

View File

@ -59,15 +59,11 @@ func resourceNetworkingRouterRouteV2Create(d *schema.ResourceData, meta interfac
n, err := routers.Get(networkingClient, routerId).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
@ -121,15 +117,11 @@ func resourceNetworkingRouterRouteV2Read(d *schema.ResourceData, meta interface{
n, err := routers.Get(networkingClient, routerId).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
@ -168,14 +160,10 @@ func resourceNetworkingRouterRouteV2Delete(d *schema.ResourceData, meta interfac
n, err := routers.Get(networkingClient, routerId).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}

View File

@ -171,15 +171,11 @@ func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) er
n, err := routers.Get(networkingClient, d.Id()).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
@ -276,26 +272,20 @@ func waitForRouterDelete(networkingClient *gophercloud.ServiceClient, routerId s
r, err := routers.Get(networkingClient, routerId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Router %s", routerId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
err = routers.Delete(networkingClient, routerId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Router %s", routerId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Router %s still active.\n", routerId)

View File

@ -241,26 +241,20 @@ func waitForSecGroupRuleDelete(networkingClient *gophercloud.ServiceClient, secG
r, err := rules.Get(networkingClient, secGroupRuleId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Neutron Security Group Rule %s", secGroupRuleId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
err = rules.Delete(networkingClient, secGroupRuleId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Neutron Security Group Rule %s", secGroupRuleId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Neutron Security Group Rule %s still active.\n", secGroupRuleId)

View File

@ -131,26 +131,20 @@ func waitForSecGroupDelete(networkingClient *gophercloud.ServiceClient, secGroup
r, err := groups.Get(networkingClient, secGroupId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Neutron Security Group %s", secGroupId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
err = groups.Delete(networkingClient, secGroupId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return r, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Neutron Security Group %s", secGroupId)
return r, "DELETED", nil
}
return r, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Neutron Security Group %s still active.\n", secGroupId)

View File

@ -418,26 +418,20 @@ func waitForSubnetDelete(networkingClient *gophercloud.ServiceClient, subnetId s
s, err := subnets.Get(networkingClient, subnetId).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return s, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Subnet %s", subnetId)
return s, "DELETED", nil
}
return s, "ACTIVE", err
}
err = subnets.Delete(networkingClient, subnetId).ExtractErr()
if err != nil {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return s, "ACTIVE", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
log.Printf("[DEBUG] Successfully deleted OpenStack Subnet %s", subnetId)
return s, "DELETED", nil
}
return s, "ACTIVE", err
}
log.Printf("[DEBUG] OpenStack Subnet %s still active.\n", subnetId)

View File

@ -10,13 +10,10 @@ import (
// CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so,
// sets the resource ID to the empty string instead of throwing an error.
func CheckDeleted(d *schema.ResourceData, err error, msg string) error {
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
if !ok {
return fmt.Errorf("%s: %s", msg, err)
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("%s: %s", msg, err)
}