Reference documentation and code samples for the Google Cloud Tpu V2 Client class TpuClient.
Service Description: Manages TPU nodes and other resources
This class is currently experimental and may be subject to changes.
Namespace
Google \ Cloud \ Tpu \ V2 \ ClientMethods
__construct
Constructor.
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 false
.
↳ 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 rest
or grpc
. Defaults to grpc
if gRPC support is detected on the system. Advanced usage
: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface
object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.
↳ 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\BaseClient\self::createNodeAsync() .
request
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.
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 $nodeAcceleratorType The type of hardware accelerators associated with this node.
* @param string $nodeRuntimeVersion The runtime version running in the Node.
*/
function create_node_sample(
string $formattedParent,
string $nodeAcceleratorType,
string $nodeRuntimeVersion
): void {
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$node = (new Node())
->setAcceleratorType($nodeAcceleratorType)
->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]');
$nodeAcceleratorType = '[ACCELERATOR_TYPE]';
$nodeRuntimeVersion = '[RUNTIME_VERSION]';
create_node_sample($formattedParent, $nodeAcceleratorType, $nodeRuntimeVersion);
}
deleteNode
Deletes a node.
The async variant is Google\Cloud\Tpu\V2\Client\BaseClient\self::deleteNodeAsync() .
request
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.
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\BaseClient\self::generateServiceIdentityAsync() .
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.
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\BaseClient\self::getAcceleratorTypeAsync() .
request
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.
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\BaseClient\self::getGuestAttributesAsync() .
request
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.
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\BaseClient\self::getNodeAsync() .
request
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.
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\BaseClient\self::getRuntimeVersionAsync() .
request
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.
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\BaseClient\self::listAcceleratorTypesAsync() .
request
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.
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\BaseClient\self::listNodesAsync() .
request
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.
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\BaseClient\self::listRuntimeVersionsAsync() .
request
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.
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\BaseClient\self::startNodeAsync() .
request
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.
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\BaseClient\self::stopNodeAsync() .
request
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.
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\BaseClient\self::updateNodeAsync() .
request
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.
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 $nodeAcceleratorType The type of hardware accelerators associated with this node.
* @param string $nodeRuntimeVersion The runtime version running in the Node.
*/
function update_node_sample(string $nodeAcceleratorType, string $nodeRuntimeVersion): void
{
// Create a client.
$tpuClient = new TpuClient();
// Prepare the request message.
$updateMask = new FieldMask();
$node = (new Node())
->setAcceleratorType($nodeAcceleratorType)
->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
{
$nodeAcceleratorType = '[ACCELERATOR_TYPE]';
$nodeRuntimeVersion = '[RUNTIME_VERSION]';
update_node_sample($nodeAcceleratorType, $nodeRuntimeVersion);
}
getLocation
Gets information about a location.
The async variant is Google\Cloud\Tpu\V2\Client\BaseClient\self::getLocationAsync() .
request
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.
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\BaseClient\self::listLocationsAsync() .
request
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.
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
GuzzleHttp\Promise\PromiseInterface
deleteNodeAsync
GuzzleHttp\Promise\PromiseInterface
generateServiceIdentityAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
getAcceleratorTypeAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
getGuestAttributesAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
getNodeAsync
GuzzleHttp\Promise\PromiseInterface
getRuntimeVersionAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
listAcceleratorTypesAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
listNodesAsync
GuzzleHttp\Promise\PromiseInterface
listRuntimeVersionsAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
startNodeAsync
GuzzleHttp\Promise\PromiseInterface
stopNodeAsync
GuzzleHttp\Promise\PromiseInterface
updateNodeAsync
GuzzleHttp\Promise\PromiseInterface
getLocationAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
listLocationsAsync
optionalArgs = []
array
GuzzleHttp\Promise\PromiseInterface
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
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.
operationName
string
The name of the long running operation
methodName
string
The name of the method used to start the operation
static::acceleratorTypeName
Formats a string containing the fully-qualified path to represent a accelerator_type resource.
project
string
location
string
acceleratorType
string
string
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
project
string
location
string
string
static::nodeName
Formats a string containing the fully-qualified path to represent a node resource.
project
string
location
string
node
string
string
static::runtimeVersionName
Formats a string containing the fully-qualified path to represent a runtime_version resource.
project
string
location
string
runtimeVersion
string
string
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.
formattedName
string
The formatted name string
template
string
Optional name of template to match
array