use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.
the class CreateTemplateFromInstance method createTemplateFromInstance.
// Create a new instance template based on an existing instance.
// This new template specifies a different boot disk.
public static void createTemplateFromInstance(String projectId, String templateName, String instance) throws IOException, ExecutionException, InterruptedException {
try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create();
GlobalOperationsClient globalOperationsClient = GlobalOperationsClient.create()) {
SourceInstanceParams sourceInstanceParams = SourceInstanceParams.newBuilder().addDiskConfigs(DiskInstantiationConfig.newBuilder().setDeviceName("disk-1").setInstantiateFrom(InstantiateFrom.CUSTOM_IMAGE.toString()).setCustomImage(String.format("projects/%s/global/images/family/%s", "rocky-linux-cloud", "rocky-linux-8")).setAutoDelete(true).build()).build();
InstanceTemplate instanceTemplate = InstanceTemplate.newBuilder().setName(templateName).setSourceInstance(instance).setSourceInstanceParams(sourceInstanceParams).build();
InsertInstanceTemplateRequest insertInstanceTemplateRequest = InsertInstanceTemplateRequest.newBuilder().setProject(projectId).setInstanceTemplateResource(instanceTemplate).build();
Operation operation = instanceTemplatesClient.insertCallable().futureCall(insertInstanceTemplateRequest).get();
Operation response = globalOperationsClient.wait(projectId, operation.getName());
if (response.hasError()) {
System.out.println("Instance Template creation failed ! ! " + response);
return;
}
System.out.printf("Instance Template creation operation status %s: %s", templateName, response.getStatus());
}
}
use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.
the class DeleteFirewallRule method deleteFirewallRule.
// Deletes a firewall rule from the project.
public static void deleteFirewallRule(String project, String firewallRuleName) throws IOException, ExecutionException, InterruptedException {
/* Initialize client that will be used to send requests. This client only needs to be created
once, and can be reused for multiple requests. After completing all of your requests, call
the `firewallsClient.close()` method on the client to safely
clean up any remaining background resources. */
try (FirewallsClient firewallsClient = FirewallsClient.create()) {
OperationFuture<Operation, Operation> operation = firewallsClient.deleteAsync(project, firewallRuleName);
operation.get();
System.out.println("Deleted firewall rule -> " + firewallRuleName);
}
}
use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.
the class DeleteInstanceTemplate method deleteInstanceTemplate.
// Delete an instance template.
public static void deleteInstanceTemplate(String projectId, String templateName) throws IOException, ExecutionException, InterruptedException {
try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create()) {
DeleteInstanceTemplateRequest deleteInstanceTemplateRequest = DeleteInstanceTemplateRequest.newBuilder().setProject(projectId).setInstanceTemplate(templateName).build();
Operation response = instanceTemplatesClient.deleteAsync(deleteInstanceTemplateRequest).get();
if (response.hasError()) {
System.out.println("Instance template deletion failed ! ! " + response);
return;
}
System.out.printf("Instance template deletion operation status for %s: %s ", templateName, response.getStatus());
}
}
use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.
the class PatchFirewallRule method patchFirewallPriority.
// Modifies the priority of a given firewall rule.
public static void patchFirewallPriority(String project, String firewallRuleName, int priority) throws IOException, ExecutionException, InterruptedException {
/* Initialize client that will be used to send requests. This client only needs to be created
once, and can be reused for multiple requests. After completing all of your requests, call
the `firewallsClient.close()` method on the client to safely
clean up any remaining background resources. */
try (FirewallsClient firewallsClient = FirewallsClient.create()) {
/* The patch operation doesn't require the full definition of a Firewall object. It will only
update the values that were set in it, in this case it will only change the priority. */
Firewall firewall = Firewall.newBuilder().setPriority(priority).build();
PatchFirewallRequest patchFirewallRequest = PatchFirewallRequest.newBuilder().setProject(project).setFirewall(firewallRuleName).setFirewallResource(firewall).build();
OperationFuture<Operation, Operation> operation = firewallsClient.patchAsync(patchFirewallRequest);
operation.get();
System.out.println("Firewall Patch applied successfully ! ");
}
}
use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.
the class CreateInstance method createInstance.
// Create a new instance with the provided "instanceName" value in the specified project and zone.
public static void createInstance(String project, String zone, String instanceName) throws IOException, InterruptedException, ExecutionException {
// Below are sample values that can be replaced.
// machineType: machine type of the VM being created. This value uses the format zones/{zone}/machineTypes/{type_name}. For a list of machine types, see https://cloud.google.com/compute/docs/machine-types
// sourceImage: path to the operating system image to mount. For details about images you can mount, see https://cloud.google.com/compute/docs/images
// diskSizeGb: storage size of the boot disk to attach to the instance.
// networkName: network interface to associate with the instance.
String machineType = String.format("zones/%s/machineTypes/n1-standard-1", zone);
String sourceImage = String.format("projects/debian-cloud/global/images/family/%s", "debian-10");
long diskSizeGb = 10L;
String networkName = "default";
// clean up any remaining background resources.
try (InstancesClient instancesClient = InstancesClient.create()) {
// Instance creation requires at least one persistent disk and one network interface.
AttachedDisk disk = AttachedDisk.newBuilder().setBoot(true).setAutoDelete(true).setType(Type.PERSISTENT.toString()).setDeviceName("disk-1").setInitializeParams(AttachedDiskInitializeParams.newBuilder().setSourceImage(sourceImage).setDiskSizeGb(diskSizeGb).build()).build();
// Use the network interface provided in the networkName argument.
NetworkInterface networkInterface = NetworkInterface.newBuilder().setName(networkName).build();
// Bind `instanceName`, `machineType`, `disk`, and `networkInterface` to an instance.
Instance instanceResource = Instance.newBuilder().setName(instanceName).setMachineType(machineType).addDisks(disk).addNetworkInterfaces(networkInterface).build();
System.out.printf("Creating instance: %s at %s %n", instanceName, zone);
// Insert the instance in the specified project and zone.
InsertInstanceRequest insertInstanceRequest = InsertInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstanceResource(instanceResource).build();
OperationFuture<Operation, Operation> operation = instancesClient.insertAsync(insertInstanceRequest);
// Wait for the operation to complete.
Operation response = operation.get();
if (response.hasError()) {
System.out.println("Instance creation failed ! ! " + response);
return;
}
System.out.println("Operation Status: " + response.getStatus());
}
}
Aggregations