Class InstancesClient (1.91.0)

GitHub RepositoryProduct Reference

Service Description: The Instances API.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (InstancesClient instancesClient = InstancesClient.create()) {
   String project = "project-309310695";
   String zone = "zone3744684";
   String instance = "instance555127957";
   Instance response = instancesClient.get(project, zone, instance);
 }
 

Note: close() needs to be called on the InstancesClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

AddAccessConfig

Adds an access config to an instance's network interface.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • addAccessConfigAsync(AddAccessConfigInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • addAccessConfigAsync(String project, String zone, String instance, String networkInterface, AccessConfig accessConfigResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • addAccessConfigOperationCallable()

  • addAccessConfigCallable()

AddNetworkInterface

Adds one dynamic network interface to an active instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • addNetworkInterfaceAsync(AddNetworkInterfaceInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • addNetworkInterfaceAsync(String project, String zone, String instance, NetworkInterface networkInterfaceResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • addNetworkInterfaceOperationCallable()

  • addNetworkInterfaceCallable()

AddResourcePolicies

Adds existing resource policies to an instance. You can only add one policy right now which will be applied to this instance for scheduling live migrations.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • addResourcePoliciesAsync(AddResourcePoliciesInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • addResourcePoliciesAsync(String project, String zone, String instance, InstancesAddResourcePoliciesRequest instancesAddResourcePoliciesRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • addResourcePoliciesOperationCallable()

  • addResourcePoliciesCallable()

AggregatedList

Retrieves an aggregated list of all of the instances in your project across all regions and zones.

The performance of this method degrades when a filter is specified on a project that has a very large number of instances.

To prevent failure, Google recommends that you set the returnPartialSuccess parameter to true.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • aggregatedList(AggregatedListInstancesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • aggregatedList(String project)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • aggregatedListPagedCallable()

  • aggregatedListCallable()

AttachDisk

Attaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, readAdding a persistent disk to your instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • attachDiskAsync(AttachDiskInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • attachDiskAsync(String project, String zone, String instance, AttachedDisk attachedDiskResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • attachDiskOperationCallable()

  • attachDiskCallable()

BulkInsert

Creates multiple instances. Count specifies the number of instances to create. For more information, seeAbout bulk creation of VMs.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • bulkInsertAsync(BulkInsertInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • bulkInsertAsync(String project, String zone, BulkInsertInstanceResource bulkInsertInstanceResourceResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • bulkInsertOperationCallable()

  • bulkInsertCallable()

Delete

Deletes the specified Instance resource. For more information, seeDeleting an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteAsync(DeleteInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • deleteAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteOperationCallable()

  • deleteCallable()

DeleteAccessConfig

Deletes an access config from an instance's network interface.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteAccessConfigAsync(DeleteAccessConfigInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • deleteAccessConfigAsync(String project, String zone, String instance, String accessConfig, String networkInterface)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteAccessConfigOperationCallable()

  • deleteAccessConfigCallable()

DeleteNetworkInterface

Deletes one dynamic network interface from an active instance. InstancesDeleteNetworkInterfaceRequest indicates: - instance from which to delete, using project+zone+resource_id fields; - dynamic network interface to be deleted, using network_interface_name field;

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteNetworkInterfaceAsync(DeleteNetworkInterfaceInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • deleteNetworkInterfaceAsync(String project, String zone, String instance, String networkInterfaceName)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteNetworkInterfaceOperationCallable()

  • deleteNetworkInterfaceCallable()

DetachDisk

Detaches a disk from an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • detachDiskAsync(DetachDiskInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • detachDiskAsync(String project, String zone, String instance, String deviceName)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • detachDiskOperationCallable()

  • detachDiskCallable()

Get

Returns the specified Instance resource.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • get(GetInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • get(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getCallable()

GetEffectiveFirewalls

Returns effective firewalls applied to an interface of the instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getEffectiveFirewalls(GetEffectiveFirewallsInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getEffectiveFirewalls(String project, String zone, String instance, String networkInterface)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getEffectiveFirewallsCallable()

GetGuestAttributes

Returns the specified guest attributes entry.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getGuestAttributes(GetGuestAttributesInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getGuestAttributes(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getGuestAttributesCallable()

GetIamPolicy

Gets the access control policy for a resource. May be empty if no such policy or resource exists.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getIamPolicy(GetIamPolicyInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getIamPolicy(String project, String zone, String resource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getIamPolicyCallable()

GetScreenshot

Returns the screenshot from the specified instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getScreenshot(GetScreenshotInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getScreenshot(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getScreenshotCallable()

GetSerialPortOutput

Returns the last 1 MB of serial port output from the specified instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getSerialPortOutput(GetSerialPortOutputInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getSerialPortOutput(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getSerialPortOutputCallable()

GetShieldedInstanceIdentity

Returns the Shielded Instance Identity of an instance

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getShieldedInstanceIdentity(GetShieldedInstanceIdentityInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getShieldedInstanceIdentity(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getShieldedInstanceIdentityCallable()

Insert

Creates an instance resource in the specified project using the data included in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • insertAsync(InsertInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • insertAsync(String project, String zone, Instance instanceResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • insertOperationCallable()

  • insertCallable()

List

Retrieves the list of instances contained within the specified zone.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • list(ListInstancesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • list(String project, String zone)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listPagedCallable()

  • listCallable()

ListReferrers

Retrieves a list of resources that refer to the VM instance specified in the request. For example, if the VM instance is part of a managed or unmanaged instance group, the referrers list includes the instance group. For more information, readViewing referrers to VM instances.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listReferrers(ListReferrersInstancesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listReferrers(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listReferrersPagedCallable()

  • listReferrersCallable()

PerformMaintenance

Perform a manual maintenance on the instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • performMaintenanceAsync(PerformMaintenanceInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • performMaintenanceAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • performMaintenanceOperationCallable()

  • performMaintenanceCallable()

RemoveResourcePolicies

Removes resource policies from an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • removeResourcePoliciesAsync(RemoveResourcePoliciesInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • removeResourcePoliciesAsync(String project, String zone, String instance, InstancesRemoveResourcePoliciesRequest instancesRemoveResourcePoliciesRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • removeResourcePoliciesOperationCallable()

  • removeResourcePoliciesCallable()

ReportHostAsFaulty

Mark the host as faulty and try to restart the instance on a new host.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • reportHostAsFaultyAsync(ReportHostAsFaultyInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • reportHostAsFaultyAsync(String project, String zone, String instance, InstancesReportHostAsFaultyRequest instancesReportHostAsFaultyRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • reportHostAsFaultyOperationCallable()

  • reportHostAsFaultyCallable()

Reset

Performs a reset on the instance. This is a hard reset. The VM does not do a graceful shutdown. For more information, seeResetting an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • resetAsync(ResetInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • resetAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • resetOperationCallable()

  • resetCallable()

Resume

Resumes an instance that was suspended using theinstances().suspend method.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • resumeAsync(ResumeInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • resumeAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • resumeOperationCallable()

  • resumeCallable()

SendDiagnosticInterrupt

Sends diagnostic interrupt to the instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • sendDiagnosticInterrupt(SendDiagnosticInterruptInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • sendDiagnosticInterrupt(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • sendDiagnosticInterruptCallable()

SetDeletionProtection

Sets deletion protection on the instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setDeletionProtectionAsync(SetDeletionProtectionInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setDeletionProtectionAsync(String project, String zone, String resource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setDeletionProtectionOperationCallable()

  • setDeletionProtectionCallable()

SetDiskAutoDelete

Sets the auto-delete flag for a disk attached to an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setDiskAutoDeleteAsync(SetDiskAutoDeleteInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setDiskAutoDeleteAsync(String project, String zone, String instance, boolean autoDelete, String deviceName)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setDiskAutoDeleteOperationCallable()

  • setDiskAutoDeleteCallable()

SetIamPolicy

Sets the access control policy on the specified resource. Replaces any existing policy.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setIamPolicy(SetIamPolicyInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • setIamPolicy(String project, String zone, String resource, ZoneSetPolicyRequest zoneSetPolicyRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setIamPolicyCallable()

SetLabels

Sets labels on an instance. To learn more about labels, read theLabeling Resources documentation.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setLabelsAsync(SetLabelsInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setLabelsAsync(String project, String zone, String instance, InstancesSetLabelsRequest instancesSetLabelsRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setLabelsOperationCallable()

  • setLabelsCallable()

SetMachineResources

Changes the number and/or type of accelerator for a stopped instance to the values specified in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setMachineResourcesAsync(SetMachineResourcesInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setMachineResourcesAsync(String project, String zone, String instance, InstancesSetMachineResourcesRequest instancesSetMachineResourcesRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setMachineResourcesOperationCallable()

  • setMachineResourcesCallable()

SetMachineType

Changes the machine type for a stopped instance to the machine type specified in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setMachineTypeAsync(SetMachineTypeInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setMachineTypeAsync(String project, String zone, String instance, InstancesSetMachineTypeRequest instancesSetMachineTypeRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setMachineTypeOperationCallable()

  • setMachineTypeCallable()

SetMetadata

Sets metadata for the specified instance to the data included in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setMetadataAsync(SetMetadataInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setMetadataAsync(String project, String zone, String instance, Metadata metadataResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setMetadataOperationCallable()

  • setMetadataCallable()

SetMinCpuPlatform

Changes the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, readSpecifying a Minimum CPU Platform.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setMinCpuPlatformAsync(SetMinCpuPlatformInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setMinCpuPlatformAsync(String project, String zone, String instance, InstancesSetMinCpuPlatformRequest instancesSetMinCpuPlatformRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setMinCpuPlatformOperationCallable()

  • setMinCpuPlatformCallable()

SetName

Sets name of an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setNameAsync(SetNameInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setNameAsync(String project, String zone, String instance, InstancesSetNameRequest instancesSetNameRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setNameOperationCallable()

  • setNameCallable()

SetScheduling

Sets an instance's scheduling options. You can only call this method on astopped instance, that is, a VM instance that is in a TERMINATED state. SeeInstance Life Cycle for more information on the possible instance states. For more information about setting scheduling options for a VM, seeSet VM host maintenance policy.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setSchedulingAsync(SetSchedulingInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setSchedulingAsync(String project, String zone, String instance, Scheduling schedulingResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setSchedulingOperationCallable()

  • setSchedulingCallable()

SetSecurityPolicy

Sets the Google Cloud Armor security policy for the specified instance. For more information, seeGoogle Cloud Armor Overview

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setSecurityPolicyAsync(SetSecurityPolicyInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setSecurityPolicyAsync(String project, String zone, String instance, InstancesSetSecurityPolicyRequest instancesSetSecurityPolicyRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setSecurityPolicyOperationCallable()

  • setSecurityPolicyCallable()

SetServiceAccount

Sets the service account on the instance. For more information, readChanging the service account and access scopes for an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setServiceAccountAsync(SetServiceAccountInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setServiceAccountAsync(String project, String zone, String instance, InstancesSetServiceAccountRequest instancesSetServiceAccountRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setServiceAccountOperationCallable()

  • setServiceAccountCallable()

SetShieldedInstanceIntegrityPolicy

Sets the Shielded Instance integrity policy for an instance. You can only use this method on a running instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setShieldedInstanceIntegrityPolicyAsync(SetShieldedInstanceIntegrityPolicyInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setShieldedInstanceIntegrityPolicyAsync(String project, String zone, String instance, ShieldedInstanceIntegrityPolicy shieldedInstanceIntegrityPolicyResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setShieldedInstanceIntegrityPolicyOperationCallable()

  • setShieldedInstanceIntegrityPolicyCallable()

SetTags

Sets network tags for the specified instance to the data included in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setTagsAsync(SetTagsInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • setTagsAsync(String project, String zone, String instance, Tags tagsResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setTagsOperationCallable()

  • setTagsCallable()

SimulateMaintenanceEvent

Simulates a host maintenance event on a VM. For more information, see Simulate a host maintenance event.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • simulateMaintenanceEventAsync(SimulateMaintenanceEventInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • simulateMaintenanceEventAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • simulateMaintenanceEventOperationCallable()

  • simulateMaintenanceEventCallable()

Start

Starts an instance that was stopped using theinstances().stop method. For more information, seeRestart an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • startAsync(StartInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • startAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • startOperationCallable()

  • startCallable()

StartWithEncryptionKey

Starts an instance that was stopped using theinstances().stop method. For more information, seeRestart an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • startWithEncryptionKeyAsync(StartWithEncryptionKeyInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • startWithEncryptionKeyAsync(String project, String zone, String instance, InstancesStartWithEncryptionKeyRequest instancesStartWithEncryptionKeyRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • startWithEncryptionKeyOperationCallable()

  • startWithEncryptionKeyCallable()

Stop

Stops a running instance, shutting it down cleanly, and allows you to restart the instance at a later time. Stopped instances do not incur VM usage charges while they are stopped. However, resources that the VM is using, such as persistent disks and static IP addresses, will continue to be charged until they are deleted. For more information, seeStopping an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • stopAsync(StopInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • stopAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • stopOperationCallable()

  • stopCallable()

Suspend

This method suspends a running instance, saving its state to persistent storage, and allows you to resume the instance at a later time. Suspended instances have no compute costs (cores or RAM), and incur only storage charges for the saved VM memory and localSSD data. Any charged resources the virtual machine was using, such as persistent disks and static IP addresses, will continue to be charged while the instance is suspended. For more information, see Suspending and resuming an instance.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • suspendAsync(SuspendInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • suspendAsync(String project, String zone, String instance)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • suspendOperationCallable()

  • suspendCallable()

TestIamPermissions

Returns permissions that a caller has on the specified resource.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • testIamPermissions(TestIamPermissionsInstanceRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • testIamPermissions(String project, String zone, String resource, TestPermissionsRequest testPermissionsRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • testIamPermissionsCallable()

Update

Updates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateAsync(UpdateInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateAsync(String project, String zone, String instance, Instance instanceResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateOperationCallable()

  • updateCallable()

UpdateAccessConfig

Updates the specified access config from an instance's network interface with the data included in the request. This method supportsPATCH semantics and uses theJSON merge patch format and processing rules.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateAccessConfigAsync(UpdateAccessConfigInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateAccessConfigAsync(String project, String zone, String instance, String networkInterface, AccessConfig accessConfigResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateAccessConfigOperationCallable()

  • updateAccessConfigCallable()

UpdateDisplayDevice

Updates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supportsPATCH semantics and uses theJSON merge patch format and processing rules.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateDisplayDeviceAsync(UpdateDisplayDeviceInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateDisplayDeviceAsync(String project, String zone, String instance, DisplayDevice displayDeviceResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateDisplayDeviceOperationCallable()

  • updateDisplayDeviceCallable()

UpdateNetworkInterface

Updates an instance's network interface. This method can only update an interface's alias IP range and attached network. See Modifying alias IP ranges for an existing instance for instructions on changing alias IP ranges. See Migrating a VM between networks for instructions on migrating an interface. This method follows PATCH semantics.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateNetworkInterfaceAsync(UpdateNetworkInterfaceInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateNetworkInterfaceAsync(String project, String zone, String instance, String networkInterface, NetworkInterface networkInterfaceResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateNetworkInterfaceOperationCallable()

  • updateNetworkInterfaceCallable()

UpdateShieldedInstanceConfig

Updates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supportsPATCH semantics and uses theJSON merge patch format and processing rules.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateShieldedInstanceConfigAsync(UpdateShieldedInstanceConfigInstanceRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • updateShieldedInstanceConfigAsync(String project, String zone, String instance, ShieldedInstanceConfig shieldedInstanceConfigResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateShieldedInstanceConfigOperationCallable()

  • updateShieldedInstanceConfigCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of InstancesSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 InstancesSettings instancesSettings =
     InstancesSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 InstancesClient instancesClient = InstancesClient.create(instancesSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 InstancesSettings instancesSettings =
     InstancesSettings.newBuilder().setEndpoint(myEndpoint).build();
 InstancesClient instancesClient = InstancesClient.create(instancesSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > InstancesClient

Static Methods

create()

public static final InstancesClient create()

Constructs an instance of InstancesClient with default settings.

Returns
Type Description
InstancesClient
Exceptions
Type Description
IOException

create(InstancesSettings settings)

public static final InstancesClient create(InstancesSettings settings)

Constructs an instance of InstancesClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings InstancesSettings
Returns
Type Description
InstancesClient
Exceptions
Type Description
IOException

create(InstancesStub stub)

public static final InstancesClient create(InstancesStub stub)

Constructs an instance of InstancesClient, using the given stub for making calls. This is for advanced usage - prefer using create(InstancesSettings).

Parameter
Name Description
stub InstancesStub
Returns
Type Description
InstancesClient

Constructors

InstancesClient(InstancesSettings settings)

protected InstancesClient(InstancesSettings settings)

Constructs an instance of InstancesClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings InstancesSettings

InstancesClient(InstancesStub stub)

protected InstancesClient(InstancesStub stub)
Parameter
Name Description
stub InstancesStub

Methods

addAccessConfigAsync(AddAccessConfigInstanceRequest request)

public final OperationFuture<Operation,Operation> addAccessConfigAsync(AddAccessConfigInstanceRequest request)

Adds an access config to an instance's network interface.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (InstancesClient instancesClient = InstancesClient.create()) {
   AddAccess