@google-cloud/compute

Google Compute Engine Client Library for Node.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@google-cloud/compute
2,8171444.4.022 days ago8 years agoMinified + gzip package size for @google-cloud/compute in KB

Readme

Google Cloud Platform logorelease level npm version
Google Compute Engine Client Library for Node.js
A comprehensive list of changes in each version may be found in the CHANGELOG.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explainedexplained.
Table of contents:
Before you begin Installing the client library Using the client library

Quickstart

Before you begin

  1. Select or create a Cloud Platform projectprojects.
  2. Enable billing for your projectbilling.
  3. Enable the Google Compute Engine APIenableapi.
  4. Set up authentication with a service accountauth so you can access the
API from your local workstation.

Installing the client library

npm install @google-cloud/compute

Using the client library

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';

const compute = require('@google-cloud/compute');

// List all instances in the specified project.
async function listAllInstances() {
  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({
    project: projectId,
    maxResults: 5,
  });

  console.log('Instances found:');

  // Despite using the `maxResults` parameter, you don't need to handle the pagination
  // yourself. The returned object handles pagination automatically,
  // requesting next pages as you iterate over the results.
  for await (const [zone, instancesObject] of aggListRequest) {
    const instances = instancesObject.instances;

    if (instances && instances.length > 0) {
      console.log(` ${zone}`);
      for (const instance of instances) {
        console.log(` - ${instance.name} (${instance.machineType})`);
      }
    }
  }
}

