Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into release-v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 13, 2021
2 parents 46ccf32 + 859641f commit f79b2f9
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 49 deletions.
54 changes: 25 additions & 29 deletions samples/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 samples/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
6 changes: 2 additions & 4 deletions samples/disableUsageExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ function main(projectId) {
const compute = require('@google-cloud/compute');

async function disableUsageExport() {
const projectsClient = new compute.ProjectsClient({fallback: 'rest'});
const operationsClient = new compute.GlobalOperationsClient({
fallback: 'rest',
});
const projectsClient = new compute.ProjectsClient();
const operationsClient = new compute.GlobalOperationsClient();

// Updating the setting with empty usageExportLocationResource will disable the usage report generation.
let [operation] = await projectsClient.setUsageExportBucket({
Expand Down
2 changes: 1 addition & 1 deletion samples/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 samples/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 samples/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 samples/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 samples/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 samples/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 samples/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 f79b2f9

Please sign in to comment.