diff --git a/src/main/java/org/openbaton/drivers/openstack4j/OpenStack4JDriver.java b/src/main/java/org/openbaton/drivers/openstack4j/OpenStack4JDriver.java index 68d23bc..d7ca2eb 100644 --- a/src/main/java/org/openbaton/drivers/openstack4j/OpenStack4JDriver.java +++ b/src/main/java/org/openbaton/drivers/openstack4j/OpenStack4JDriver.java @@ -1514,10 +1514,17 @@ private void attachToRouter(OSClient os, String subnetExtId, BaseVimInstance vim .attachInterface(router.getId(), AttachInterfaceType.SUBNET, subnetExtId); } else { Router router = createRouter(os, vimInstance); + if (null == router) { + throw new VimDriverException("Unable to create router"); + } iface = os.networking() .router() .attachInterface(router.getId(), AttachInterfaceType.SUBNET, subnetExtId); + if (null == iface) { + // failed to attach router, delete the router + os.networking().router().delete(router.getId()); + } } if (iface == null) { throw new VimDriverException("Not Able to attach to router the new subnet"); @@ -1680,6 +1687,14 @@ public Subnet createSubnet(BaseVimInstance vimInstance, BaseNetwork createdNetwo attachToRouter(os, sn.getExtId(), vimInstance); } catch (VimDriverException e) { log.error(e.getMessage()); + + // if we could not attach the router to the delete the subnet + try { + deleteSubnet(vimInstance, sn.getExtId()); + } catch (VimDriverException e2) { + log.error(e.getMessage()); + } + throw new VimDriverException("Deleted subnet"); } return sn; }