Constructor

Firewall

new Firewall(compute, name)

A Firewall object allows you to interact with a Google Compute Engine firewall.

Parameter

compute

Compute

name

string

See also

Firewalls Overview

Firewall Resource

Example

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

Properties

compute

Compute

The parent Compute instance of this Firewall instance.

id

string

metadata

object

name

string

Methods

create

create(config)

Create a firewall.

Parameter

config

object

See Compute#createFirewall.

Example

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

const config = {
  // ...
};

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

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

delete

delete(callback)

Delete the firewall.

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

Firewalls: delete API Documentation

Example

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

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

exists

exists(callback)

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

Example

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

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

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

get

get(options)

Get a firewall 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 firewall = compute.firewall('tcp-3000');

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

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

getMetadata

getMetadata(callback)

Get the firewall's metadata.

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

apiResponse

object

The full API response.

See also

Firewalls: get API Documentation

Firewall Resource

Example

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

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

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

setMetadata

setMetadata(metadata, callback)

Set the firewall'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

Firewall Resource

Example

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

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

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