Skip to content

Commit cb15d52

Browse files
FrodoTheTrueAce Nassri
authored and
Ace Nassri
committed
chore(compute): change LRO wrappers (#605)
1 parent c5e7042 commit cb15d52

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

compute/createInstance.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ function main(
8383

8484
console.log(`Creating the ${instanceName} instance in ${zone}...`);
8585

86-
// Wait for the create operation to complete.
87-
const [operation] = await instancesClient.insert({
86+
let [operation] = await instancesClient.insert({
8887
instanceResource: instance,
8988
project: projectId,
9089
zone,
9190
});
9291

93-
if (operation.status === 'RUNNING') {
94-
const operationsClient = new compute.ZoneOperationsClient({
95-
fallback: 'rest',
96-
});
92+
const operationsClient = new compute.ZoneOperationsClient({
93+
fallback: 'rest',
94+
});
9795

98-
await operationsClient.wait({
96+
// Wait for the create operation to complete.
97+
while (operation.status !== 'DONE') {
98+
[operation] = await operationsClient.wait({
9999
operation: operation.name,
100100
project: projectId,
101101
zone: operation.zone.split('/').pop(),

compute/deleteInstance.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ function main(projectId, zone, instanceName) {
3636

3737
console.log(`Deleting ${instanceName} from ${zone}...`);
3838

39-
// Wait for the delete operation to complete.
40-
const [operation] = await instancesClient.delete({
39+
let [operation] = await instancesClient.delete({
4140
project: projectId,
4241
zone,
4342
instance: instanceName,
4443
});
4544

46-
if (operation.status === 'RUNNING') {
47-
const operationsClient = new compute.ZoneOperationsClient({
48-
fallback: 'rest',
49-
});
45+
const operationsClient = new compute.ZoneOperationsClient({
46+
fallback: 'rest',
47+
});
5048

51-
await operationsClient.wait({
49+
// Wait for the delete operation to complete.
50+
while (operation.status !== 'DONE') {
51+
[operation] = await operationsClient.wait({
5252
operation: operation.name,
5353
project: projectId,
5454
zone: operation.zone.split('/').pop(),

compute/setUsageExportBucket.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,21 @@ function main(projectId, bucketName, reportNamePrefix = '') {
4545

4646
// Set the usage export location.
4747
const projectsClient = new compute.ProjectsClient({fallback: 'rest'});
48-
projectsClient.setUsageExportBucket({
48+
const operationsClient = new compute.GlobalOperationsClient({
49+
fallback: 'rest',
50+
});
51+
52+
let [operation] = await projectsClient.setUsageExportBucket({
4953
project: projectId,
5054
usageExportLocationResource,
5155
});
56+
57+
while (operation.status !== 'DONE') {
58+
[operation] = await operationsClient.wait({
59+
operation: operation.name,
60+
project: projectId,
61+
});
62+
}
5263
}
5364

5465
setUsageExportBucket();

compute/waitForOperation.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ function main(projectId, operationString) {
2828
const compute = require('@google-cloud/compute');
2929

3030
// Parse stringified operation to the object instance.
31-
const operation = JSON.parse(operationString);
31+
let operation = JSON.parse(operationString);
3232

3333
async function waitForOperation() {
34-
if (operation.status === 'RUNNING') {
35-
const operationsClient = new compute.ZoneOperationsClient({
36-
fallback: 'rest',
37-
});
34+
const operationsClient = new compute.ZoneOperationsClient({
35+
fallback: 'rest',
36+
});
3837

39-
await operationsClient.wait({
38+
while (operation.status !== 'DONE') {
39+
[operation] = await operationsClient.wait({
4040
operation: operation.name,
4141
project: projectId,
4242
zone: operation.zone.split('/').pop(),

0 commit comments

Comments
 (0)