Search in sources :

Example 1 with SetDeletionProtectionInstanceRequest

use of com.google.cloud.compute.v1.SetDeletionProtectionInstanceRequest in project java-docs-samples by GoogleCloudPlatform.

the class SetDeleteProtection method setDeleteProtection.

// Updates the "Delete Protection" setting of given instance.
public static void setDeleteProtection(String projectId, String zone, String instanceName, boolean deleteProtection) throws IOException, ExecutionException, InterruptedException {
    try (InstancesClient instancesClient = InstancesClient.create()) {
        SetDeletionProtectionInstanceRequest request = SetDeletionProtectionInstanceRequest.newBuilder().setProject(projectId).setZone(zone).setResource(instanceName).setDeletionProtection(deleteProtection).build();
        instancesClient.setDeletionProtectionAsync(request).get();
        // Retrieve the updated setting from the instance.
        System.out.printf("Updated Delete Protection setting: %s", instancesClient.get(projectId, zone, instanceName).getDeletionProtection());
    }
}
Also used : SetDeletionProtectionInstanceRequest(com.google.cloud.compute.v1.SetDeletionProtectionInstanceRequest) InstancesClient(com.google.cloud.compute.v1.InstancesClient)

Aggregations

InstancesClient (com.google.cloud.compute.v1.InstancesClient)1 SetDeletionProtectionInstanceRequest (com.google.cloud.compute.v1.SetDeletionProtectionInstanceRequest)1