@Override public CloudResource build( OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception { try { OSClient osClient = createOSClient(auth); NeutronNetworkView networkView = new NeutronNetworkView(network); Router router = Builders.router() .name(resource.getName()) .adminStateUp(true) .tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)) .externalGateway(networkView.getPublicNetId()) .build(); router = osClient.networking().router().create(router); osClient .networking() .router() .attachInterface( router.getId(), AttachInterfaceType.SUBNET, context.getStringParameter(OpenStackConstants.SUBNET_ID)); return createPersistedResource(resource, router.getId()); } catch (OS4JException ex) { throw new OpenStackResourceException( "Router creation failed", resourceType(), resource.getName(), ex); } }
@Override public CloudResource delete( OpenStackContext context, AuthenticatedContext auth, CloudResource resource) throws Exception { try { OSClient osClient = createOSClient(auth); String subnetId = context.getStringParameter(OpenStackConstants.SUBNET_ID); osClient.networking().router().detachInterface(resource.getReference(), subnetId, null); ActionResponse response = osClient.networking().router().delete(resource.getReference()); return checkDeleteResponse( response, resourceType(), auth, resource, "Router deletion failed"); } catch (OS4JException ex) { throw new OpenStackResourceException( "Router deletion failed", resourceType(), resource.getName(), ex); } }