use of com.google.cloud.compute.v1.RoutesClient in project java-docs-samples by GoogleCloudPlatform.
the class CreateRouteToWindowsActivationHost method createRouteToWindowsActivationHost.
// Creates a new route to kms.windows.googlecloud.com (35.190.247.13) for Windows activation.
public static void createRouteToWindowsActivationHost(String projectId, String routeName, String networkName) throws IOException, ExecutionException, InterruptedException, TimeoutException {
// Instantiates a client.
try (RoutesClient routesClient = RoutesClient.create()) {
// If you have Windows instances without external IP addresses,
// you must also enable Private Google Access so that instances
// with only internal IP addresses can send traffic to the external
// IP address for kms.windows.googlecloud.com.
// More information: https://cloud.google.com/vpc/docs/configure-private-google-access#enabling
Route route = Route.newBuilder().setName(routeName).setDestRange("35.190.247.13/32").setNetwork(networkName).setNextHopGateway(String.format("projects/%s/global/gateways/default-internet-gateway", projectId)).build();
InsertRouteRequest request = InsertRouteRequest.newBuilder().setProject(projectId).setRouteResource(route).build();
// Wait for the operation to complete.
Operation operation = routesClient.insertAsync(request).get(3, TimeUnit.MINUTES);
if (operation.hasError()) {
System.out.printf("Error in creating route %s", operation.getError());
return;
}
System.out.printf("Route created %s", routeName);
}
}
Aggregations