private void deleteGuestNetworkRouters(Network network){
String accountUuid = getAccountUuid(network);
boolean isVpc = getIsVpc(network);
long id = getRouterId(network, isVpc);
Router tenantRouter = getGuestNetworkRouter(id, accountUuid, isVpc);
// Delete any peer ports corresponding to this router
for(Port peerPort : tenantRouter.getPeerPorts((new MultivaluedMapImpl()))){
if(peerPort != null && peerPort instanceof RouterPort){
RouterPort checkPort = (RouterPort) peerPort;
if(checkPort.getType().equals("ExteriorRouter")) {
checkPort.vifId(null).update();
} else if (checkPort.getType().equals("InteriorRouter")) {
checkPort.unlink();
}
checkPort.delete();
} else if (peerPort != null && peerPort instanceof BridgePort) {
BridgePort checkPort = (BridgePort) peerPort;
if(checkPort.getType().equals("ExteriorBridge")) {
checkPort.vifId(null).update();
} else if (checkPort.getType().equals("InteriorBridge")) {
checkPort.unlink();
}
checkPort.delete();
}
}
if(tenantRouter != null){
// Remove all peer ports if any exist
for(RouterPort p : tenantRouter.getPorts(new MultivaluedMapImpl())) {
if(p.getType().equals("ExteriorRouter")) {
// Set VIF ID to null
p.vifId(null).update();
// the port might have some chains associated with it
}
if(p.getType().equals("InteriorRouter")) {
p.unlink();
}
// Delete port
p.delete();
}
// Remove inbound and outbound filter chains
String accountIdStr = String.valueOf(accountUuid);
String routerName = getRouterName(isVpc, id);
RuleChain pre = api.getChain(tenantRouter.getInboundFilterId());
RuleChain preFilter = getChain(accountIdStr, routerName, RuleChainCode.TR_PREFILTER);
RuleChain preNat = getChain(accountIdStr, routerName, RuleChainCode.TR_PRENAT);
RuleChain post = api.getChain(tenantRouter.getOutboundFilterId());
pre.delete();
preFilter.delete();
preNat.delete();
post.delete();
// Remove routes
for(Route r : tenantRouter.getRoutes(new MultivaluedMapImpl())) {
r.delete();
}
tenantRouter.delete();
}
}