Constructor

Autoscaler

new Autoscaler(zone, name)

Autoscalers allow you to automatically scale virtual machine instances in managed instance groups according to an autoscaling policy that you define.

Parameter

zone

Zone

name

string

See also

Autoscaling Groups of Instances

Example

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

Properties

name

string

zone

Zone

Parent Zone instance of this Autoscaler instance.

Methods

create

create(config)

Create an autoscaler.

Parameter

config

object

See {Zone#createAutoscaler}.

Example

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

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

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

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

autoscaler.create(config, callback);

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

delete

delete(callback)

Delete the autoscaler.

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.

operation

Operation

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

apiResponse

object

The full API response.

See also

Autoscalers: delete API Documentation

Example

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

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

exists

exists(callback)

Check if the autoscaler 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 autoscaler exists or not.

Example

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

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

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

get

get(options)

Get an autoscaler 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 autoscaler = zone.autoscaler('autoscaler-name');

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

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

getMetadata

getMetadata(callback)

Get the metadata of this autoscaler.

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 autoscaler's metadata.

apiResponse

object

The full API response.

See also

Autoscaler Resource

Autoscalers: get API Documentation

Example

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

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

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

setMetadata

setMetadata(metadata, callback)

Set the autoscaler's metadata.

Parameter

metadata

object

See a Firewall resource.

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.

operation

Operation

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

apiResponse

object

The full API response.

See also

Autoscaler Resource

Example

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

const metadata = {
  description: 'New description'
};

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