Reference documentation and code samples for the Google Cloud Tpu V2 Client class TpuClient.
Service Description: Manages TPU nodes and other resources
TPU API v2
This class provides the ability to make remote calls to the backing service through method calls that map to API methods.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
Namespace
Google \ Cloud \ Tpu \ V2 \ ClientMethods
__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 Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper 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 Google\ApiCore\CredentialsWrapper::build() . |
↳ 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. May be either the string |
↳ 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 = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods 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. |
createNode
Creates a node.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::createNodeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\CreateNodeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\CreateNodeRequest;
use Google\Cloud\Tpu\V2\Node;
use Google\Rpc\Status;
/**
* @param string $formattedParent The parent resource name. Please see
* {@see TpuClient::locationName()} for help formatting this field.
* @param string $nodeRuntimeVersion The runtime version running in the Node.
*/
function create_node_sample(string $formattedParent, string $nodeRuntimeVersion): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$node = (new Node())
->setRuntimeVersion($nodeRuntimeVersion);
$request = (new CreateNodeRequest())
->setParent($formattedParent)
->setNode($node);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $tpuClient->createNode($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Node $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TpuClient::locationName('[PROJECT]', '[LOCATION]');
$nodeRuntimeVersion = '[RUNTIME_VERSION]';
create_node_sample($formattedParent, $nodeRuntimeVersion);
}
deleteNode
Deletes a node.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::deleteNodeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\DeleteNodeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\DeleteNodeRequest;
use Google\Rpc\Status;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::nodeName()} for help formatting this field.
*/
function delete_node_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new DeleteNodeRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $tpuClient->deleteNode($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::nodeName('[PROJECT]', '[LOCATION]', '[NODE]');
delete_node_sample($formattedName);
}
generateServiceIdentity
Generates the Cloud TPU service identity for the project.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::generateServiceIdentityAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GenerateServiceIdentityRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Tpu\V2\GenerateServiceIdentityResponse |
use Google\ApiCore\ApiException;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\GenerateServiceIdentityRequest;
use Google\Cloud\Tpu\V2\GenerateServiceIdentityResponse;
/**
* @param string $formattedParent The parent resource name. Please see
* {@see TpuClient::locationName()} for help formatting this field.
*/
function generate_service_identity_sample(string $formattedParent): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new GenerateServiceIdentityRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var GenerateServiceIdentityResponse $response */
$response = $tpuClient->generateServiceIdentity($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TpuClient::locationName('[PROJECT]', '[LOCATION]');
generate_service_identity_sample($formattedParent);
}
getAcceleratorType
Gets AcceleratorType.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::getAcceleratorTypeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetAcceleratorTypeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Tpu\V2\AcceleratorType |
use Google\ApiCore\ApiException;
use Google\Cloud\Tpu\V2\AcceleratorType;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\GetAcceleratorTypeRequest;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::acceleratorTypeName()} for help formatting this field.
*/
function get_accelerator_type_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new GetAcceleratorTypeRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var AcceleratorType $response */
$response = $tpuClient->getAcceleratorType($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::acceleratorTypeName('[PROJECT]', '[LOCATION]', '[ACCELERATOR_TYPE]');
get_accelerator_type_sample($formattedName);
}
getGuestAttributes
Retrieves the guest attributes for the node.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::getGuestAttributesAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetGuestAttributesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Tpu\V2\GetGuestAttributesResponse |
use Google\ApiCore\ApiException;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\GetGuestAttributesRequest;
use Google\Cloud\Tpu\V2\GetGuestAttributesResponse;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::nodeName()} for help formatting this field.
*/
function get_guest_attributes_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new GetGuestAttributesRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var GetGuestAttributesResponse $response */
$response = $tpuClient->getGuestAttributes($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::nodeName('[PROJECT]', '[LOCATION]', '[NODE]');
get_guest_attributes_sample($formattedName);
}
getNode
Gets the details of a node.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::getNodeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetNodeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Tpu\V2\Node |
use Google\ApiCore\ApiException;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\GetNodeRequest;
use Google\Cloud\Tpu\V2\Node;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::nodeName()} for help formatting this field.
*/
function get_node_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new GetNodeRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Node $response */
$response = $tpuClient->getNode($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::nodeName('[PROJECT]', '[LOCATION]', '[NODE]');
get_node_sample($formattedName);
}
getRuntimeVersion
Gets a runtime version.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::getRuntimeVersionAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetRuntimeVersionRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Tpu\V2\RuntimeVersion |
use Google\ApiCore\ApiException;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\GetRuntimeVersionRequest;
use Google\Cloud\Tpu\V2\RuntimeVersion;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::runtimeVersionName()} for help formatting this field.
*/
function get_runtime_version_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new GetRuntimeVersionRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var RuntimeVersion $response */
$response = $tpuClient->getRuntimeVersion($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::runtimeVersionName('[PROJECT]', '[LOCATION]', '[RUNTIME_VERSION]');
get_runtime_version_sample($formattedName);
}
listAcceleratorTypes
Lists accelerator types supported by this API.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::listAcceleratorTypesAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\ListAcceleratorTypesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Tpu\V2\AcceleratorType;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\ListAcceleratorTypesRequest;
/**
* @param string $formattedParent The parent resource name. Please see
* {@see TpuClient::locationName()} for help formatting this field.
*/
function list_accelerator_types_sample(string $formattedParent): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new ListAcceleratorTypesRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $tpuClient->listAcceleratorTypes($request);
/** @var AcceleratorType $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TpuClient::locationName('[PROJECT]', '[LOCATION]');
list_accelerator_types_sample($formattedParent);
}
listNodes
Lists nodes.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::listNodesAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\ListNodesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\ListNodesRequest;
use Google\Cloud\Tpu\V2\Node;
/**
* @param string $formattedParent The parent resource name. Please see
* {@see TpuClient::locationName()} for help formatting this field.
*/
function list_nodes_sample(string $formattedParent): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new ListNodesRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $tpuClient->listNodes($request);
/** @var Node $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TpuClient::locationName('[PROJECT]', '[LOCATION]');
list_nodes_sample($formattedParent);
}
listRuntimeVersions
Lists runtime versions supported by this API.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::listRuntimeVersionsAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\ListRuntimeVersionsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\ListRuntimeVersionsRequest;
use Google\Cloud\Tpu\V2\RuntimeVersion;
/**
* @param string $formattedParent The parent resource name. Please see
* {@see TpuClient::locationName()} for help formatting this field.
*/
function list_runtime_versions_sample(string $formattedParent): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new ListRuntimeVersionsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $tpuClient->listRuntimeVersions($request);
/** @var RuntimeVersion $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TpuClient::locationName('[PROJECT]', '[LOCATION]');
list_runtime_versions_sample($formattedParent);
}
startNode
Starts a node.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::startNodeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\StartNodeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\Node;
use Google\Cloud\Tpu\V2\StartNodeRequest;
use Google\Rpc\Status;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::nodeName()} for help formatting this field.
*/
function start_node_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new StartNodeRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $tpuClient->startNode($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Node $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::nodeName('[PROJECT]', '[LOCATION]', '[NODE]');
start_node_sample($formattedName);
}
stopNode
Stops a node. This operation is only available with single TPU nodes.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::stopNodeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\StopNodeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\Node;
use Google\Cloud\Tpu\V2\StopNodeRequest;
use Google\Rpc\Status;
/**
* @param string $formattedName The resource name. Please see
* {@see TpuClient::nodeName()} for help formatting this field.
*/
function stop_node_sample(string $formattedName): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = (new StopNodeRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $tpuClient->stopNode($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Node $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TpuClient::nodeName('[PROJECT]', '[LOCATION]', '[NODE]');
stop_node_sample($formattedName);
}
updateNode
Updates the configurations of a node.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::updateNodeAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\UpdateNodeRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Tpu\V2\Client\TpuClient;
use Google\Cloud\Tpu\V2\Node;
use Google\Cloud\Tpu\V2\UpdateNodeRequest;
use Google\Protobuf\FieldMask;
use Google\Rpc\Status;
/**
* @param string $nodeRuntimeVersion The runtime version running in the Node.
*/
function update_node_sample(string $nodeRuntimeVersion): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$updateMask = new FieldMask();
$node = (new Node())
->setRuntimeVersion($nodeRuntimeVersion);
$request = (new UpdateNodeRequest())
->setUpdateMask($updateMask)
->setNode($node);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $tpuClient->updateNode($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Node $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$nodeRuntimeVersion = '[RUNTIME_VERSION]';
update_node_sample($nodeRuntimeVersion);
}
getLocation
Gets information about a location.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::getLocationAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Location\Location |
use Google\ApiCore\ApiException;
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Tpu\V2\Client\TpuClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function get_location_sample(): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = new GetLocationRequest();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $tpuClient->getLocation($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
listLocations
Lists information about the supported locations for this service.
The async variant is Google\Cloud\Tpu\V2\Client\TpuClient::listLocationsAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Tpu\V2\Client\TpuClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function list_locations_sample(): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$request = new ListLocationsRequest();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $tpuClient->listLocations($request);
/** @var Location $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
createNodeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\CreateNodeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
deleteNodeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\DeleteNodeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
generateServiceIdentityAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GenerateServiceIdentityRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getAcceleratorTypeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetAcceleratorTypeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getGuestAttributesAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetGuestAttributesRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getNodeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetNodeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getRuntimeVersionAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\GetRuntimeVersionRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
listAcceleratorTypesAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\ListAcceleratorTypesRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
listNodesAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\ListNodesRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
listRuntimeVersionsAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\ListRuntimeVersionsRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
startNodeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\StartNodeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
stopNodeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\StopNodeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
updateNodeAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Tpu\V2\UpdateNodeRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getLocationAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Location\GetLocationRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
listLocationsAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Location\ListLocationsRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
Returns | |
---|---|
Type | Description |
Google\ApiCore\LongRunning\OperationsClient |
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 |
static::acceleratorTypeName
Formats a string containing the fully-qualified path to represent a accelerator_type resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
acceleratorType |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted accelerator_type resource. |
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted location resource. |
static::nodeName
Formats a string containing the fully-qualified path to represent a node resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
node |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted node resource. |
static::runtimeVersionName
Formats a string containing the fully-qualified path to represent a runtime_version resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
runtimeVersion |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted runtime_version resource. |
static::parseName
Parses a formatted name string and returns an associative array of the components in the name.
The following name formats are supported: Template: Pattern
- acceleratorType: projects/{project}/locations/{location}/acceleratorTypes/{accelerator_type}
- location: projects/{project}/locations/{location}
- node: projects/{project}/locations/{location}/nodes/{node}
- runtimeVersion: projects/{project}/locations/{location}/runtimeVersions/{runtime_version}
The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.
Parameters | |
---|---|
Name | Description |
formattedName |
string
The formatted name string |
template |
string
Optional name of template to match |
Returns | |
---|---|
Type | Description |
array |
An associative array from name component IDs to component values. |