File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
compute/cloud-client/instances/src Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 2828use Google \Cloud \Compute \V1 \AttachedDiskInitializeParams ;
2929use Google \Cloud \Compute \V1 \Instance ;
3030use 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}
Original file line number Diff line number Diff line change 2424namespace Google \Cloud \Samples \Compute ;
2525
2626use 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}
You can’t perform that action at this time.
0 commit comments