Reference documentation and code samples for the Compute V1 Client class InstancesClient.
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:
$instancesClient = new InstancesClient();
try {
$accessConfigResource = new AccessConfig();
$instance = 'instance';
$networkInterface = 'network_interface';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->addAccessConfig($accessConfigResource, $instance, $networkInterface, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->addAccessConfig($accessConfigResource, $instance, $networkInterface, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'addAccessConfig');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Methods
getOperationsClient
Return an ZoneOperationsClient object with the same endpoint as $this.
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\ZoneOperationsClient |
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
Parameters | |
---|---|
Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
options |
array
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
string|array|FetchAuthTokenInterface|CredentialsWrapper
The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed {@see} object or {@see} object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see {@see} . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|TransportInterface
The transport used for executing network requests. At the moment, supports only |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'rest' => [...], ]; See the {@see} method for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
addAccessConfig
Adds an access config to an instance's network interface.
Sample code:
$instancesClient = new InstancesClient();
try {
$accessConfigResource = new AccessConfig();
$instance = 'instance';
$networkInterface = 'network_interface';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->addAccessConfig($accessConfigResource, $instance, $networkInterface, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->addAccessConfig($accessConfigResource, $instance, $networkInterface, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'addAccessConfig');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
accessConfigResource |
Google\Cloud\Compute\V1\AccessConfig
The body resource for this request |
instance |
string
The instance name for this request. |
networkInterface |
string
The name of the network interface to add to this instance. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
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.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesAddResourcePoliciesRequestResource = new InstancesAddResourcePoliciesRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->addResourcePolicies($instance, $instancesAddResourcePoliciesRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->addResourcePolicies($instance, $instancesAddResourcePoliciesRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'addResourcePolicies');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
The instance name for this request. |
instancesAddResourcePoliciesRequestResource |
Google\Cloud\Compute\V1\InstancesAddResourcePoliciesRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
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.
Sample code:
$instancesClient = new InstancesClient();
try {
$project = 'project';
// Iterate over pages of elements
$pagedResponse = $instancesClient->aggregatedList($project);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $key => $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $instancesClient->aggregatedList($project);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
project |
string
Project ID for this request. |
optionalArgs |
array
Optional. |
↳ filter |
string
A filter expression that filters resources listed in the response. Most Compute resources support two types of filter expressions: expressions that support regular expressions and expressions that follow API improvement proposal AIP-160. If you want to use AIP-160, your expression must specify the field name, an operator, and the value that you want to use for filtering. The value must be a string, a number, or a boolean. The operator must be either |
↳ includeAllScopes |
bool
Indicates whether every visible scope for each scope type (zone, region, global) should be included in the response. For new resource types added after this field, the flag has no effect as new resource types will always include every visible scope for each scope type in response. For resource types which predate this field, if this flag is omitted or false, only scopes of the scope types where the resource type is expected to be found will be included. |
↳ maxResults |
int
The maximum number of results per page that should be returned. If the number of available results is larger than |
↳ orderBy |
string
Sorts list results by a certain order. By default, results are returned in alphanumerical order based on the resource name. You can also sort results in descending order based on the creation timestamp using |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ returnPartialSuccess |
bool
Opt-in for partial success behavior which provides partial results in case of failure. The default value is false. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
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, read Adding a persistent disk to your instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$attachedDiskResource = new AttachedDisk();
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->attachDisk($attachedDiskResource, $instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->attachDisk($attachedDiskResource, $instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'attachDisk');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
attachedDiskResource |
Google\Cloud\Compute\V1\AttachedDisk
The body resource for this request |
instance |
string
The instance name for this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ forceAttach |
bool
Whether to force attach the regional disk even if it's currently attached to another instance. If you try to force attach a zonal disk to an instance, you will receive an error. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
bulkInsert
Creates multiple instances. Count specifies the number of instances to create. For more information, see About bulk creation of VMs.
Sample code:
$instancesClient = new InstancesClient();
try {
$bulkInsertInstanceResourceResource = new BulkInsertInstanceResource();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->bulkInsert($bulkInsertInstanceResourceResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->bulkInsert($bulkInsertInstanceResourceResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'bulkInsert');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
bulkInsertInstanceResourceResource |
Google\Cloud\Compute\V1\BulkInsertInstanceResource
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
delete
Deletes the specified Instance resource. For more information, see Deleting an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->delete($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->delete($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'delete');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to delete. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
deleteAccessConfig
Deletes an access config from an instance's network interface.
Sample code:
$instancesClient = new InstancesClient();
try {
$accessConfig = 'access_config';
$instance = 'instance';
$networkInterface = 'network_interface';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->deleteAccessConfig($accessConfig, $instance, $networkInterface, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->deleteAccessConfig($accessConfig, $instance, $networkInterface, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'deleteAccessConfig');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
accessConfig |
string
The name of the access config to delete. |
instance |
string
The instance name for this request. |
networkInterface |
string
The name of the network interface. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
detachDisk
Detaches a disk from an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$deviceName = 'device_name';
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->detachDisk($deviceName, $instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->detachDisk($deviceName, $instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'detachDisk');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
deviceName |
string
The device name of the disk to detach. Make a get() request on the instance to view currently attached disks and device names. |
instance |
string
Instance name for this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
get
Returns the specified Instance resource. Gets a list of available instances by making a list() request.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->get($instance, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to return. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\Instance |
getEffectiveFirewalls
Returns effective firewalls applied to an interface of the instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$networkInterface = 'network_interface';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->getEffectiveFirewalls($instance, $networkInterface, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
networkInterface |
string
The name of the network interface to get the effective firewalls. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\InstancesGetEffectiveFirewallsResponse |
getGuestAttributes
Returns the specified guest attributes entry.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->getGuestAttributes($instance, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ queryPath |
string
Specifies the guest attributes path to be queried. |
↳ variableKey |
string
Specifies the key for the guest attributes entry. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\GuestAttributes |
getIamPolicy
Gets the access control policy for a resource. May be empty if no such policy or resource exists.
Sample code:
$instancesClient = new InstancesClient();
try {
$project = 'project';
$resource = 'resource';
$zone = 'zone';
$response = $instancesClient->getIamPolicy($project, $resource, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
project |
string
Project ID for this request. |
resource |
string
Name or id of the resource for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ optionsRequestedPolicyVersion |
int
Requested IAM Policy version. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\Policy |
getScreenshot
Returns the screenshot from the specified instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->getScreenshot($instance, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\Screenshot |
getSerialPortOutput
Returns the last 1 MB of serial port output from the specified instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->getSerialPortOutput($instance, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance for this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ port |
int
Specifies which COM or serial port to retrieve data from. |
↳ start |
int
Specifies the starting byte position of the output to return. To start with the first byte of output to the specified port, omit this field or set it to |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\SerialPortOutput |
getShieldedInstanceIdentity
Returns the Shielded Instance Identity of an instance
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->getShieldedInstanceIdentity($instance, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name or id of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\ShieldedInstanceIdentity |
insert
Creates an instance resource in the specified project using the data included in the request.
Sample code:
$instancesClient = new InstancesClient();
try {
$instanceResource = new Instance();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->insert($instanceResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->insert($instanceResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'insert');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instanceResource |
Google\Cloud\Compute\V1\Instance
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ sourceInstanceTemplate |
string
Specifies instance template to create the instance. This field is optional. It can be a full or partial URL. For example, the following are all valid URLs to an instance template: - https://www.googleapis.com/compute/v1/projects/project /global/instanceTemplates/instanceTemplate - projects/project/global/instanceTemplates/instanceTemplate - global/instanceTemplates/instanceTemplate |
↳ sourceMachineImage |
string
Specifies the machine image to use to create the instance. This field is optional. It can be a full or partial URL. For example, the following are all valid URLs to a machine image: - https://www.googleapis.com/compute/v1/projects/project/global/global /machineImages/machineImage - projects/project/global/global/machineImages/machineImage - global/machineImages/machineImage |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
list
Retrieves the list of instances contained within the specified zone.
Sample code:
$instancesClient = new InstancesClient();
try {
$project = 'project';
$zone = 'zone';
// Iterate over pages of elements
$pagedResponse = $instancesClient->list($project, $zone);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $instancesClient->list($project, $zone);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ filter |
string
A filter expression that filters resources listed in the response. Most Compute resources support two types of filter expressions: expressions that support regular expressions and expressions that follow API improvement proposal AIP-160. If you want to use AIP-160, your expression must specify the field name, an operator, and the value that you want to use for filtering. The value must be a string, a number, or a boolean. The operator must be either |
↳ maxResults |
int
The maximum number of results per page that should be returned. If the number of available results is larger than |
↳ orderBy |
string
Sorts list results by a certain order. By default, results are returned in alphanumerical order based on the resource name. You can also sort results in descending order based on the creation timestamp using |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ returnPartialSuccess |
bool
Opt-in for partial success behavior which provides partial results in case of failure. The default value is false. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
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, read Viewing referrers to VM instances.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
// Iterate over pages of elements
$pagedResponse = $instancesClient->listReferrers($instance, $project, $zone);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $instancesClient->listReferrers($instance, $project, $zone);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the target instance scoping this request, or '-' if the request should span over all instances in the container. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ filter |
string
A filter expression that filters resources listed in the response. Most Compute resources support two types of filter expressions: expressions that support regular expressions and expressions that follow API improvement proposal AIP-160. If you want to use AIP-160, your expression must specify the field name, an operator, and the value that you want to use for filtering. The value must be a string, a number, or a boolean. The operator must be either |
↳ maxResults |
int
The maximum number of results per page that should be returned. If the number of available results is larger than |
↳ orderBy |
string
Sorts list results by a certain order. By default, results are returned in alphanumerical order based on the resource name. You can also sort results in descending order based on the creation timestamp using |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ returnPartialSuccess |
bool
Opt-in for partial success behavior which provides partial results in case of failure. The default value is false. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
removeResourcePolicies
Removes resource policies from an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesRemoveResourcePoliciesRequestResource = new InstancesRemoveResourcePoliciesRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->removeResourcePolicies($instance, $instancesRemoveResourcePoliciesRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->removeResourcePolicies($instance, $instancesRemoveResourcePoliciesRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'removeResourcePolicies');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
The instance name for this request. |
instancesRemoveResourcePoliciesRequestResource |
Google\Cloud\Compute\V1\InstancesRemoveResourcePoliciesRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
reset
Performs a reset on the instance. This is a hard reset. The VM does not do a graceful shutdown. For more information, see Resetting an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->reset($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->reset($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'reset');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
resume
Resumes an instance that was suspended using the instances().suspend method.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->resume($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->resume($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'resume');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to resume. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
sendDiagnosticInterrupt
Sends diagnostic interrupt to the instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$response = $instancesClient->sendDiagnosticInterrupt($instance, $project, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\SendDiagnosticInterruptInstanceResponse |
setDeletionProtection
Sets deletion protection on the instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$project = 'project';
$resource = 'resource';
$zone = 'zone';
$operationResponse = $instancesClient->setDeletionProtection($project, $resource, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setDeletionProtection($project, $resource, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setDeletionProtection');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
project |
string
Project ID for this request. |
resource |
string
Name or id of the resource for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ deletionProtection |
bool
Whether the resource should be protected against deletion. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setDiskAutoDelete
Sets the auto-delete flag for a disk attached to an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$autoDelete = false;
$deviceName = 'device_name';
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setDiskAutoDelete($autoDelete, $deviceName, $instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setDiskAutoDelete($autoDelete, $deviceName, $instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setDiskAutoDelete');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
autoDelete |
bool
Whether to auto-delete the disk when the instance is deleted. |
deviceName |
string
The device name of the disk to modify. Make a get() request on the instance to view currently attached disks and device names. |
instance |
string
The instance name for this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setIamPolicy
Sets the access control policy on the specified resource. Replaces any existing policy.
Sample code:
$instancesClient = new InstancesClient();
try {
$project = 'project';
$resource = 'resource';
$zone = 'zone';
$zoneSetPolicyRequestResource = new ZoneSetPolicyRequest();
$response = $instancesClient->setIamPolicy($project, $resource, $zone, $zoneSetPolicyRequestResource);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
project |
string
Project ID for this request. |
resource |
string
Name or id of the resource for this request. |
zone |
string
The name of the zone for this request. |
zoneSetPolicyRequestResource |
Google\Cloud\Compute\V1\ZoneSetPolicyRequest
The body resource for this request |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\Policy |
setLabels
Sets labels on an instance. To learn more about labels, read the Labeling Resources documentation.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesSetLabelsRequestResource = new InstancesSetLabelsRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setLabels($instance, $instancesSetLabelsRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setLabels($instance, $instancesSetLabelsRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setLabels');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
instancesSetLabelsRequestResource |
Google\Cloud\Compute\V1\InstancesSetLabelsRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setMachineResources
Changes the number and/or type of accelerator for a stopped instance to the values specified in the request.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesSetMachineResourcesRequestResource = new InstancesSetMachineResourcesRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setMachineResources($instance, $instancesSetMachineResourcesRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setMachineResources($instance, $instancesSetMachineResourcesRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setMachineResources');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
instancesSetMachineResourcesRequestResource |
Google\Cloud\Compute\V1\InstancesSetMachineResourcesRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setMachineType
Changes the machine type for a stopped instance to the machine type specified in the request.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesSetMachineTypeRequestResource = new InstancesSetMachineTypeRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setMachineType($instance, $instancesSetMachineTypeRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setMachineType($instance, $instancesSetMachineTypeRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setMachineType');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
instancesSetMachineTypeRequestResource |
Google\Cloud\Compute\V1\InstancesSetMachineTypeRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setMetadata
Sets metadata for the specified instance to the data included in the request.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$metadataResource = new Metadata();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setMetadata($instance, $metadataResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setMetadata($instance, $metadataResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setMetadata');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
metadataResource |
Google\Cloud\Compute\V1\Metadata
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setMinCpuPlatform
Changes the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, read Specifying a Minimum CPU Platform.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesSetMinCpuPlatformRequestResource = new InstancesSetMinCpuPlatformRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setMinCpuPlatform($instance, $instancesSetMinCpuPlatformRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setMinCpuPlatform($instance, $instancesSetMinCpuPlatformRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setMinCpuPlatform');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
instancesSetMinCpuPlatformRequestResource |
Google\Cloud\Compute\V1\InstancesSetMinCpuPlatformRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setScheduling
Sets an instance's scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED
state. See Instance Life Cycle for more information on the possible instance states. For more information about setting scheduling options for a VM, see Set VM host maintenance policy.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$schedulingResource = new Scheduling();
$zone = 'zone';
$operationResponse = $instancesClient->setScheduling($instance, $project, $schedulingResource, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setScheduling($instance, $project, $schedulingResource, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setScheduling');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Instance name for this request. |
project |
string
Project ID for this request. |
schedulingResource |
Google\Cloud\Compute\V1\Scheduling
The body resource for this request |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setServiceAccount
Sets the service account on the instance. For more information, read Changing the service account and access scopes for an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesSetServiceAccountRequestResource = new InstancesSetServiceAccountRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->setServiceAccount($instance, $instancesSetServiceAccountRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setServiceAccount($instance, $instancesSetServiceAccountRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setServiceAccount');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to start. |
instancesSetServiceAccountRequestResource |
Google\Cloud\Compute\V1\InstancesSetServiceAccountRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
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.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$shieldedInstanceIntegrityPolicyResource = new ShieldedInstanceIntegrityPolicy();
$zone = 'zone';
$operationResponse = $instancesClient->setShieldedInstanceIntegrityPolicy($instance, $project, $shieldedInstanceIntegrityPolicyResource, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setShieldedInstanceIntegrityPolicy($instance, $project, $shieldedInstanceIntegrityPolicyResource, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setShieldedInstanceIntegrityPolicy');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name or id of the instance scoping this request. |
project |
string
Project ID for this request. |
shieldedInstanceIntegrityPolicyResource |
Google\Cloud\Compute\V1\ShieldedInstanceIntegrityPolicy
The body resource for this request |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setTags
Sets network tags for the specified instance to the data included in the request.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$tagsResource = new Tags();
$zone = 'zone';
$operationResponse = $instancesClient->setTags($instance, $project, $tagsResource, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->setTags($instance, $project, $tagsResource, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'setTags');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
tagsResource |
Google\Cloud\Compute\V1\Tags
The body resource for this request |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
simulateMaintenanceEvent
Simulates a host maintenance event on a VM. For more information, see Simulate a host maintenance event.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->simulateMaintenanceEvent($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->simulateMaintenanceEvent($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'simulateMaintenanceEvent');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
start
Starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->start($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->start($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'start');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to start. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
startWithEncryptionKey
Starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instancesStartWithEncryptionKeyRequestResource = new InstancesStartWithEncryptionKeyRequest();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->startWithEncryptionKey($instance, $instancesStartWithEncryptionKeyRequestResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->startWithEncryptionKey($instance, $instancesStartWithEncryptionKeyRequestResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'startWithEncryptionKey');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to start. |
instancesStartWithEncryptionKeyRequestResource |
Google\Cloud\Compute\V1\InstancesStartWithEncryptionKeyRequest
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
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, see Stopping an instance.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->stop($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->stop($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'stop');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to stop. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
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.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->suspend($instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->suspend($instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'suspend');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to suspend. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
testIamPermissions
Returns permissions that a caller has on the specified resource.
Sample code:
$instancesClient = new InstancesClient();
try {
$project = 'project';
$resource = 'resource';
$testPermissionsRequestResource = new TestPermissionsRequest();
$zone = 'zone';
$response = $instancesClient->testIamPermissions($project, $resource, $testPermissionsRequestResource, $zone);
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
project |
string
Project ID for this request. |
resource |
string
Name or id of the resource for this request. |
testPermissionsRequestResource |
Google\Cloud\Compute\V1\TestPermissionsRequest
The body resource for this request |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Compute\V1\TestPermissionsResponse |
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.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$instanceResource = new Instance();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->update($instance, $instanceResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->update($instance, $instanceResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'update');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name of the instance resource to update. |
instanceResource |
Google\Cloud\Compute\V1\Instance
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ minimalAction |
string
Specifies the action to take when updating an instance even if the updated properties do not require it. If not specified, then Compute Engine acts based on the minimum action that the updated properties require. Check the MinimalAction enum for the list of possible values. |
↳ mostDisruptiveAllowedAction |
string
Specifies the most disruptive action that can be taken on the instance as part of the update. Compute Engine returns an error if the instance properties require a more disruptive action as part of the instance update. Valid options from lowest to highest are NO_EFFECT, REFRESH, and RESTART. Check the MostDisruptiveAllowedAction enum for the list of possible values. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
updateAccessConfig
Updates the specified access config from an instance's network interface with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
Sample code:
$instancesClient = new InstancesClient();
try {
$accessConfigResource = new AccessConfig();
$instance = 'instance';
$networkInterface = 'network_interface';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->updateAccessConfig($accessConfigResource, $instance, $networkInterface, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->updateAccessConfig($accessConfigResource, $instance, $networkInterface, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'updateAccessConfig');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
accessConfigResource |
Google\Cloud\Compute\V1\AccessConfig
The body resource for this request |
instance |
string
The instance name for this request. |
networkInterface |
string
The name of the network interface where the access config is attached. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
updateDisplayDevice
Updates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
Sample code:
$instancesClient = new InstancesClient();
try {
$displayDeviceResource = new DisplayDevice();
$instance = 'instance';
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->updateDisplayDevice($displayDeviceResource, $instance, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->updateDisplayDevice($displayDeviceResource, $instance, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'updateDisplayDevice');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
displayDeviceResource |
Google\Cloud\Compute\V1\DisplayDevice
The body resource for this request |
instance |
string
Name of the instance scoping this request. |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
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.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$networkInterface = 'network_interface';
$networkInterfaceResource = new NetworkInterface();
$project = 'project';
$zone = 'zone';
$operationResponse = $instancesClient->updateNetworkInterface($instance, $networkInterface, $networkInterfaceResource, $project, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->updateNetworkInterface($instance, $networkInterface, $networkInterfaceResource, $project, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'updateNetworkInterface');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
The instance name for this request. |
networkInterface |
string
The name of the network interface to update. |
networkInterfaceResource |
Google\Cloud\Compute\V1\NetworkInterface
The body resource for this request |
project |
string
Project ID for this request. |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
updateShieldedInstanceConfig
Updates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules.
Sample code:
$instancesClient = new InstancesClient();
try {
$instance = 'instance';
$project = 'project';
$shieldedInstanceConfigResource = new ShieldedInstanceConfig();
$zone = 'zone';
$operationResponse = $instancesClient->updateShieldedInstanceConfig($instance, $project, $shieldedInstanceConfigResource, $zone);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $instancesClient->updateShieldedInstanceConfig($instance, $project, $shieldedInstanceConfigResource, $zone);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $instancesClient->resumeOperation($operationName, 'updateShieldedInstanceConfig');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// if creating/modifying, retrieve the target resource
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$instancesClient->close();
}
Parameters | |
---|---|
Name | Description |
instance |
string
Name or id of the instance scoping this request. |
project |
string
Project ID for this request. |
shieldedInstanceConfigResource |
Google\Cloud\Compute\V1\ShieldedInstanceConfig
The body resource for this request |
zone |
string
The name of the zone for this request. |
optionalArgs |
array
Optional. |
↳ requestId |
string
An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
Constants
SERVICE_NAME
Value: 'google.cloud.compute.v1.Instances'
The name of the service.
SERVICE_ADDRESS
Value: 'compute.googleapis.com'
The default address of the service.
DEFAULT_SERVICE_PORT
Value: 443
The default port of the service.
CODEGEN_NAME
Value: 'gapic'
The name of the code generator, to be included in the agent header.