listAllInstances();

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.
| Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | | Acceleratortypes.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Acceleratortypes.get | source code | !Open in Cloud Shellshellimg | | Acceleratortypes.list | source code | !Open in Cloud Shellshellimg | | Addresses.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Addresses.delete | source code | !Open in Cloud Shellshellimg | | Addresses.get | source code | !Open in Cloud Shellshellimg | | Addresses.insert | source code | !Open in Cloud Shellshellimg | | Addresses.list | source code | !Open in Cloud Shellshellimg | | Addresses.move | source code | !Open in Cloud Shellshellimg | | Addresses.setlabels | source code | !Open in Cloud Shellshellimg | | Autoscalers.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Autoscalers.delete | source code | !Open in Cloud Shellshellimg | | Autoscalers.get | source code | !Open in Cloud Shellshellimg | | Autoscalers.insert | source code | !Open in Cloud Shellshellimg | | Autoscalers.list | source code | !Open in Cloud Shellshellimg | | Autoscalers.patch | source code | !Open in Cloud Shellshellimg | | Autoscalers.update | source code | !Open in Cloud Shellshellimg | | Backendbuckets.addsignedurlkey | source code | !Open in Cloud Shellshellimg | | Backendbuckets.delete | source code | !Open in Cloud Shellshellimg | | Backendbuckets.deletesignedurlkey | source code | !Open in Cloud Shellshellimg | | Backendbuckets.get | source code | !Open in Cloud Shellshellimg | | Backendbuckets.getiampolicy | source code | !Open in Cloud Shellshellimg | | Backendbuckets.insert | source code | !Open in Cloud Shellshellimg | | Backendbuckets.list | source code | !Open in Cloud Shellshellimg | | Backendbuckets.patch | source code | !Open in Cloud Shellshellimg | | Backendbuckets.setedgesecuritypolicy | source code | !Open in Cloud Shellshellimg | | Backendbuckets.setiampolicy | source code | !Open in Cloud Shellshellimg | | Backendbuckets.testiampermissions | source code | !Open in Cloud Shellshellimg | | Backendbuckets.update | source code | !Open in Cloud Shellshellimg | | Backendservices.addsignedurlkey | source code | !Open in Cloud Shellshellimg | | Backendservices.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Backendservices.delete | source code | !Open in Cloud Shellshellimg | | Backendservices.deletesignedurlkey | source code | !Open in Cloud Shellshellimg | | Backendservices.get | source code | !Open in Cloud Shellshellimg | | Backendservices.gethealth | source code | !Open in Cloud Shellshellimg | | Backendservices.getiampolicy | source code | !Open in Cloud Shellshellimg | | Backendservices.insert | source code | !Open in Cloud Shellshellimg | | Backendservices.list | source code | !Open in Cloud Shellshellimg | | Backendservices.listusable | source code | !Open in Cloud Shellshellimg | | Backendservices.patch | source code | !Open in Cloud Shellshellimg | | Backendservices.setedgesecuritypolicy | source code | !Open in Cloud Shellshellimg | | Backendservices.setiampolicy | source code | !Open in Cloud Shellshellimg | | Backendservices.setsecuritypolicy | source code | !Open in Cloud Shellshellimg | | Backendservices.testiampermissions | source code | !Open in Cloud Shellshellimg | | Backendservices.update | source code | !Open in Cloud Shellshellimg | | Disktypes.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Disktypes.get | source code | !Open in Cloud Shellshellimg | | Disktypes.list | source code | !Open in Cloud Shellshellimg | | Disks.addresourcepolicies | source code | !Open in Cloud Shellshellimg | | Disks.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Disks.bulkinsert | source code | !Open in Cloud Shellshellimg | | Disks.createsnapshot | source code | !Open in Cloud Shellshellimg | | Disks.delete | source code | !Open in Cloud Shellshellimg | | Disks.get | source code | !Open in Cloud Shellshellimg | | Disks.getiampolicy | source code | !Open in Cloud Shellshellimg | | Disks.insert | source code | !Open in Cloud Shellshellimg | | Disks.list | source code | !Open in Cloud Shellshellimg | | Disks.removeresourcepolicies | source code | !Open in Cloud Shellshellimg | | Disks.resize | source code | !Open in Cloud Shellshellimg | | Disks.setiampolicy | source code | !Open in Cloud Shellshellimg | | Disks.setlabels | source code | !Open in Cloud Shellshellimg | | Disks.startasyncreplication | source code | !Open in Cloud Shellshellimg | | Disks.stopasyncreplication | source code | !Open in Cloud Shellshellimg | | Disks.stopgroupasyncreplication | source code | !Open in Cloud Shellshellimg | | Disks.testiampermissions | source code | !Open in Cloud Shellshellimg | | Disks.update | source code | !Open in Cloud Shellshellimg | | Externalvpngateways.delete | source code | !Open in Cloud Shellshellimg | | Externalvpngateways.get | source code | !Open in Cloud Shellshellimg | | Externalvpngateways.insert | source code | !Open in Cloud Shellshellimg | | Externalvpngateways.list | source code | !Open in Cloud Shellshellimg | | Externalvpngateways.setlabels | source code | !Open in Cloud Shellshellimg | | Externalvpngateways.testiampermissions | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.addassociation | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.addrule | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.clonerules | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.delete | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.get | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.getassociation | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.getiampolicy | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.getrule | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.insert | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.list | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.listassociations | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.move | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.patch | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.patchrule | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.removeassociation | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.removerule | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.setiampolicy | source code | !Open in Cloud Shellshellimg | | Firewallpolicies.testiampermissions | source code | !Open in Cloud Shellshellimg | | Firewalls.delete | source code | !Open in Cloud Shellshellimg | | Firewalls.get | source code | !Open in Cloud Shellshellimg | | Firewalls.insert | source code | !Open in Cloud Shellshellimg | | Firewalls.list | source code | !Open in Cloud Shellshellimg | | Firewalls.patch | source code | !Open in Cloud Shellshellimg | | Firewalls.update | source code | !Open in Cloud Shellshellimg | | Forwardingrules.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Forwardingrules.delete | source code | !Open in Cloud Shellshellimg | | Forwardingrules.get | source code | !Open in Cloud Shellshellimg | | Forwardingrules.insert | source code | !Open in Cloud Shellshellimg | | Forwardingrules.list | source code | !Open in Cloud Shellshellimg | | Forwardingrules.patch | source code | !Open in Cloud Shellshellimg | | Forwardingrules.setlabels | source code | !Open in Cloud Shellshellimg | | Forwardingrules.settarget | source code | !Open in Cloud Shellshellimg | | Globaladdresses.delete | source code | !Open in Cloud Shellshellimg | | Globaladdresses.get | source code | !Open in Cloud Shellshellimg | | Globaladdresses.insert | source code | !Open in Cloud Shellshellimg | | Globaladdresses.list | source code | !Open in Cloud Shellshellimg | | Globaladdresses.move | source code | !Open in Cloud Shellshellimg | | Globaladdresses.setlabels | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.delete | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.get | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.insert | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.list | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.patch | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.setlabels | source code | !Open in Cloud Shellshellimg | | Globalforwardingrules.settarget | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.attachnetworkendpoints | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.delete | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.detachnetworkendpoints | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.get | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.insert | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.list | source code | !Open in Cloud Shellshellimg | | Globalnetworkendpointgroups.listnetworkendpoints | source code | !Open in Cloud Shellshellimg | | Globaloperations.aggregatedlist | source code | !Open in Cloud Shellshellimg | | Globaloperations.delete | source code | !Open in Cloud Shellshellimg | | Globaloperations.get | source code | !Open in Cloud Shellshellimg(https://console.cloud.google.com/cloudshell/open?gitrepo=https://github.com/googleapis/google-cloud-node&page=editor&openineditor=packages/google-cloud-compute/samples/generated/v1/globaloperations.get.js,packages/google-cloud-