new Region(compute, name)

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

Parameters

Name Type Optional Description

compute

 

 

name

 

 

See also

Regions & Zones Overview

Region Resource

Properties

getAddressesStream

Get a list of Address objects in this region as a readable object stream.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

region.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.
//-
region.getAddressesStream()
  .on('data', function(address) {
    this.end();
  });

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getOperationsStream

Get a list of Operation objects for this region as a readable object stream.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

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

Parameter

Name Type Optional Description

options

object

Yes

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

Returns

stream 

getRulesStream

Get a list of Rule objects in this region as a readable object stream.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

region.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.
//-
region.getRulesStream()
  .on('data', function(rule) {
    this.end();
  });

Parameter

Name Type Optional Description

options

object

Yes

Configuration object. See Region#getRulesStream for a complete list of options.

Returns

stream 

getSubnetworksStream

Get a list of Subnetwork objects in this region as a readable object stream.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

region.getSubnetworksStream()
  .on('error', console.error)
  .on('data', function(subnetwork) {
    // `subnetwork` is a `Subnetwork` object.
  })
  .on('end', function() {
    // All subnetworks retrieved.
  });

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

Parameter

Name Type Optional Description

options

object

Yes

Configuration object. See Region#getSubnetworks for a complete list of options.

Returns

stream 

id  string

name  string

Methods

address(name) → Address

Get a reference to a Google Compute Engine address in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

const address = region.address('address-name');

Parameter

Name Type Optional Description

name

string

 

Name of the address.

See also

Instances and Networks

Returns

Address 

createAddress(name[, options], callback)

Create an address in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

function callback(err, address, operation, apiResponse) {
  // `address` is an Address object.

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

region.createAddress('new-address', callback);

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

Parameters

Name Type Optional Description

name

string

 

Name of the address.

options

object

Yes

See an Address resource.

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.

address

Address

 

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

Instances and Networks

Address Resource

Addresses: insert API Documentation

createRule(name, config, callback)

Create a forwarding rule in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

const name = 'new-rule-name';

const cfg = {
  target: 'zones/us-central1-a/targetInstances/my-target-instance',
  range: '8080-8089'
};

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

Parameters

Name Type Optional Description

name

string

 

Name of the rule.

config

object

 

See a ForwardingRule resource.

Values in config have the following properties:

Name Type Optional Description

ip

string

Yes

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

string

Yes

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

range

string

Yes

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.

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.

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

ForwardingRule Resource

ForwardingRules: insert API Documentation

createSubnetwork(name, config, callback)

Create a subnetwork in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

const config = {
  network: 'network1',
  range: '10.0.1.0/24'
};

function callback(err, subnetwork, operation, apiResponse) {
  // `subnetwork` is a Subnetwork object.

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

region.createSubnetwork('new-subnetwork-name', config, callback);

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

Parameters

Name Type Optional Description

name

string

 

Name of the subnetwork.

config

object

 

See a Subnetwork resource.

Values in config have the following properties:

Name Type Optional Description

network

(Network or string)

 

The network to which this subnetwork belongs. Only networks that are in the distributed mode can have subnetworks.

range

string

 

The range of internal addresses that are owned by this subnetwork. CIDR range of addresses that are legal on this network. (Alias for config.ipCidrRange)

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.

subnetwork

Subnetwork

 

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

Subnetwork Resource

Subnetwork: insert API Documentation

exists(callback)

Check if the region exists.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

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

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

get()

Get a region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

region.get(function(err, region, apiResponse) {
  // `region` is a Region object.
});

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

getAddresses([options], callback)

Get a list of addresses in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

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

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

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

Parameters

Name Type Optional Description

options

object

Yes

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

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

addresses

Array of Address

 

Address objects from this region.

apiResponse

object

 

The full API response.

See also

Instances and Networks

Addresses: list API Documentation

getMetadata([callback])

Get the region's metadata.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

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

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

apiResponse

object

 

The full API response.

See also

Region Resource

Regions: get API Documentation

getOperations([options], callback)

Get a list of operations for this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

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

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

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

Parameters

Name Type Optional Description

options

object

Yes

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

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

operations

Array of Operation

 

Operation objects from this region.

apiResponse

object

 

The full API response.

See also

Region Operation Overview

RegionOperations: list API Documentation

getRules([options], callback)

Get a list of forwading rules in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

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

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

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

Parameters

Name Type Optional Description

options

object

Yes

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

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

rules

Array of Rule

 

Rule objects from this region.

apiResponse

object

 

The full API response.

See also

ForwardingRules: list API Documentation

getSubnetworks([options], callback)

Get a list of subnetworks in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

region.getSubnetworks(function(err, subnetworks) {
  // `subnetworks` is an array of `Subnetwork` objects.
});

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

region.getSubnetworks({
  autoPaginate: false
}, callback);

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

Parameters

Name Type Optional Description

options

object

Yes

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

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

subnetworks

Array of Subnetwork

 

Subnetwork objects from this region.

apiResponse

object

 

The full API response.

See also

Subnetworks Overview

Subnetworks: list API Documentation

operation(name) → Operation

Get a reference to a Google Compute Engine region operation.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

const operation = region.operation('operation-name');

Parameter

Name Type Optional Description

name

string

 

Name of the existing operation.

See also

Region Operation Overview

Returns

Operation 

rule(name) → Rule

Get a reference to a Google Compute Engine forwarding rule in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

const rule = region.rule('rule-name');

Parameter

Name Type Optional Description

name

string

 

Name of the rule.

Returns

Rule 

subnetwork(name) → Subnetwork

Get a reference to a Google Compute Engine subnetwork in this region.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const region = compute.region('us-central1');

const subnetwork = region.subnetwork('subnetwork-name');

Parameter

Name Type Optional Description

name

string

 

Name of the subnetwork.

See also

Subnetworks Overview

Returns

Subnetwork