Constructor

Zone

new Zone(compute, name)

A Zone object allows you to interact with a Google Compute Engine zone.

Parameter

compute

Compute

Compute object this zone belongs to.

name

string

Name of the zone.

See also

Regions & Zones Overview

Zone Resource

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

Properties

compute

Compute

The parent Compute instance of this Zone instance.

getAutoscalersStream

Get a list of Autoscaler objects from this zone as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Zone#getAutoscalers for a complete list of options.

Returns

stream 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getAutoscalersStream()
  .on('error', console.error)
  .on('data', function(autoscaler) {
    // `autoscaler` is an `Autoscaler` object.
  })
  .on('end', function() {
    // All autoscalers retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getAutoscalersStream()
  .on('data', function(autoscaler) {
    this.end();
  });

getDisksStream

Get a list of Disk objects in this zone as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Zone#getDisks for a complete list of options.

Returns

stream 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getDisksStream()
  .on('error', console.error)
  .on('data', function(disk) {
    // `disk` is a `Disk` object.
  })
  .on('end', function() {
    // All disks retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getDisksStream()
  .on('data', function(disk) {
    this.end();
  });

getInstanceGroupsStream

Get a list of InstanceGroup objects for this zone as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Zone#getInstanceGroups for a complete list of options.

Returns

stream 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getInstanceGroupsStream()
  .on('error', console.error)
  .on('data', function(instanceGroup) {
    // `instanceGroup` is an `InstanceGroup` object.
  })
  .on('end', function() {
    // All instance groups retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getInstanceGroupsStream()
  .on('data', function(instanceGroup) {
    this.end();
  });

getMachineTypesStream

Get a list of MachineType objects for this zone as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Zone#getMachineTypes for a complete list of options.

Returns

stream 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getMachineTypesStream()
  .on('error', console.error)
  .on('data', function(machineType) {
    // `machineType` is a `MachineType` object.
  })
  .on('end', function() {
    // All machine types retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getMachineTypesStream()
  .on('data', function(machineType) {
    this.end();
  });

getOperationsStream

Get a list of Operation objects for this zone as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Zone#getOperations for a complete list of options.

Returns

stream 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getOperationsStream()
  .on('error', console.error)
  .on('data', function(operation) {
    // `operation` is an `Operation` object.
  })
  .on('end', function() {
    // All operations retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getOperationsStream()
  .on('data', function(operation) {
    this.end();
  });

getVMsStream

Get a list of VM instances in this zone as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Zone#getVMs for a complete list of options.

Returns

stream 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getVMsStream()
  .on('error', console.error)
  .on('data', function(vm) {
    // `vm` is a `VM` object.
  })
  .on('end', function() {
    // All instances retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getVMsStream()
  .on('data', function(vm) {
    this.end();
  });

id

string

name

string

Methods

autoscaler

autoscaler(name) returns Autoscaler

Get a reference to a Google Compute Engine autoscaler in this zone.

Parameter

name

string

Name of the autoscaler.

Returns

Autoscaler 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const autoscaler = zone.autoscaler('autoscaler-name');

createAutoscaler

createAutoscaler(name, config, callback)

Create an autoscaler in this zone.

Parameter

name

string

Name of the autoscaler.

config

object

See an Autoscaler resource.

callback

function()

The callback function.

See also

Load Balancing and Scaling

Autoscaler Resource

Autoscalers: insert API Documentation

Throws

Error 

If config.target is not provided.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const config = {
  coolDown: 30,
  cpu: 80,
  loadBalance: 40,
  maxReplicas: 5,
  minReplicas: 0,
  target: 'instance-group-manager-1'
};

function callback(err, autoscaler, operation, apiResponse) {
  // `autoscaler` is an Autoscaler object.

  // `operation` is an Operation object that can be used to check the status
  // of the request.
}

zone.createAutoscaler('name', config, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createAutoscaler('name', config).then(function(data) {
  const autoscaler = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

createDisk

createDisk(name, config, callback)

Create a persistent disk in this zone.

Parameter

name

string

Name of the disk.

config

object

See a Disk resource.

callback

function()

The callback function.

See also

Disk Resource

Disks: insert API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

//-
// Create a persistent disk using the latest Ubuntu version
// as the source image.
//-
const config = {
  os: 'ubuntu',
  sizeGb: 10
};

//-
// Create a persistent disk using the latest Ubuntu version from your project
// as the source image.
//-
const config = {
  os: 'your-project-id-or-name/ubuntu',
  sizeGb: 10
};

zone.createDisk('name', config, function(err, disk, operation, apiResponse) {
  // `disk` is a Disk object.

  // `operation` is an Operation object that can be used to check the status
  // of the request.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createDisk('name', config).then(function(data) {
  const disk = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

createInstanceGroup

createInstanceGroup(name, options, callback)

Create an instance group in this zone.

Parameter

name

string

Name of the instance group.

options

object

See an InstanceGroup resource.

callback

function()

The callback function.

See also

InstanceGroup Resource

InstanceGroups: insert API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

function onCreated(err, instanceGroup, operation, apiResponse) {
  // `instanceGroup` is an InstanceGroup object.

  // `operation` is an Operation object that can be used to check the status
  // of the request.
}

zone.createInstanceGroup('instance-group-name', onCreated);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createInstanceGroup('instance-group-name', config).then(function(data) {
  const instanceGroup = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

createVM

createVM(name, config, callback)

Create a virtual machine in this zone.

Parameter

name

string

Name of the instance.

config

object

See an Instance resource.

callback

function()

The callback function.

See also

Instance Resource

Instances: insert API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

//-
// Create a new instance using the latest Debian version from your project
// as the source image for a new boot disk.
//-
const config = {
  os: 'your-project-id-or-name/debian',
  http: true,
  tags: ['debian-server']
};

//-
// Create a new instance using the latest Debian version as the source image
// for a new boot disk.
//-
const config = {
  os: 'debian',
  http: true,
  tags: ['debian-server']
};

//-
// The above object will auto-expand behind the scenes to something like the
// following. The Debian version may be different when you run the command.
//-
const config = {
  machineType: 'n1-standard-1',
  disks: [
    {
      boot: true,
      initializeParams: {
        sourceImage:
          'https://www.googleapis.com/compute/v1/projects' +
          '/debian-cloud/global/images/debian-7-wheezy-v20150710'
      }
    }
  ],
  networkInterfaces: [
    {
      network: 'global/networks/default'
    }
  ],
  tags: [
    {
      items: [
        'debian-server',
        'http-server'
      ]
    }
  ]
};

function callback(err, vm, operation, apiResponse) {
  // `vm` is a VM object.

  // `operation` is an Operation object that can be used to check the status
  // of the request.
}

zone.createVM('new-vm-name', config, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createVM('new-vm-name', config).then(function(data) {
  const vm = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

disk

disk(name) returns Disk

Get a reference to a Google Compute Engine disk in this zone.

Parameter

name

string

Name of the disk.

See also

Disks Overview

Returns

Disk 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const disk = zone.disk('disk1');

exists

exists(callback)

Check if the zone exists.

Parameter

callback

function()

The callback function.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.exists(function(err, exists) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.exists().then(function(data) {
  const exists = data[0];
});

get

get()

Get a zone.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.get(function(err, zone, apiResponse) {
  // `zone` is a Zone object.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.get().then(function(data) {
  const zone = data[0];
  const apiResponse = data[1];
});

getAutoscalers

getAutoscalers(options, callback)

Get a list of autoscalers from this zone.

Parameter

options

Optional

object

Autoscaler search options.

callback

function()

The callback function.

See also

Managing Autoscalers

Understanding Autoscaler Decisions

Autoscalers: aggregatedList API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getAutoscalers(function(err, autoscalers) {
  // autoscalers is an array of `Autoscaler` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, autoscalers, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    zone.getAutoscalers(nextQuery, callback);
  }
}

zone.getAutoscalers({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getAutoscalers().then(function(data) {
  const autoscalers = data[0];
});

getDisks

getDisks(options, callback)

Get a list of disks in this zone.

Parameter

options

Optional

object

Disk search options.

callback

function()

The callback function.

See also

Disks Overview

Disks: list API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getDisks(function(err, disks) {
  // `disks` is an array of `Disk` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, disks, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    zone.getDisks(nextQuery, callback);
  }
}

zone.getDisks({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getDisks().then(function(data) {
  const disks = data[0];
});

getInstanceGroups

getInstanceGroups(options, callback)

Get a list of instance groups for this zone.

Parameter

options

Optional

object

Instance group search options.

callback

function()

The callback function.

See also

InstanceGroups Overview

InstanceGroups: list API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getInstanceGroups(function(err, instanceGroups) {
  // `instanceGroups` is an array of `InstanceGroup` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, instanceGroups, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    zone.getInstanceGroups(nextQuery, callback);
  }
}

zone.getInstanceGroups({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getInstanceGroups().then(function(data) {
  const instanceGroups = data[0];
});

getMachineTypes

getMachineTypes(options, callback)

Get a list of machine types for this zone.

Parameter

options

Optional

object

Machine type search options.

callback

function()

The callback function.

See also

MachineTypes: list API Documentation

Machine Types Overview

MachineType Resource

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getMachineTypes(function(err, machineTypes) {
  // `machineTypes` is an array of `MachineType` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, machineTypes, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    zone.getMachineTypes(nextQuery, callback);
  }
}

zone.getMachineTypes({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getMachineTypes().then(function(data) {
  const machineTypes = data[0];
});

getMetadata

getMetadata(callback)

Get the zone's metadata.

Parameter

callback

Optional

function()

The callback function.

See also

Zone Resource

Zones: get API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getMetadata(function(err, metadata, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getMetadata().then(function(data) {
  const metadata = data[0];
  const apiResponse = data[1];
});

getOperations

getOperations(options, callback)

Get a list of operations for this zone.

Parameter

options

Optional

object

Operation search options.

callback

function()

The callback function.

See also

Zone Operation Overview

ZoneOperations: list API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getOperations(function(err, operations) {
  // `operations` is an array of `Operation` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, operations, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    zone.getOperations(nextQuery, callback);
  }
}

zone.getOperations({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getOperations().then(function(data) {
  const operations = data[0];
});

getVMs

getVMs(options, callback)

Get a list of VM instances in this zone.

Parameter

options

Optional

object

Instance search options.

callback

function()

The callback function.

See also

Instances and Networks

Instances: list API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

zone.getVMs(function(err, vms) {
  // `vms` is an array of `VM` objects.
});

//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, vms, nextQuery, apiResponse) {
  if (nextQuery) {
    // More results exist.
    zone.getVMs(nextQuery, callback);
  }
}

zone.getVMs({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getVMs().then(function(data) {
  const vms = data[0];
});

instanceGroup

instanceGroup(name) returns InstanceGroup

Get a reference to a Google Compute Engine instance group.

Parameter

name

string

Name of the existing instance group.

See also

InstanceGroups Overview

Returns

InstanceGroup 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const instanceGroup = zone.instanceGroup('my-instance-group');

machineType

machineType(name) returns MachineType

Get a reference to a Google Compute Engine machine type.

Parameter

name

string

Name of the existing machine type.

See also

Machine Types Overview

MachineType Resource

Returns

MachineType 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const machineType = zone.machineType('g1-small');

operation

operation(name) returns Operation

Get a reference to a Google Compute Engine zone operation.

Parameter

name

string

Name of the existing operation.

See also

Zone Operation Overview

Returns

Operation 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const operation = zone.operation('operation-1445532685163-8b137d2a-1822afe7');

vm

vm(name) returns VM

Get a reference to a Google Compute Engine virtual machine instance.

Parameter

name

string

Name of the virtual machine.

See also

Instances and Networks

Returns

VM 

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');

const vm = zone.vm('vm-name');