diff --git a/compute/createInstance.js b/compute/createInstance.js index 64eef1e3ed..c9b32a815e 100644 --- a/compute/createInstance.js +++ b/compute/createInstance.js @@ -52,46 +52,42 @@ function main( // const networkName = 'global/networks/default'; const compute = require('@google-cloud/compute'); - const compute_protos = compute.protos.google.cloud.compute.v1; + const computeProtos = compute.protos.google.cloud.compute.v1; // Create a new instance with the values provided above in the specified project and zone. async function createInstance() { - const instancesClient = new compute.InstancesClient({fallback: 'rest'}); - - // Describe the size and source image of the boot disk to attach to the instance. - const attachedDisk = new compute_protos.AttachedDisk(); - const initializeParams = new compute_protos.AttachedDiskInitializeParams(); - - initializeParams.diskSizeGb = '10'; - initializeParams.sourceImage = sourceImage; - - attachedDisk.initializeParams = initializeParams; - attachedDisk.autoDelete = true; - attachedDisk.boot = true; - attachedDisk.type = compute_protos.AttachedDisk.Type.PERSISTENT; - - // Use the network interface provided in the networkName argument. - const networkInterface = new compute_protos.NetworkInterface(); - networkInterface.name = networkName; - - // Collect information into the Instance object. - const instance = new compute_protos.Instance(); - instance.name = instanceName; - instance.disks = [attachedDisk]; - instance.machineType = `zones/${zone}/machineTypes/${machineType}`; - instance.networkInterfaces = [networkInterface]; + const instancesClient = new compute.InstancesClient(); console.log(`Creating the ${instanceName} instance in ${zone}...`); let [operation] = await instancesClient.insert({ - instanceResource: instance, + instanceResource: { + name: instanceName, + disks: [ + { + // Describe the size and source image of the boot disk to attach to the instance. + initializeParams: { + diskSizeGb: '10', + sourceImage, + }, + autoDelete: true, + boot: true, + type: computeProtos.AttachedDisk.Type.PERSISTENT, + }, + ], + machineType: `zones/${zone}/machineTypes/${machineType}`, + networkInterfaces: [ + { + // Use the network interface provided in the networkName argument. + name: networkName, + }, + ], + }, project: projectId, zone, }); - const operationsClient = new compute.ZoneOperationsClient({ - fallback: 'rest', - }); + const operationsClient = new compute.ZoneOperationsClient(); // Wait for the create operation to complete. while (operation.status !== 'DONE') { diff --git a/compute/deleteInstance.js b/compute/deleteInstance.js index b37eb4fb76..bd1a4858d0 100644 --- a/compute/deleteInstance.js +++ b/compute/deleteInstance.js @@ -32,7 +32,7 @@ function main(projectId, zone, instanceName) { // Delete the instance specified by `instanceName` if it's present in the given project and zone. async function deleteInstance() { - const instancesClient = new compute.InstancesClient({fallback: 'rest'}); + const instancesClient = new compute.InstancesClient(); console.log(`Deleting ${instanceName} from ${zone}...`); @@ -42,9 +42,7 @@ function main(projectId, zone, instanceName) { instance: instanceName, }); - const operationsClient = new compute.ZoneOperationsClient({ - fallback: 'rest', - }); + const operationsClient = new compute.ZoneOperationsClient(); // Wait for the delete operation to complete. while (operation.status !== 'DONE') { diff --git a/compute/getUsageExportBucket.js b/compute/getUsageExportBucket.js index 289dcba6e8..5f7327e676 100644 --- a/compute/getUsageExportBucket.js +++ b/compute/getUsageExportBucket.js @@ -28,7 +28,7 @@ function main(projectId) { async function getUsageExportBucket() { // Get the usage export location for the project from the server. - const projectsClient = new compute.ProjectsClient({fallback: 'rest'}); + const projectsClient = new compute.ProjectsClient(); const [project] = await projectsClient.get({ project: projectId, }); diff --git a/compute/listAllInstances.js b/compute/listAllInstances.js index 16057b1c66..65464db0a7 100644 --- a/compute/listAllInstances.js +++ b/compute/listAllInstances.js @@ -28,7 +28,7 @@ function main(projectId) { // List all instances in the specified project. async function listAllInstances() { - const instancesClient = new compute.InstancesClient({fallback: 'rest'}); + const instancesClient = new compute.InstancesClient(); //Use the `maxResults` parameter to limit the number of results that the API returns per response page. const aggListRequest = instancesClient.aggregatedListAsync({ diff --git a/compute/listImages.js b/compute/listImages.js index c6513e46e4..99ecfce0ff 100644 --- a/compute/listImages.js +++ b/compute/listImages.js @@ -27,7 +27,7 @@ function main(projectId) { const compute = require('@google-cloud/compute'); async function listImages() { - const imagesClient = new compute.ImagesClient({fallback: 'rest'}); + const imagesClient = new compute.ImagesClient(); // Listing only non-deprecated images to reduce the size of the reply. const images = imagesClient.listAsync({ diff --git a/compute/listImagesByPage.js b/compute/listImagesByPage.js index a14f2e7261..c3337c287d 100644 --- a/compute/listImagesByPage.js +++ b/compute/listImagesByPage.js @@ -29,7 +29,7 @@ function main(projectId, pageSize = 10) { const compute = require('@google-cloud/compute'); async function listImagesByPage() { - const imagesClient = new compute.ImagesClient({fallback: 'rest'}); + const imagesClient = new compute.ImagesClient(); // Listing only non-deprecated images to reduce the size of the reply. const listRequest = { diff --git a/compute/listInstances.js b/compute/listInstances.js index 1e81ff2c43..8e83a7a943 100644 --- a/compute/listInstances.js +++ b/compute/listInstances.js @@ -30,7 +30,7 @@ function main(projectId, zone) { // List all instances in the given zone in the specified project. async function listInstances() { - const instancesClient = new compute.InstancesClient({fallback: 'rest'}); + const instancesClient = new compute.InstancesClient(); const [instanceList] = await instancesClient.list({ project: projectId, diff --git a/compute/setUsageExportBucket.js b/compute/setUsageExportBucket.js index c0e6ad54a8..a292a0f341 100644 --- a/compute/setUsageExportBucket.js +++ b/compute/setUsageExportBucket.js @@ -44,10 +44,8 @@ function main(projectId, bucketName, reportNamePrefix = '') { } // Set the usage export location. - const projectsClient = new compute.ProjectsClient({fallback: 'rest'}); - const operationsClient = new compute.GlobalOperationsClient({ - fallback: 'rest', - }); + const projectsClient = new compute.ProjectsClient(); + const operationsClient = new compute.GlobalOperationsClient(); let [operation] = await projectsClient.setUsageExportBucket({ project: projectId, diff --git a/compute/waitForOperation.js b/compute/waitForOperation.js index 3cdfaf8222..e4e4c0df98 100644 --- a/compute/waitForOperation.js +++ b/compute/waitForOperation.js @@ -31,9 +31,7 @@ function main(projectId, operationString) { let operation = JSON.parse(operationString); async function waitForOperation() { - const operationsClient = new compute.ZoneOperationsClient({ - fallback: 'rest', - }); + const operationsClient = new compute.ZoneOperationsClient(); while (operation.status !== 'DONE') { [operation] = await operationsClient.wait({