diff --git a/compute/createInstance.js b/compute/createInstance.js index 44caeb7426..64eef1e3ed 100644 --- a/compute/createInstance.js +++ b/compute/createInstance.js @@ -83,19 +83,19 @@ function main( console.log(`Creating the ${instanceName} instance in ${zone}...`); - // Wait for the create operation to complete. - const [operation] = await instancesClient.insert({ + let [operation] = await instancesClient.insert({ instanceResource: instance, project: projectId, zone, }); - if (operation.status === 'RUNNING') { - const operationsClient = new compute.ZoneOperationsClient({ - fallback: 'rest', - }); + const operationsClient = new compute.ZoneOperationsClient({ + fallback: 'rest', + }); - await operationsClient.wait({ + // Wait for the create operation to complete. + while (operation.status !== 'DONE') { + [operation] = await operationsClient.wait({ operation: operation.name, project: projectId, zone: operation.zone.split('/').pop(), diff --git a/compute/deleteInstance.js b/compute/deleteInstance.js index b309926db2..b37eb4fb76 100644 --- a/compute/deleteInstance.js +++ b/compute/deleteInstance.js @@ -36,19 +36,19 @@ function main(projectId, zone, instanceName) { console.log(`Deleting ${instanceName} from ${zone}...`); - // Wait for the delete operation to complete. - const [operation] = await instancesClient.delete({ + let [operation] = await instancesClient.delete({ project: projectId, zone, instance: instanceName, }); - if (operation.status === 'RUNNING') { - const operationsClient = new compute.ZoneOperationsClient({ - fallback: 'rest', - }); + const operationsClient = new compute.ZoneOperationsClient({ + fallback: 'rest', + }); - await operationsClient.wait({ + // Wait for the delete operation to complete. + while (operation.status !== 'DONE') { + [operation] = await operationsClient.wait({ operation: operation.name, project: projectId, zone: operation.zone.split('/').pop(), diff --git a/compute/setUsageExportBucket.js b/compute/setUsageExportBucket.js index 0bbbc3033a..c0e6ad54a8 100644 --- a/compute/setUsageExportBucket.js +++ b/compute/setUsageExportBucket.js @@ -45,10 +45,21 @@ function main(projectId, bucketName, reportNamePrefix = '') { // Set the usage export location. const projectsClient = new compute.ProjectsClient({fallback: 'rest'}); - projectsClient.setUsageExportBucket({ + const operationsClient = new compute.GlobalOperationsClient({ + fallback: 'rest', + }); + + let [operation] = await projectsClient.setUsageExportBucket({ project: projectId, usageExportLocationResource, }); + + while (operation.status !== 'DONE') { + [operation] = await operationsClient.wait({ + operation: operation.name, + project: projectId, + }); + } } setUsageExportBucket(); diff --git a/compute/waitForOperation.js b/compute/waitForOperation.js index 3f27c67dfa..3cdfaf8222 100644 --- a/compute/waitForOperation.js +++ b/compute/waitForOperation.js @@ -28,15 +28,15 @@ function main(projectId, operationString) { const compute = require('@google-cloud/compute'); // Parse stringified operation to the object instance. - const operation = JSON.parse(operationString); + let operation = JSON.parse(operationString); async function waitForOperation() { - if (operation.status === 'RUNNING') { - const operationsClient = new compute.ZoneOperationsClient({ - fallback: 'rest', - }); + const operationsClient = new compute.ZoneOperationsClient({ + fallback: 'rest', + }); - await operationsClient.wait({ + while (operation.status !== 'DONE') { + [operation] = await operationsClient.wait({ operation: operation.name, project: projectId, zone: operation.zone.split('/').pop(),