new Zone(compute, name)

Example

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

Parameters

Name Type Optional Description

compute

 

 

Compute object this zone belongs to.

name

 

 

Name of the zone.

See also

Regions & Zones Overview

Zone Resource

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.

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();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getDisksStream

Get a list of Disk objects in this zone as a readable object 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();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getInstanceGroupsStream

Get a list of InstanceGroup objects for this zone as a readable object 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();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getMachineTypesStream

Get a list of MachineType objects for this zone as a readable object 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();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getOperationsStream

Get a list of Operation objects for this zone as a readable object 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();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getVMsStream

Get a list of VM instances in this zone as a readable object 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();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

id  string

name  string

Methods

autoscaler(name) → Autoscaler

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

Example

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

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

Parameter

Name Type Optional Description

name

string

 

Name of the autoscaler.

Returns

Autoscaler 

createAutoscaler(name, config, callback)

Create an autoscaler in this zone.

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];
});

Parameters

Name Type Optional Description

name

string

 

Name of the autoscaler.

config

object

 

See an Autoscaler resource.

Values in config have the following properties:

Name Type Optional Description

coolDown

number

 

The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. Alias for config.autoscalingPolicy.coolDownPeriodSec.

cpu

number

 

The target CPU utilization that the autoscaler should maintain, between 1 - 100. Alias for config.autoscalingPolicy.cpuUtilization.utilizationTarget.

loadBalance

number

 

Backend capacity utilization that autoscaler should maintain, between 1 - 100. Alias for config.autoscalingPolicy.loadBalancingUtilization.utilizationTarget.

maxReplicas

number

 

The maximum number of instances that the autoscaler can scale up to. Alias for config.autoscalingPolicy.maxNumReplicas.

minReplicas

number

 

The minimum number of replicas that the autoscaler can scale down to. Alias for config.autoscalingPolicy.minNumReplicas.

target

string

 

The name of the managed instance group that this autoscaler will scale.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

autoscaler

Autoscaler

 

The created Autoscaler object.

operation

Operation

 

An operation object that can be used to check the status of the request.

apiResponse

object

 

The full API response.

See also

Load Balancing and Scaling

Autoscaler Resource

Autoscalers: insert API Documentation

Throws

Error 

If config.target is not provided.

createDisk(name, config, callback)

Create a persistent disk in this zone.

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];
});

Parameters

Name Type Optional Description

name

string

 

Name of the disk.

config

object

 

See a Disk resource.

Values in config have the following properties:

Name Type Optional Description

os

string

Yes

Specify the name of an OS, and we will use the latest version as the source image of a new boot disk. See this list of accepted OS names.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

disk

Disk

 

The created Disk object.

operation

Operation

 

An operation object that can be used to check the status of the request.

apiResponse

object

 

The full API response.

See also

Disk Resource

Disks: insert API Documentation

createInstanceGroup(name, options, callback)

Create an instance group in this zone.

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];
});

Parameters

Name Type Optional Description

name

string

 

Name of the instance group.

options

object

 

See an InstanceGroup resource.

Values in options have the following properties:

Name Type Optional Description

ports

object

 

A map of names to ports. The key should be the name, and the value the port number. Maps to options.namedPorts.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

instanceGroup

InstanceGroup

 

The created InstanceGroup object.

operation

Operation

 

An operation object that can be used to check the status of the request.

apiResponse

object

 

The full API response.

See also

InstanceGroup Resource

InstanceGroups: insert API Documentation

createVM(name, config, callback)

Create a virtual machine in this zone.

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];
});

Parameters

Name Type Optional Description

name

string

 

Name of the instance.

config

object

 

See an Instance resource.

Values in config have the following properties:

Name Type Optional Description

disks

Array of object

 

See a Disk resource.

Value can be null.

http

boolean

Yes

Allow HTTP traffic. Default: false

https

boolean

Yes

Allow HTTPS traffic. Default: false

networkInterfaces

Array of object

 

An array of configurations for this interface. This specifies how this interface should interact with other network services, such as connecting to the internet. Default: [ { network: 'global/networks/default' } ]

Value can be null.

machineType

string

Yes

The machine type resource to use. Provide only the name of the machine, e.g. n1-standard-16. Refer to Available Machine Types. Default: n1-standard-1

os

string

Yes

Specify the name of an OS, and we will use the latest version as the source image of a new boot disk. See this list of accepted OS names.

tags

Array of string

 

An array of tags.

Value can be null.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

vm

VM

 

The created VM object.

operation

Operation

 

An operation object that can be used to check the status of the request.

apiResponse

object

 

The full API response.

See also

Instance Resource

Instances: insert API Documentation

disk(name) → Disk

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

Example

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

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

Parameter

Name Type Optional Description

name

string

 

Name of the disk.

See also

Disks Overview

Returns

Disk 

exists(callback)

Check if the zone exists.

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];
});

Parameters

Name Type Optional Description

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

exists

boolean

 

Whether the zone exists or not.

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([options], callback)

Get a list of autoscalers from this zone.

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];
});

Parameters

Name Type Optional Description

options

object

Yes

Autoscaler search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

filter

string

 

Search filter in the format of {name} {comparison} {filterString}. - name: the name of the field to compare - comparison: the comparison operator, eq (equal) or ne (not equal) - filterString: the string to filter to. For string fields, this can be a regular expression.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of autoscalers to return.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

