Skip to content

Commit

Permalink
docs(Compute): update samples to use new surface (#7907)
Browse files Browse the repository at this point in the history
updates after rebase
  • Loading branch information
bshaffer authored Dec 11, 2024
1 parent b1019a6 commit e6f8670
Show file tree
Hide file tree
Showing 877 changed files with 8,090 additions and 2,984 deletions.
9 changes: 7 additions & 2 deletions Compute/samples/V1/AcceleratorTypesClient/aggregated_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_AcceleratorTypes_AggregatedList_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Compute\V1\AcceleratorTypesClient;
use Google\Cloud\Compute\V1\AggregatedListAcceleratorTypesRequest;
use Google\Cloud\Compute\V1\Client\AcceleratorTypesClient;

/**
* Retrieves an aggregated list of accelerator types. To prevent failure, Google recommends that you set the `returnPartialSuccess` parameter to `true`.
Expand All @@ -37,10 +38,14 @@ function aggregated_list_sample(string $project): void
// Create a client.
$acceleratorTypesClient = new AcceleratorTypesClient();

// Prepare the request message.
$request = (new AggregatedListAcceleratorTypesRequest())
->setProject($project);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $acceleratorTypesClient->aggregatedList($project);
$response = $acceleratorTypesClient->aggregatedList($request);

foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
Expand Down
11 changes: 9 additions & 2 deletions Compute/samples/V1/AcceleratorTypesClient/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_AcceleratorTypes_Get_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Compute\V1\AcceleratorType;
use Google\Cloud\Compute\V1\AcceleratorTypesClient;
use Google\Cloud\Compute\V1\Client\AcceleratorTypesClient;
use Google\Cloud\Compute\V1\GetAcceleratorTypeRequest;

/**
* Returns the specified accelerator type.
Expand All @@ -39,10 +40,16 @@ function get_sample(string $acceleratorType, string $project, string $zone): voi
// Create a client.
$acceleratorTypesClient = new AcceleratorTypesClient();

// Prepare the request message.
$request = (new GetAcceleratorTypeRequest())
->setAcceleratorType($acceleratorType)
->setProject($project)
->setZone($zone);

// Call the API and handle any network failures.
try {
/** @var AcceleratorType $response */
$response = $acceleratorTypesClient->get($acceleratorType, $project, $zone);
$response = $acceleratorTypesClient->get($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
Expand Down
10 changes: 8 additions & 2 deletions Compute/samples/V1/AcceleratorTypesClient/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_AcceleratorTypes_List_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Compute\V1\AcceleratorTypesClient;
use Google\Cloud\Compute\V1\Client\AcceleratorTypesClient;
use Google\Cloud\Compute\V1\ListAcceleratorTypesRequest;

/**
* Retrieves a list of accelerator types that are available to the specified project.
Expand All @@ -38,10 +39,15 @@ function list_sample(string $project, string $zone): void
// Create a client.
$acceleratorTypesClient = new AcceleratorTypesClient();

// Prepare the request message.
$request = (new ListAcceleratorTypesRequest())
->setProject($project)
->setZone($zone);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $acceleratorTypesClient->list($project, $zone);
$response = $acceleratorTypesClient->list($request);

foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
Expand Down
9 changes: 7 additions & 2 deletions Compute/samples/V1/AddressesClient/aggregated_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Addresses_AggregatedList_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\AggregatedListAddressesRequest;
use Google\Cloud\Compute\V1\Client\AddressesClient;

/**
* Retrieves an aggregated list of addresses. To prevent failure, Google recommends that you set the `returnPartialSuccess` parameter to `true`.
Expand All @@ -37,10 +38,14 @@ function aggregated_list_sample(string $project): void
// Create a client.
$addressesClient = new AddressesClient();

// Prepare the request message.
$request = (new AggregatedListAddressesRequest())
->setProject($project);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $addressesClient->aggregatedList($project);
$response = $addressesClient->aggregatedList($request);

foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
Expand Down
11 changes: 9 additions & 2 deletions Compute/samples/V1/AddressesClient/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Addresses_Delete_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\Client\AddressesClient;
use Google\Cloud\Compute\V1\DeleteAddressRequest;
use Google\Rpc\Status;

/**
Expand All @@ -40,10 +41,16 @@ function delete_sample(string $address, string $project, string $region): void
// Create a client.
$addressesClient = new AddressesClient();

// Prepare the request message.
$request = (new DeleteAddressRequest())
->setAddress($address)
->setProject($project)
->setRegion($region);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $addressesClient->delete($address, $project, $region);
$response = $addressesClient->delete($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
11 changes: 9 additions & 2 deletions Compute/samples/V1/AddressesClient/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Addresses_Get_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Compute\V1\Address;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\Client\AddressesClient;
use Google\Cloud\Compute\V1\GetAddressRequest;

/**
* Returns the specified address resource.
Expand All @@ -39,10 +40,16 @@ function get_sample(string $address, string $project, string $region): void
// Create a client.
$addressesClient = new AddressesClient();

// Prepare the request message.
$request = (new GetAddressRequest())
->setAddress($address)
->setProject($project)
->setRegion($region);

// Call the API and handle any network failures.
try {
/** @var Address $response */
$response = $addressesClient->get($address, $project, $region);
$response = $addressesClient->get($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
Expand Down
11 changes: 8 additions & 3 deletions Compute/samples/V1/AddressesClient/insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Compute\V1\Address;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\Client\AddressesClient;
use Google\Cloud\Compute\V1\InsertAddressRequest;
use Google\Rpc\Status;

/**
Expand All @@ -40,13 +41,17 @@ function insert_sample(string $project, string $region): void
// Create a client.
$addressesClient = new AddressesClient();

// Prepare any non-scalar elements to be passed along with the request.
// Prepare the request message.
$addressResource = new Address();
$request = (new InsertAddressRequest())
->setAddressResource($addressResource)
->setProject($project)
->setRegion($region);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $addressesClient->insert($addressResource, $project, $region);
$response = $addressesClient->insert($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
10 changes: 8 additions & 2 deletions Compute/samples/V1/AddressesClient/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Addresses_List_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\Client\AddressesClient;
use Google\Cloud\Compute\V1\ListAddressesRequest;

/**
* Retrieves a list of addresses contained within the specified region.
Expand All @@ -38,10 +39,15 @@ function list_sample(string $project, string $region): void
// Create a client.
$addressesClient = new AddressesClient();

// Prepare the request message.
$request = (new ListAddressesRequest())
->setProject($project)
->setRegion($region);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $addressesClient->list($project, $region);
$response = $addressesClient->list($request);

foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
Expand Down
17 changes: 9 additions & 8 deletions Compute/samples/V1/AddressesClient/move.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Addresses_Move_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\Client\AddressesClient;
use Google\Cloud\Compute\V1\MoveAddressRequest;
use Google\Cloud\Compute\V1\RegionAddressesMoveRequest;
use Google\Rpc\Status;

Expand All @@ -41,18 +42,18 @@ function move_sample(string $address, string $project, string $region): void
// Create a client.
$addressesClient = new AddressesClient();

// Prepare any non-scalar elements to be passed along with the request.
// Prepare the request message.
$regionAddressesMoveRequestResource = new RegionAddressesMoveRequest();
$request = (new MoveAddressRequest())
->setAddress($address)
->setProject($project)
->setRegion($region)
->setRegionAddressesMoveRequestResource($regionAddressesMoveRequestResource);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $addressesClient->move(
$address,
$project,
$region,
$regionAddressesMoveRequestResource
);
$response = $addressesClient->move($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
17 changes: 9 additions & 8 deletions Compute/samples/V1/AddressesClient/set_labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
// [START compute_v1_generated_Addresses_SetLabels_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Compute\V1\AddressesClient;
use Google\Cloud\Compute\V1\Client\AddressesClient;
use Google\Cloud\Compute\V1\RegionSetLabelsRequest;
use Google\Cloud\Compute\V1\SetLabelsAddressRequest;
use Google\Rpc\Status;

/**
Expand All @@ -41,18 +42,18 @@ function set_labels_sample(string $project, string $region, string $resource): v
// Create a client.
$addressesClient = new AddressesClient();

// Prepare any non-scalar elements to be passed along with the request.
// Prepare the request message.
$regionSetLabelsRequestResource = new RegionSetLabelsRequest();
$request = (new SetLabelsAddressRequest())
->setProject($project)
->setRegion($region)
->setRegionSetLabelsRequestResource($regionSetLabelsRequestResource)
->setResource($resource);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $addressesClient->setLabels(
$project,
$region,
$regionSetLabelsRequestResource,
$resource
);
$response = $addressesClient->setLabels($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
9 changes: 7 additions & 2 deletions Compute/samples/V1/AutoscalersClient/aggregated_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Autoscalers_AggregatedList_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Compute\V1\AutoscalersClient;
use Google\Cloud\Compute\V1\AggregatedListAutoscalersRequest;
use Google\Cloud\Compute\V1\Client\AutoscalersClient;

/**
* Retrieves an aggregated list of autoscalers. To prevent failure, Google recommends that you set the `returnPartialSuccess` parameter to `true`.
Expand All @@ -37,10 +38,14 @@ function aggregated_list_sample(string $project): void
// Create a client.
$autoscalersClient = new AutoscalersClient();

// Prepare the request message.
$request = (new AggregatedListAutoscalersRequest())
->setProject($project);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $autoscalersClient->aggregatedList($project);
$response = $autoscalersClient->aggregatedList($request);

foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
Expand Down
11 changes: 9 additions & 2 deletions Compute/samples/V1/AutoscalersClient/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Autoscalers_Delete_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Compute\V1\AutoscalersClient;
use Google\Cloud\Compute\V1\Client\AutoscalersClient;
use Google\Cloud\Compute\V1\DeleteAutoscalerRequest;
use Google\Rpc\Status;

/**
Expand All @@ -40,10 +41,16 @@ function delete_sample(string $autoscaler, string $project, string $zone): void
// Create a client.
$autoscalersClient = new AutoscalersClient();

// Prepare the request message.
$request = (new DeleteAutoscalerRequest())
->setAutoscaler($autoscaler)
->setProject($project)
->setZone($zone);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $autoscalersClient->delete($autoscaler, $project, $zone);
$response = $autoscalersClient->delete($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
11 changes: 9 additions & 2 deletions Compute/samples/V1/AutoscalersClient/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START compute_v1_generated_Autoscalers_Get_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Compute\V1\Autoscaler;
use Google\Cloud\Compute\V1\AutoscalersClient;
use Google\Cloud\Compute\V1\Client\AutoscalersClient;
use Google\Cloud\Compute\V1\GetAutoscalerRequest;

/**
* Returns the specified autoscaler resource.
Expand All @@ -39,10 +40,16 @@ function get_sample(string $autoscaler, string $project, string $zone): void
// Create a client.
$autoscalersClient = new AutoscalersClient();

// Prepare the request message.
$request = (new GetAutoscalerRequest())
->setAutoscaler($autoscaler)
->setProject($project)
->setZone($zone);

// Call the API and handle any network failures.
try {
/** @var Autoscaler $response */
$response = $autoscalersClient->get($autoscaler, $project, $zone);
$response = $autoscalersClient->get($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
Expand Down
Loading

0 comments on commit e6f8670

Please sign in to comment.