Skip to content

Commit 41ae641

Browse files
authored
add LRO to compute samples (GoogleCloudPlatform#1358)
1 parent 6d8ba78 commit 41ae641

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

compute/cloud-client/instances/src/create_instance.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Google\Cloud\Compute\V1\AttachedDiskInitializeParams;
2929
use Google\Cloud\Compute\V1\Instance;
3030
use Google\Cloud\Compute\V1\NetworkInterface;
31+
use Google\Cloud\Compute\V1\ZoneOperationsClient;
3132

3233
/**
3334
* Creates an instance.
@@ -76,7 +77,11 @@ function create_instance(
7677
$instancesClient = new InstancesClient();
7778
$operation = $instancesClient->insert($instance, $projectId, $zone);
7879

79-
/** TODO: wait until operation completes */
80+
if ($operation->getStatus() === 'RUNNING') {
81+
// Wait until operation completes
82+
$operationClient = new ZoneOperationsClient();
83+
$operationClient->wait($operation->getName(), $projectId, $zone);
84+
}
8085

8186
printf('Created instance %s' . PHP_EOL, $instanceName);
8287
}

compute/cloud-client/instances/src/delete_instance.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace Google\Cloud\Samples\Compute;
2525

2626
use Google\Cloud\Compute\V1\InstancesClient;
27+
use Google\Cloud\Compute\V1\ZoneOperationsClient;
2728

2829
/**
2930
* Creates an instance.
@@ -45,7 +46,11 @@ function delete_instance(
4546
$instancesClient = new InstancesClient();
4647
$operation = $instancesClient->delete($instanceName, $projectId, $zone);
4748

48-
/** TODO: wait until operation completes */
49+
if ($operation->getStatus() === 'RUNNING') {
50+
// Wait until operation completes
51+
$operationClient = new ZoneOperationsClient();
52+
$operationClient->wait($operation->getName(), $projectId, $zone);
53+
}
4954

5055
printf('Deleted instance %s' . PHP_EOL, $instanceName);
5156
}

0 commit comments

Comments
 (0)