Skip to content

Commit 44924dc

Browse files
authored
chore: compute sample comments and readme updates (GoogleCloudPlatform#1377)
README.md and comments updates based on iX input.
1 parent a19a1b3 commit 44924dc

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

compute/cloud-client/instances/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ Instances for YOUR_PROJECT_ID (us-central1-a)
8282
- my-new-instance-name
8383
```
8484

85+
### List all instances
86+
87+
```
88+
$ php src/list_all_instances.php $YOUR_PROJECT_ID
89+
All instances for YOUR_PROJECT_ID
90+
Zone - zones/us-central1-a
91+
- my-new-instance-name
92+
Zone - zones/us-central1-b
93+
- my-new-instance-name-2
94+
- my-new-instance-name-3
95+
```
96+
8597
### Delete an instance
8698

8799
```

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333
use Google\Cloud\Compute\V1\ZoneOperationsClient;
3434

3535
/**
36-
* Creates an instance.
36+
* Create an instance in the specified project and zone.
3737
* Example:
3838
* ```
3939
* create_instance($projectId, $zone, $instanceName);
4040
* ```
4141
*
42-
* @param string $projectId Your Google Cloud project ID.
43-
* @param string $zone The zone to create the instance in (e.g. "us-central1-a").
44-
* @param string $instanceName The unique name for this Compute instance.
45-
* @param string $machineType Instance machine type.
42+
* @param string $projectId Project ID of the Cloud project to create the instance in.
43+
* @param string $zone Zone to create the instance in (like "us-central1-a").
44+
* @param string $instanceName Unique name for this Compute Engine instance.
45+
* @param string $machineType Machine type of the instance being created.
4646
* @param string $sourceImage Boot disk image name or family.
47-
* @param string $networkName The Compute instance ID.
47+
* @param string $networkName Network interface to associate with the instance.
4848
*
4949
* @throws \Google\ApiCore\ApiException if the remote call fails.
5050
*/
@@ -56,33 +56,33 @@ function create_instance(
5656
string $sourceImage = 'projects/debian-cloud/global/images/family/debian-10',
5757
string $networkName = 'global/networks/default'
5858
) {
59-
// Set the machine type using the specified zone
59+
// Set the machine type using the specified zone.
6060
$machineTypeFullName = sprintf('zones/%s/machineTypes/%s', $zone, $machineType);
6161

62-
// Set the boot disk
62+
// Describe the source image of the boot disk to attach to the instance.
6363
$diskInitializeParams = (new AttachedDiskInitializeParams())
6464
->setSourceImage($sourceImage);
6565
$disk = (new AttachedDisk())
6666
->setBoot(true)
6767
->setInitializeParams($diskInitializeParams);
6868

69-
// Set the network
69+
// Use the network interface provided in the $networkName argument.
7070
$network = (new NetworkInterface())
7171
->setName($networkName);
7272

73-
// Create the Instance message
73+
// Create the Instance object.
7474
$instance = (new Instance())
7575
->setName($instanceName)
7676
->setDisks([$disk])
7777
->setMachineType($machineTypeFullName)
7878
->setNetworkInterfaces([$network]);
7979

80-
// Insert the new Compute Engine instance using the InstancesClient
80+
// Insert the new Compute Engine instance using InstancesClient.
8181
$instancesClient = new InstancesClient();
8282
$operation = $instancesClient->insert($instance, $projectId, $zone);
8383

84+
// Wait for the create operation to complete.
8485
if ($operation->getStatus() === Operation\Status::RUNNING) {
85-
// Wait until operation completes
8686
$operationClient = new ZoneOperationsClient();
8787
$operationClient->wait($operation->getName(), $projectId, $zone);
8888
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
# [END compute_instances_operation_check]
3333

3434
/**
35-
* Creates an instance.
35+
* Delete an instance.
3636
* Example:
3737
* ```
3838
* delete_instance($projectId, $zone, $instanceName);
3939
* ```
4040
*
4141
* @param string $projectId Your Google Cloud project ID.
42-
* @param string $zone The zone to delete the instance in (e.g. "us-central1-a").
43-
* @param string $instanceName The unique name for the Compute instance to delete.
42+
* @param string $zone Zone where the instance you want to delete is (like "us-central1-a").
43+
* @param string $instanceName Unique name for the Compute instance to delete.
4444
*
4545
* @throws \Google\ApiCore\ApiException if the remote call fails.
4646
*/
@@ -49,16 +49,16 @@ function delete_instance(
4949
string $zone,
5050
string $instanceName
5151
) {
52-
// Delete the Compute Engine instance using the InstancesClient
52+
// Delete the Compute Engine instance using InstancesClient.
5353
$instancesClient = new InstancesClient();
5454
$operation = $instancesClient->delete($instanceName, $projectId, $zone);
5555

5656
# [START compute_instances_operation_check]
5757
if ($operation->getStatus() === Operation\Status::RUNNING) {
58-
// Wait until operation completes
58+
// Wait for the operation to complete.
5959
$operationClient = new ZoneOperationsClient();
6060

61-
// Default timeout of 60s is not always enough for operation to finish,
61+
// Default timeout of 60 s is not always enough for operation to finish,
6262
// to avoid an exception we set timeout to 180000 ms = 180 s = 3 minutes
6363
$optionalArgs = ['timeoutMillis' => 180000];
6464
$operationClient->wait($operation->getName(), $projectId, $zone, $optionalArgs);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use Google\Cloud\Compute\V1\InstancesClient;
2828

2929
/**
30-
* List all instances for particular $projectId
30+
* List all instances for a particular Cloud project.
3131
* Example:
3232
* ```
3333
* list_all_instances($projectId);
@@ -39,7 +39,7 @@
3939
*/
4040
function list_all_instances(string $projectId)
4141
{
42-
// List the new Compute Engine instance using the InstancesClient
42+
// List Compute Engine instances using InstancesClient.
4343
$instancesClient = new InstancesClient();
4444
$allInstances = $instancesClient->aggregatedList($projectId);
4545

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@
2727
use Google\Cloud\Compute\V1\InstancesClient;
2828

2929
/**
30-
* List instances for particular $projectId and $zone
30+
* List all instances for a particular Cloud project and zone.
3131
* Example:
3232
* ```
3333
* list_instances($projectId, $zone);
3434
* ```
3535
*
3636
* @param string $projectId Your Google Cloud project ID.
37-
* @param string $zone The zone to list the instance in (e.g. "us-central1-a").
37+
* @param string $zone Zone to list instances for (like "us-central1-a").
3838
*
3939
* @throws \Google\ApiCore\ApiException if the remote call fails.
4040
*/
4141
function list_instances(string $projectId, string $zone)
4242
{
43-
// List the new Compute Engine instance using the InstancesClient
43+
// List Compute Engine instances using InstancesClient.
4444
$instancesClient = new InstancesClient();
4545
$instancesList = $instancesClient->list($projectId, $zone);
4646

0 commit comments

Comments
 (0)