Skip to content

Commit

Permalink
chore(compute): change LRO wrappers (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrodoTheTrue authored and Ace Nassri committed Nov 21, 2022
1 parent c5e7042 commit cb15d52
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
14 changes: 7 additions & 7 deletions compute/createInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
14 changes: 7 additions & 7 deletions compute/deleteInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 12 additions & 1 deletion compute/setUsageExportBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions compute/waitForOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit cb15d52

Please sign in to comment.