autoscalers

Array of Autoscaler

 

Autoscaler objects from your project.

apiResponse

object

 

The full API response.

See also

Managing Autoscalers

Understanding Autoscaler Decisions

Autoscalers: aggregatedList API Documentation

getDisks([options], callback)

Get a list of disks in this zone.

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];
});

Parameters

Name Type Optional Description

options

object

Yes

Disk search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

filter

string

 

Search filter in the format of {name} {comparison} {filterString}. - name: the name of the field to compare - comparison: the comparison operator, eq (equal) or ne (not equal) - filterString: the string to filter to. For string fields, this can be a regular expression.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of disks to return.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

disks

Array of Disk

 

Disk objects from this zone.

apiResponse

object

 

The full API response.

See also

Disks Overview

Disks: list API Documentation

getInstanceGroupManagers([options], callback)

Get a list of instance group managers for this zone.

Example

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

zone.getInstanceGroupManagers(function(err, instanceGroupManagers) {
  // `instanceGroupManagers` is an array of `InstanceGroupManager` objects.
});

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

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

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

Parameters

Name Type Optional Description

options

object

Yes

Instance group manager search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

filter

string

 

Search filter in the format of {name} {comparison} {filterString}. - name: the name of the field to compare - comparison: the comparison operator, eq (equal) or ne (not equal) - filterString: the string to filter to. For string fields, this can be a regular expression.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of instance groups to return.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

instanceGroupManagers

Array of InstanceGroupManager

 

InstanceGroupManager objects from this zone.

apiResponse

object

 

The full API response.

See also

InstanceGroupManagers Overview

InstanceGroupManagers: list API Documentation

getInstanceGroups([options], callback)

Get a list of instance groups for this zone.

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];
});

Parameters

Name Type Optional Description

options

object

Yes

Instance group search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

filter

string

 

Search filter in the format of {name} {comparison} {filterString}. - name: the name of the field to compare - comparison: the comparison operator, eq (equal) or ne (not equal) - filterString: the string to filter to. For string fields, this can be a regular expression.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of instance groups to return.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

instanceGroups

Array of InstanceGroup

 

InstanceGroup objects from this zone.

apiResponse

object

 

The full API response.

See also

InstanceGroups Overview

InstanceGroups: list API Documentation

getMachineTypes([options], callback)

Get a list of machine types for this zone.

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];
});

Parameters

Name Type Optional Description

options

object

Yes

Machine type search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of machineTypes to return.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

machineTypes

Array of MachineType

 

MachineType objects from this zone.

apiResponse

object

 

The full API response.

See also

MachineTypes: list API Documentation

Machine Types Overview

MachineType Resource

getMetadata([callback])

Get the zone's metadata.

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];
});

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

metadata

object

 

The zone's metadata.

apiResponse

object

 

The full API response.

See also

Zone Resource

Zones: get API Documentation

getOperations([options], callback)

Get a list of operations for this zone.

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];
});

Parameters

Name Type Optional Description

options

object

Yes

Operation search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

filter

string

 

Search filter in the format of {name} {comparison} {filterString}. - name: the name of the field to compare - comparison: the comparison operator, eq (equal) or ne (not equal) - filterString: the string to filter to. For string fields, this can be a regular expression.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of operations to return.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

operations

Array of Operation

 

Operation objects from this zone.

apiResponse

object

 

The full API response.

See also

Zone Operation Overview

ZoneOperations: list API Documentation

getVMs([options], callback)

Get a list of VM instances in this zone.

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];
});

Parameters

Name Type Optional Description

options

object

Yes

Instance search options.

Values in options have the following properties:

Name Type Optional Description

autoPaginate

boolean

 

Have pagination handled automatically. Default: true.

filter

string

 

Search filter in the format of {name} {comparison} {filterString}. - name: the name of the field to compare - comparison: the comparison operator, eq (equal) or ne (not equal) - filterString: the string to filter to. For string fields, this can be a regular expression.

pageToken

string

 

A previously-returned page token representing part of the larger set of results to view.

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

vms

Array of VM

 

VM objects from this zone.

apiResponse

object

 

The full API response.

See also

Instances and Networks

Instances: list API Documentation

instanceGroup(name) → InstanceGroup

Get a reference to a Google Compute Engine instance group.

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');

Parameter

Name Type Optional Description

name

string

 

Name of the existing instance group.

See also

InstanceGroups Overview

Returns

InstanceGroup 

instanceGroupManager(name) → InstanceGroupManager

Get a reference to a Google Compute Engine instance group manager.

Example

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

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

Parameter

Name Type Optional Description

name

string

 

Name of the existing instance group manager.

See also

InstanceGroupManagers Overview

Returns

InstanceGroupManager 

machineType(name) → MachineType

Get a reference to a Google Compute Engine machine type.

Example

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

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

Parameter

Name Type Optional Description

name

string

 

Name of the existing machine type.

See also

Machine Types Overview

MachineType Resource

Returns

MachineType 

operation(name) → Operation

Get a reference to a Google Compute Engine zone 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');

Parameter

Name Type Optional Description

name

string

 

Name of the existing operation.

See also

Zone Operation Overview

Returns

Operation 

vm(name) → VM

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

Example

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

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

Parameter

Name Type Optional Description

name

string

 

Name of the virtual machine.

See also

Instances and Networks

Returns

VM