new InstanceGroup(zone, name)

Example

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

Parameters

Name Type Optional Description

zone

 

 

name

 

 

See also

Creating Groups of Instances

Unmanaged Instance Groups

Properties

getVMsStream

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

Example

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

instanceGroup.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.
//-
instanceGroup.getVMsStream()
  .on('data', function(vm) {
    this.end();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

id  string

name  string

name  string

zone  Zone

The parent Zone instance of this InstanceGroup instance.

zone  Zone

The parent Zone instance of this InstanceGroup instance.

Methods

add(vms, callback)

Add one or more VMs to this instance group.

Example

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

const vms = [
  gce.zone('us-central1-a').vm('http-server'),
  gce.zone('us-central1-a').vm('https-server')
];

instanceGroup.add(vms, function(err, operation, apiResponse) {
  // `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.
//-
instanceGroup.add(vms).then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});

Parameters

Name Type Optional Description

vms

(VM or Array of VM)

 

VM instances to add to this instance group.

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.

operation

Operation

 

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

apiResponse

object

 

The full API response.

See also

InstanceGroups: addInstances API Documentation

create([options])

Create an instance group.

Example

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

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.
}

instanceGroup.create(onCreated);

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

Parameter

Name Type Optional Description

options

object

Yes

See Zone#createInstanceGroup.

delete([callback])

Delete the instance group.

Example

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

instanceGroup.delete(function(err, operation, apiResponse) {
  // `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.
//-
instanceGroup.delete().then(function(data) {
  const operation = 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.

operation

Operation

 

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

apiResponse

object

 

The full API response.

See also

InstanceGroups: delete API Documentation

exists(callback)

Check if the instance group exists.

Example

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

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

//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.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 instance group exists or not.

get([options])

Get an instance group if it exists.

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Example

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

instanceGroup.get(function(err, instanceGroup, apiResponse) {
  // `instanceGroup` is an InstanceGroup object.
});

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

Parameters

Name Type Optional Description

options

options

Yes

Configuration object.

Values in options have the following properties:

Name Type Optional Description

autoCreate

boolean

 

Automatically create the object if it does not exist. Default: false

getMetadata([callback])

Get the instance group's metadata.

Example

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

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

//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.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 instance group's metadata.

apiResponse

object

 

The full API response.

See also

InstanceGroups: get API Documentation

InstanceGroups Resource

getVMs([options], callback)

Get a list of VM instances in this instance group.

Example

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

instanceGroup.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.
    instanceGroup.getVMs(nextQuery, callback);
  }
}

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

//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.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.

maxApiCalls

number

 

Maximum number of API calls to make.

maxResults

number

 

Maximum number of VMs to return.

pageToken

string

 

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

running

boolean

 

Only return instances which are running.

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 instance group.

apiResponse

object

 

The full API response.

See also

InstanceGroups: listInstances API Documentation

remove(vms, callback)

Remove one or more VMs from this instance group.

Example

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

const vms = [
  gce.zone('us-central1-a').vm('http-server'),
  gce.zone('us-central1-a').vm('https-server')
];

instanceGroup.remove(vms, function(err, operation, apiResponse) {
  // `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.
//-
instanceGroup.remove(vms).then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});

Parameters

Name Type Optional Description

vms

(VM or Array of VM)

 

VM instances to remove from this instance group.

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.

operation

Operation

 

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

apiResponse

object

 

The full API response.

See also

InstanceGroups: removeInstances API Documentation

setPorts(ports[, callback])

Set the named ports for this instance group.

Example

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

const ports = {
  http: 80,
  https: 443
};

instanceGroup.setPorts(ports, function(err, operation, apiResponse) {
  // `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.
//-
instanceGroup.setPorts(ports).then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});

Parameters

Name Type Optional Description

ports

object

 

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

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.

operation

Operation

 

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

apiResponse

object

 

The full API response.

See also

InstanceGroups: setNamedPorts API Documentation