Search in sources :

Example 1 with InsertRouteRequest

use of com.google.cloud.compute.v1.InsertRouteRequest 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);
    }
}
Also used : RoutesClient(com.google.cloud.compute.v1.RoutesClient) Operation(com.google.cloud.compute.v1.Operation) InsertRouteRequest(com.google.cloud.compute.v1.InsertRouteRequest) Route(com.google.cloud.compute.v1.Route)

Aggregations

InsertRouteRequest (com.google.cloud.compute.v1.InsertRouteRequest)1 Operation (com.google.cloud.compute.v1.Operation)1 Route (com.google.cloud.compute.v1.Route)1 RoutesClient (com.google.cloud.compute.v1.RoutesClient)1