Constructor

Network

new Network(compute, name)

A Network object allows you to interact with a Google Compute Engine network.

Parameter

compute

Compute

name

strign

See also

Networks Overview

Network Resource

Example

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

Properties

compute

Compute

The parent Compute instance of this Network instance.

formattedName

string

id

string

name

string

Methods

create

create(config)

Create a network.

Parameter

config

object

See Compute#createNetwork.

Example

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

const config = {
  // ...
};

network.create(config, function(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.
});


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

createFirewall

createFirewall(name, config, callback)

Create a firewall for this network.

Parameter

name

string

Name of the firewall.

config

object

See a Firewall resource.

callback

function()

The callback function.

See also

Firewalls Overview

Firewalls: insert API Documentation

Example

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

const 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.
}

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

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

createSubnetwork

createSubnetwork(name, config, callback)

Create a subnetwork in this network.

Parameter

name

string

Name of the subnetwork.

config

object

See a Subnetwork resource.

callback

function()

The callback function.

See also

Subnetwork Resource

Subnetwork: insert API Documentation

Example

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

const config = {
  region: region,
  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.
}

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

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

delete

delete(callback)

Delete the network.

Parameter

callback

Optional

function()

The callback function.

See also

Networks: delete API Documentation

Example

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

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

exists

exists(callback)

Check if the network exists.

Parameter

callback

function()

The callback function.

Example

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

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

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

firewall

firewall(name)

Get a reference to a Google Compute Engine firewall in this network.

Parameter

name

string

Name of the firewall.

See also

Firewalls Overview

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const network = compute.network('network-name');
const firewall = network.firewall('firewall-name');

get

get(options)

Get a network 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.

Example

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

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

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

getFirewalls

getFirewalls(options, callback)

Get a list of firewalls for this network.

Parameter

options

Optional

object

Firewall search options.

callback

function()

The callback function.

See also

Firewalls Overview

Firewalls: list API Documentation

Example

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

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

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

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

getFirewallsStream

getFirewallsStream(options) returns stream

Get a list of Firewall objects for this network as a readable object stream.

Parameter

options

Optional

object

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

Returns

stream 

Example

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

network.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.
//-
network.getFirewallsStream()
  .on('data', function(firewall) {
    this.end();
  });

getMetadata

getMetadata(callback)

Get the network's metadata.

Parameter

callback

Optional

function()

The callback function.

See also

Network Resource

Networks: get API Documentation

Example

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

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

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

getSubnetworks

getSubnetworks(options, callback)

Get a list of subnetworks in this network.

Parameter

options

Optional

object

Subnetwork search options.

callback

function()

The callback function.

See also

Subnetworks Overview

Subnetworks: list API Documentation

Example

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

network.getSubnetworks(function(err, subnetworks) {
  // `subnetworks` is an array of `Subnetworks` 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.
    network.getSubnetworks(nextQuery, callback);
  }
}

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

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

getSubnetworksStream

getSubnetworksStream(options) returns stream

Get a Subnetwork list within this network as a readable object stream.

Parameter

options

Optional

object

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

Returns

stream 

Example

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

network.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.
//-
network.getSubnetworksStream()
  .on('data', function(subnetwork) {
    this.end();
  });