Constructor

Compute

new Compute(options)

Parameter

options

Optional

ClientConfig

Configuration options.

See also

What is Google Compute Engine?

Examples

Create a client that uses Application Default Credentials (ADC)

const Compute = require('@google-cloud/compute');
const compute = new Compute();

Create a client with explicit credentials

const Compute = require('@google-cloud/compute');
const compute = new Compute({
  projectId: 'your-project-id',
  keyFilename: '/path/to/keyfile.json'
});

Properties

Firewall

static

constructor

Firewall class.

See also
Firewall

HealthCheck

static

constructor

HealthCheck class.

See also
HealthCheck

Network

static

constructor

Network class.

See also
Network

Operation

static

constructor

Operation class.

See also
Operation

Project

static

constructor

Project class.

See also
Project

Region

static

constructor

Region class.

See also
Region

Rule

static

constructor

Rule class.

See also
Rule

Service

static

constructor

Service class.

See also
Service

Snapshot

static

constructor

Snapshot class.

See also
Snapshot

Zone

static

constructor

Zone class.

See also
Zone

getAddressesStream

Get a list of Address objects as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getAddresses for a complete list of options.

Returns

stream 

Example

gce.getAddressesStream()
  .on('error', console.error)
  .on('data', function(address) {
    // `address` is an `Address` object.
  })
  .on('end', function() {
    // All addresses retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getAddressesStream()
  .on('data', function(address) {
    this.end();
  });

getAutoscalersStream

Get a list of Autoscaler objects as a readable object stream.

Parameter

query

Optional

object

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

Returns

stream 

Example

gce.getAutoscalersStream()
  .on('error', console.error)
  .on('data', function(autoscaler) {
    // `autoscaler` is an `Autoscaler` object.
  })
  .on('end', function() {
    // All addresses retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getAutoscalersStream()
  .on('data', function(address) {
    this.end();
  });

Methods

createFirewall

createFirewall(name, config, callback)

Create a firewall.

Parameter

name

string

Name of the firewall.

config

object

See a Firewall resource.

Values in config have the following properties:

Parameter

protocols

object

A map of protocol to port range. The keys of the object refer to a protocol (e.g. tcp, udp) and the value for the key are the ports/port-ranges that are allowed to make a connection. If a true value, that means all ports on that protocol will be opened. If false, all traffic on that protocol will be blocked.

ranges

Array of string

The IP address blocks that this rule applies to, expressed in CIDR format.

tags

Array of string

Instance tags which this rule applies to.

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.

firewall

Firewall

The created Firewall 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

Firewalls Overview

Firewalls: insert API Documentation

Throws

Error 

if a name is not provided.

Error 

if a config object is not provided.

Example

var config = {
  protocols: {
    tcp: [3000],
    udp: [] // An empty array means all ports are allowed.
  },

  ranges: ['0.0.0.0/0']
};

function callback(err, firewall, operation, apiResponse) {
  // `firewall` is a Firewall object.

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

gce.createFirewall('new-firewall-name', config, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.createFirewall('new-firewall-name', config).then(function(data) {
  var firewall = data[0];
  var operation = data[1];
  var apiResponse = data[2];
});

createHealthCheck

createHealthCheck(name, options, callback)

Create an HTTP or HTTPS health check.

Parameter

name

string

Name of the HTTP or HTTPS health check to create.

options

Optional

object

See a HttpHealthCheck resource and HttpsHealthCheck resource.

Values in options have the following properties:

Parameter

https

boolean

Create an HTTPs health check. Default: false.

interval

number

How often (in seconds) to send a health check. The default value is 5 seconds. (Alias for options.checkIntervalSec)

timeout

number

How long (in seconds) to wait before claiming failure. The default value is 5 seconds. It is invalid for this value to be greater than checkIntervalSec. (Alias for options.timeoutSec)

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.

healthCheck

HealthCheck

The created HealthCheck 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

Health Checks Overview

HttpHealthCheck: insert API Documentation

HttpsHealthCheck: insert API Documentation

Example

function callback(err, healthCheck, operation, apiResponse) {
  // `healthCheck` is a HealthCheck object.

  // `operation` is an Operation object that can be used to check the status
  // of network creation.
}

gce.createHealthCheck('new-health-check-name', callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.createHealthCheck('new-health-check-name').then(function(data) {
  var healthCheck = data[0];
  var operation = data[1];
  var apiResponse = data[2];
});

createNetwork

createNetwork(name, config, callback)

Create a network.

Parameter

name

string

Name of the network.

config

object

See a Network resource.

Values in config have the following properties:

Parameter

gateway

string

A gateway address for default routing to other networks. (Alias for config.gatewayIPv4)

range

string

CIDR range of addresses that are legal on this network. (Alias for config.IPv4Range)

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.

network

Network

The created Network 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

Networks Overview

Networks: insert API Documentation

Example

var config = {
  range: '10.240.0.0/16'
};

function callback(err, network, operation, apiResponse) {
  // `network` is a Network object.

  // `operation` is an Operation object that can be used to check the status
  // of network creation.
}

gce.createNetwork('new-network', config, callback);

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

createRule

createRule(name, config, callback)

Create a global forwarding rule.

Parameter

name

string

Name of the rule.

config

object

See a GlobalForwardingRule resource.

Values in config have the following properties:

Parameter

ip

Optional

string

The single IP address this forwarding rule will match against. All traffic that matches the IP address, protocol, and ports of this forwarding rule will be handled by this rule. If specified, the IP address must be a static external IP address. To create a new ephemeral external IP address for the forwarding rule, leave this field empty. (Alias for config.IPAddress)

protocol

Optional

string

The type of protocol that this forwarding rule matches. Valid values are AH, ESP, SCTP, TCP, UDP. Default: TCP. (Alias for config.IPProtocol)

range

Optional

string

A single port or single contiguous port range, ranging from low to high for which this forwarding rule matches. Packets of the specified protocol sent to these ports will be forwarded on to the appropriate target pool or target instance. If this field is left empty, then the forwarding matches traffic for all ports for the specified protocol. (Alias for config.portRange)

target

string

The full or valid partial URL of the target resource to receive the matched traffic. This target must be a global TargetHttpProxy or TargetHttpsProxy resource.

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.

rule

Rule

The created Rule 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

GlobalForwardingRule Resource

GlobalForwardingRules: insert API Documentation

Example

var name = 'new-rule-name';

var config = {
  target: 'global/targetHttpProxies/my-proxy',
  range: '8080-8089'
};

gce.createRule(name, config, function (err, rule, operation, apiResponse) {
  // `rule` is a Rule 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.
//-
gce.createRule(name, config).then(function(data) {
  var rule = data[0];
  var operation = data[1];
  var apiResponse = data[2];
});

createService

createService(name, config, callback)

Create a backend service.

Parameter

name

string

Name of the backend service.

config

object

See a BackendService 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.

service

Service

The created Service 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

Backend Services Overview

BackendServices: insert API Documentation

Example

var config = {
  backends: [
    {
      group: 'URL of an Instance Group resource'
    }
  ],
  healthChecks: [
    'URL of an HTTP/HTTPS health check resource'
  ]
};

function callback(err, service, operation, apiResponse) {
  // `service` is a Service object.

  // `operation` is an Operation object that can be used to check the status
  // of network creation.
}

gce.createService('new-service', config, callback);

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

execAfterOperation_

execAfterOperation_() returns (function(), error, or object)

Register a single callback that will wait for an operation to finish before being executed.

Returns

function() 

callback - The callback function.

nullable error 

callback.err - An error returned from the operation.

object 

callback.apiResponse - The operation's final API response.

firewall

firewall(name) returns Firewall

Get a reference to a Google Compute Engine firewall.

See Network#firewall to get a Firewall object for a specific network.

Parameter

name

string

Name of the firewall.

See also

Firewalls Overview

Returns

Firewall 

Example

var firewall = gce.firewall('firewall-name');

getAddresses

getAddresses(options, callback)

Get a list of addresses. For a detailed description of method's options see API reference.

Parameter

options

Optional

object

Address 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 addresses 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.

addresses

Array of Address

Address objects from your project.

apiResponse

object

The full API response.

See also

Instances and Networks

Addresses: aggregatedList API Documentation

Example

gce.getAddresses(function(err, addresses) {
  // addresses is an array of `Address` objects.
});

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

gce.getAddresses({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getAddresses().then(function(data) {
  var addresses = data[0];
});

getAutoscalers

getAutoscalers(options, callback)

Get a list of autoscalers. For a detailed description of this method's options, see the API reference.

Parameter

options

Optional

object

Address 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 addresses 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.

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

Example

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

gce.getAutoscalers({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getAutoscalers().then(function(data) {
  var autoscalers = data[0];
});

getDisks

getDisks(options, callback)

Get a list of disks.

Parameter

options

Optional

object

Disk 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 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:

Parameter

err

error

An error returned while making this request.

Value may be null.

disks

Array of Disk

Disk objects from your project.

apiResponse

object

The full API response.

See also

Disks Overview

Disks: aggregatedList API Documentation

Example

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

gce.getDisks({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getDisks().then(function(data) {
  var disks = data[0];
});

getDisksStream

getDisksStream(options) returns stream

Get a list of Disk objects as a readable object stream.

Parameter

options

Optional

object

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

Returns

stream 

Example

gce.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.
//-
gce.getDisksStream()
  .on('data', function(disk) {
    this.end();
  });

getFirewalls

getFirewalls(options, callback)

Get a list of firewalls.

Parameter

options

Optional

object

Firewall 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 firewalls 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.

firewalls

Array of Firewall

Firewall objects from your project.

apiResponse

object

The full API response.

See also

Firewalls Overview

Firewalls: list API Documentation

Example

gce.getFirewalls(function(err, firewalls) {
  // `firewalls` is an array of `Firewall` objects.
});

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

gce.getFirewalls({
  autoPaginate: false
}, callback);

gce.getFirewalls().then(function(data) {
  var firewalls = data[0];
});

getFirewallsStream

getFirewallsStream(query) returns stream

Get a list of Firewall objects as a readable object stream.

Parameter

query

Optional

object

Configuration object. See Compute#getFirewalls for a complete list of options.

Returns

stream 

Example

gce.getFirewallsStream()
  .on('error', console.error)
  .on('data', function(firewall) {
    // `firewall` is a `Firewall` object.
  })
  .on('end', function() {
    // All firewalls retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getFirewallsStream()
  .on('data', function(firewall) {
    this.end();
  });

getHealthChecks

getHealthChecks(options, callback)

Get a list of health checks.

Parameter

options

Optional

object

Health check 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.

https

boolean

List only HTTPs health checks. Default: false.

maxApiCalls

number

Maximum number of API calls to make.

maxResults

number

Maximum number of networks 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.

healthChecks

Array of HealthCheck

HealthCheck objects from your project.

apiResponse

object

The full API response.

See also

Health Checks Overview

HttpHealthCheck: list API Documentation

HttpsHealthCheck: list API Documentation

Example

gce.getHealthChecks(function(err, healthChecks) {
  // `healthChecks` is an array of `HealthCheck` objects.
});

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

gce.getHealthChecks({
  autoPaginate: false
}, callback);

gce.getHealthChecks().then(function(data) {
  var healthChecks = data[0];
});

getHealthChecksStream

getHealthChecksStream(options) returns stream

Get a list of HealthCheck objects as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getHealthChecks for a complete list of options.

Returns

stream 

Example

gce.getHealthChecksStream()
  .on('error', console.error)
  .on('data', function(healthCheck) {
    // `healthCheck` is a `HealthCheck` object.
  })
  .on('end', function() {
    // All health checks retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getHealthChecksStream()
  .on('data', function(healthCheck) {
    this.end();
  });

getInstanceGroups

getInstanceGroups(options, callback)

Get a list of instance groups.

Parameter

options

Optional

object

Instance group 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 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:

Parameter

err

error

An error returned while making this request.

Value may be null.

instanceGroups

Array of InstanceGroup

InstanceGroup objects from your project.

apiResponse

object

The full API response.

See also

InstanceGroups Overview

InstanceGroups: aggregatedList API Documentation

Example

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

gce.getInstanceGroups({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getInstanceGroups().then(function(data) {
  var instanceGroups = data[0];
});

getInstanceGroupsStream

getInstanceGroupsStream(options) returns stream

Get a list of InstanceGroup objects as a readable object stream.

Parameter

options

Optional

object

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

Returns

stream 

Example

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

getMachineTypes

getMachineTypes(options, callback)

Get a list of machine types in this project.

Parameter

options

Optional

object

Machine type 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 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:

Parameter

err

error

An error returned while making this request.

Value may be null.

machineTypes

Array of MachineType

MachineType objects from your project.

apiResponse

object

The full API response.

See also

MachineTypes: list API Documentation

Machine Types Overview

MachineType Resource

Example

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

gce.getMachineTypes({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getMachineTypes().then(function(data) {
  var machineTypes = data[0];
});

getMachineTypesStream

getMachineTypesStream(options) returns stream

Get a list of MachineType objects in this project as a readable object stream.

Parameter

options

Optional

object

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

Returns

stream 

Example

gce.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.
//-
gce.getMachineTypesStream()
  .on('data', function(machineType) {
    this.end();
  });

getNetworks

getNetworks(options, callback)

Get a list of networks.

Parameter

options

Optional

object

Network 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 networks 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.

networks

Array of Network

Network objects from your project.

apiResponse

object

The full API response.

See also

Networks Overview

Networks: list API Documentation

Example

gce.getNetworks(function(err, networks) {
  // `networks` is an array of `Network` objects.
});

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

gce.getNetworks({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getNetworks().then(function(data) {
  var networks = data[0];
});

getNetworksStream

getNetworksStream(options) returns stream

Get a list of Network objects as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getNetworks for a complete list of options.

Returns

stream 

Example

gce.getNetworksStream()
  .on('error', console.error)
  .on('data', function(network) {
    // `network` is a `Network` object.
  })
  .on('end', function() {
    // All networks retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getNetworksStream()
  .on('data', function(network) {
    this.end();
  });

getOperations

getOperations(options, callback)

Get a list of global operations.

Parameter

options

Optional

object

Operation 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 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:

Parameter

err

error

An error returned while making this request.

Value may be null.

operations

Array of Operation

Operation objects from your project.

apiResponse

object

The full API response.

See also

Global Operation Overview

GlobalOperations: list API Documentation

Example

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

gce.getOperations({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getOperations().then(function(data) {
  var operations = data[0];
});

getOperationsStream

getOperationsStream(options) returns stream

Get a list of global Operation objects as a readable object stream.

Parameter

options

Optional

object

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

Returns

stream 

Example

gce.getOperationsStream()
  .on('error', console.error)
  .on('data', function(operation) {
    // `operation` is a `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.
//-
gce.getOperationsStream()
  .on('data', function(operation) {
    this.end();
  });

getRegions

getRegions(options, callback)

Return the regions available to your project.

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

regions

Array of Region

Region objects that are available to your project.

apiResponse

object

The full API response.

See also

Regions & Zones Overview

Regions: list API Documentation

Example

gce.getRegions(function(err, regions) {
  // `regions` is an array of `Region` objects.
});

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

gce.getRegions({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getRegions().then(function(data) {
  var regions = data[0];
});

getRegionsStream

getRegionsStream(options) returns stream

Return the Region objects available to your project as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getRegions for a complete list of options.

Returns

stream 

Example

gce.getRegionsStream()
  .on('error', console.error)
  .on('data', function(region) {
    // `region` is a `Region` object.
  })
  .on('end', function() {
    // All regions retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getRegionsStream()
  .on('data', function(region) {
    this.end();
  });

getRules

getRules(options, callback)

Get a list of forwarding rules.

Parameter

options

Optional

object

Rules 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 rules 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.

rules

Array of Rule

Rule objects from your project.

apiResponse

object

The full API response.

See also

GlobalForwardingRules: list API Documentation

Example

gce.getRules(function(err, rules) {
  // `rules` is an array of `Rule` objects.
});

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

gce.getRules({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getRules().then(function(data) {
  var rules = data[0];
});

getRulesStream

getRulesStream(options) returns stream

Get a list of Rule objects as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getRules for a complete list of options.

Returns

stream 

Example

gce.getRulesStream()
  .on('error', console.error)
  .on('data', function(rule) {
    // `rule` is a `Rule` object.
  })
  .on('end', function() {
    // All rules retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getRulesStream()
  .on('data', function(rule) {
    this.end();
  });

getServices

getServices(options, callback)

Get a list of backend services.

Parameter

options

Optional

object

BackendService 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 snapshots 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.

services

Array of Service

Service objects from your project.

apiResponse

object

The full API response.

See also

Backend Services Overview

BackendServices: list API Documentation

Example

gce.getServices(function(err, services) {
  // `services` is an array of `Service` objects.
});

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

gce.getServices({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getServices().then(function(data) {
  var services = data[0];
});

getServicesStream

getServicesStream(options) returns stream

Get a list of Service objects as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getServices for a complete list of options.

Returns

stream 

Example

gce.getServicesStream()
  .on('error', console.error)
  .on('data', function(service) {
    // `service` is a `Service` object.
  })
  .on('end', function() {
    // All services retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getServicesStream()
  .on('data', function(service) {
    this.end();
  });

getSnapshots

getSnapshots(options, callback)

Get a list of snapshots.

Parameter

options

Optional

object

Snapshot 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 snapshots 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.

snapshots

Array of Snapshot

Snapshot objects from your project.

apiResponse

object

The full API response.

See also

Snapshots Overview

Snapshots: list API Documentation

Example

gce.getSnapshots(function(err, snapshots) {
  // `snapshots` is an array of `Snapshot` objects.
});

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

gce.getSnapshots({
  autoPaginate: false
}, callback);

//-
// If the callback is omitted, we'll return a Promise.
//-
gce.getSnapshots().then(function(data) {
  var snapshots = data[0];
});

getSnapshotsStream

getSnapshotsStream(options) returns stream

Get a list of Snapshot objects as a readable object stream.

Parameter

options

Optional

object

Configuration object. See Compute#getSnapshots for a complete list of options.

Returns

stream 

Example

gce.getSnapshotsStream()
  .on('error', console.error)
  .on('data', function(snapshot) {
    // `snapshot` is a `Snapshot` object.
  })
  .on('end', function() {
    // All snapshots retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
gce.getSnapshotsStream()
  .on('data', function(snapshot) {
    this.end();
  });

getSubnetworks

getSubnetworks(options, callback)

Get a list of subnetworks in this project.

Parameter

options

Optional

object

Subnetwork 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 subnetworks 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