Constructor

InstanceGroupManager

new InstanceGroupManager(zone, name)

Parameter

zone

Zone

name

string

See also

Creating Groups of Instances

Managed Instance Groups

Example

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

Property

id

string

Methods

deleteInstances

deleteInstances(vms, callback)

Flags the specified instances in the managed instance group for immediate deletion.

Parameter

vms

(VM or Array of VM)

VM instances to delete from this instance group manager.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may 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

InstanceGroupManagers: deleteInstances API Documentation

Example

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

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

instanceGroupManager.deleteInstances(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.
//-
instanceGroupManager.deleteInstances(vms).then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});

exists

exists(callback)

Check if the instance group manager exists.

Parameter

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

exists

boolean

Whether the instance group manager exists or not.

Example

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

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

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

get

get(options)

Get an instance group manager 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.

Parameter

options

Optional

options

Configuration object.

Values in options have the following properties:

Parameter

autoCreate

boolean

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

Example

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

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

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

getManagedInstances

getManagedInstances(options, callback)

Get a list of managed VM instances in this instance group manager.

Parameter

options

Optional

object

Instance search options.

Values in options have the following properties:

Parameter

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.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

vms

Array of VM

VM objects from this instance group.

apiResponse

object

The full API response.

See also

InstanceGroupManagers: listManagedInstances API Documentation

Example

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

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

instanceGroupManager.getManagedInstances({
  autoPaginate: false
}, callback);

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

getMetadata

getMetadata(callback)

Get the instance group manager's metadata.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

metadata

object

The instance group manager's metadata.

apiResponse

object

The full API response.

See also

InstanceGroupManagers: get API Documentation

InstanceGroupManagers Resource

Example

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

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

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

resize

resize(size, callback)

Resizes the managed instance group.

Parameter

size

number

The number of running instances that the managed instance group should maintain at any given time.

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may 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

InstanceGroupManagers: resize API Documentation

Example

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

instanceGroupManager.resize(2, 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.
//-
instanceGroupManager.resize(2).then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});