Skip to content

Commit

Permalink
chore(samples): remove default rest and compute_protos (#608)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
2 people authored and Ace Nassri committed Nov 21, 2022
1 parent cb15d52 commit bbf3c5c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 45 deletions.
54 changes: 25 additions & 29 deletions compute/createInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
6 changes: 2 additions & 4 deletions compute/deleteInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}...`);

Expand All @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion compute/getUsageExportBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion compute/listAllInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion compute/listImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion compute/listImagesByPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion compute/listInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions compute/setUsageExportBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions compute/waitForOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit bbf3c5c

Please sign in to comment.