InstanceGroup

InstanceGroup

You can create and manage groups of virtual machine instances so that you don't have to individually control each instance in your project.

Constructor

new InstanceGroup(zone, name)

Parameters:
Name Type Description
zone Zone
name string
Source:
See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');

Members

getVMsStream

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

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

id :string

Source:

name :string

Source:

name :string

Source:

zone :Zone

The parent Zone instance of this InstanceGroup instance.

Source:

zone :Zone

The parent Zone instance of this InstanceGroup instance.

Source:

Methods

add(vms, callback)

Add one or more VMs to this instance group.

Parameters:
Name Type Description
vms VM | Array.<VM>

VM instances to add to this instance group.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

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

apiResponse object

The full API response.

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

create(optionsopt)

Create an instance group.

Parameters:
Name Type Attributes Description
options object <optional>

See Zone#createInstanceGroup.

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

delete(callbackopt)

Delete the instance group.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

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

apiResponse object

The full API response.

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

exists(callback)

Check if the instance group exists.

Parameters:
Name Type Description
callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the instance group exists or not.

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

get(optionsopt)

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.

Parameters:
Name Type Attributes Description
options options <optional>

Configuration object.

Properties
Name Type Description
autoCreate boolean

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

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

getMetadata(callbackopt)

Get the instance group's metadata.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The instance group's metadata.

apiResponse object

The full API response.

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

getVMs(optionsopt, callback)

Get a list of VM instances in this instance group.

Parameters:
Name Type Attributes Description
options object <optional>

Instance search options.

Properties
Name Type 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.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

vms Array.<VM>

VM objects from this instance group.

apiResponse object

The full API response.

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

remove(vms, callback)

Remove one or more VMs from this instance group.

Parameters:
Name Type Description
vms VM | Array.<VM>

VM instances to remove from this instance group.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

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

apiResponse object

The full API response.

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

setPorts(ports, callbackopt)

Set the named ports for this instance group.

Parameters:
Name Type Attributes Description
ports object

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

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

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

apiResponse object

The full API response.

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