Skip to content

Commit

Permalink
Merge pull request #60 from openbaton/issue-32
Browse files Browse the repository at this point in the history
Delete network if network creation (subnet and router) fails
  • Loading branch information
lorenzotomasini authored Apr 12, 2018
2 parents bdfc4b0 + c76c535 commit c97eafd
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c97eafd

Please sign in to comment.