Skip to content

Commit 7fe2c45

Browse files
FrodoTheTruebcoe
andauthored
chore(samples): remove default rest and compute_protos (#608)
Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent d46441f commit 7fe2c45

9 files changed

+35
-45
lines changed

compute/createInstance.js

+25-29
Original file line numberDiff line numberDiff line change
@@ -52,46 +52,42 @@ function main(
5252
// const networkName = 'global/networks/default';
5353

5454
const compute = require('@google-cloud/compute');
55-
const compute_protos = compute.protos.google.cloud.compute.v1;
55+
const computeProtos = compute.protos.google.cloud.compute.v1;
5656

5757
// Create a new instance with the values provided above in the specified project and zone.
5858
async function createInstance() {
59-
const instancesClient = new compute.InstancesClient({fallback: 'rest'});
60-
61-
// Describe the size and source image of the boot disk to attach to the instance.
62-
const attachedDisk = new compute_protos.AttachedDisk();
63-
const initializeParams = new compute_protos.AttachedDiskInitializeParams();
64-
65-
initializeParams.diskSizeGb = '10';
66-
initializeParams.sourceImage = sourceImage;
67-
68-
attachedDisk.initializeParams = initializeParams;
69-
attachedDisk.autoDelete = true;
70-
attachedDisk.boot = true;
71-
attachedDisk.type = compute_protos.AttachedDisk.Type.PERSISTENT;
72-
73-
// Use the network interface provided in the networkName argument.
74-
const networkInterface = new compute_protos.NetworkInterface();
75-
networkInterface.name = networkName;
76-
77-
// Collect information into the Instance object.
78-
const instance = new compute_protos.Instance();
79-
instance.name = instanceName;
80-
instance.disks = [attachedDisk];
81-
instance.machineType = `zones/${zone}/machineTypes/${machineType}`;
82-
instance.networkInterfaces = [networkInterface];
59+
const instancesClient = new compute.InstancesClient();
8360

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

8663
let [operation] = await instancesClient.insert({
87-
instanceResource: instance,
64+
instanceResource: {
65+
name: instanceName,
66+
disks: [
67+
{
68+
// Describe the size and source image of the boot disk to attach to the instance.
69+
initializeParams: {
70+
diskSizeGb: '10',
71+
sourceImage,
72+
},
73+
autoDelete: true,
74+
boot: true,
75+
type: computeProtos.AttachedDisk.Type.PERSISTENT,
76+
},
77+
],
78+
machineType: `zones/${zone}/machineTypes/${machineType}`,
79+
networkInterfaces: [
80+
{
81+
// Use the network interface provided in the networkName argument.
82+
name: networkName,
83+
},
84+
],
85+
},
8886
project: projectId,
8987
zone,
9088
});
9189

92-
const operationsClient = new compute.ZoneOperationsClient({
93-
fallback: 'rest',
94-
});
90+
const operationsClient = new compute.ZoneOperationsClient();
9591

9692
// Wait for the create operation to complete.
9793
while (operation.status !== 'DONE') {

compute/deleteInstance.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function main(projectId, zone, instanceName) {
3232

3333
// Delete the instance specified by `instanceName` if it's present in the given project and zone.
3434
async function deleteInstance() {
35-
const instancesClient = new compute.InstancesClient({fallback: 'rest'});
35+
const instancesClient = new compute.InstancesClient();
3636

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

@@ -42,9 +42,7 @@ function main(projectId, zone, instanceName) {
4242
instance: instanceName,
4343
});
4444

45-
const operationsClient = new compute.ZoneOperationsClient({
46-
fallback: 'rest',
47-
});
45+
const operationsClient = new compute.ZoneOperationsClient();
4846

4947
// Wait for the delete operation to complete.
5048
while (operation.status !== 'DONE') {

compute/getUsageExportBucket.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function main(projectId) {
2828

2929
async function getUsageExportBucket() {
3030
// Get the usage export location for the project from the server.
31-
const projectsClient = new compute.ProjectsClient({fallback: 'rest'});
31+
const projectsClient = new compute.ProjectsClient();
3232
const [project] = await projectsClient.get({
3333
project: projectId,
3434
});

compute/listAllInstances.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function main(projectId) {
2828

2929
// List all instances in the specified project.
3030
async function listAllInstances() {
31-
const instancesClient = new compute.InstancesClient({fallback: 'rest'});
31+
const instancesClient = new compute.InstancesClient();
3232

3333
//Use the `maxResults` parameter to limit the number of results that the API returns per response page.
3434
const aggListRequest = instancesClient.aggregatedListAsync({

compute/listImages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function main(projectId) {
2727
const compute = require('@google-cloud/compute');
2828

2929
async function listImages() {
30-
const imagesClient = new compute.ImagesClient({fallback: 'rest'});
30+
const imagesClient = new compute.ImagesClient();
3131

3232
// Listing only non-deprecated images to reduce the size of the reply.
3333
const images = imagesClient.listAsync({

compute/listImagesByPage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function main(projectId, pageSize = 10) {
2929
const compute = require('@google-cloud/compute');
3030

3131
async function listImagesByPage() {
32-
const imagesClient = new compute.ImagesClient({fallback: 'rest'});
32+
const imagesClient = new compute.ImagesClient();
3333

3434
// Listing only non-deprecated images to reduce the size of the reply.
3535
const listRequest = {

compute/listInstances.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function main(projectId, zone) {
3030

3131
// List all instances in the given zone in the specified project.
3232
async function listInstances() {
33-
const instancesClient = new compute.InstancesClient({fallback: 'rest'});
33+
const instancesClient = new compute.InstancesClient();
3434

3535
const [instanceList] = await instancesClient.list({
3636
project: projectId,

compute/setUsageExportBucket.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ function main(projectId, bucketName, reportNamePrefix = '') {
4444
}
4545

4646
// Set the usage export location.
47-
const projectsClient = new compute.ProjectsClient({fallback: 'rest'});
48-
const operationsClient = new compute.GlobalOperationsClient({
49-
fallback: 'rest',
50-
});
47+
const projectsClient = new compute.ProjectsClient();
48+
const operationsClient = new compute.GlobalOperationsClient();
5149

5250
let [operation] = await projectsClient.setUsageExportBucket({
5351
project: projectId,

compute/waitForOperation.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ function main(projectId, operationString) {
3131
let operation = JSON.parse(operationString);
3232

3333
async function waitForOperation() {
34-
const operationsClient = new compute.ZoneOperationsClient({
35-
fallback: 'rest',
36-
});
34+
const operationsClient = new compute.ZoneOperationsClient();
3735

3836
while (operation.status !== 'DONE') {
3937
[operation] = await operationsClient.wait({

0 commit comments

Comments
 (0)