Constructor

Subnetwork

new Subnetwork(region, name)

An Subnetwork object allows you to interact with a Google Compute Engine subnetwork.

Parameter

region

Region

Region this subnetwork belongs to.

name

string

Name of the subnetwork.

See also

Subnetworks Overview

Subnetwork Resource

Example

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

Properties

name

string

region

Region

The parent Region instance of this Subnetwork instance.

Methods

create

create(config)

Create a subnetwork.

Parameter

config

object

See Region#createSubnetwork.

Example

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

const config = {
  // ...
};

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

subnetwork.create(config, callback);

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

delete

delete(callback)

Delete the subnetwork.

Parameter

callback

Optional

function()

The callback function.

See also

Subnetworks: delete API Documentation

Example

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

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

exists

exists(callback)

Check if the subnetwork exists.

Parameter

callback

function()

The callback function.

Example

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

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

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

get

get(options)

Get a subnetwork 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 region = compute.region('region-name');
const subnetwork = region.subnetwork('subnetwork1');

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

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

getMetadata

getMetadata(callback)

Get the metadata of this subnetwork.

Parameter

callback

Optional

function()

The callback function.

See also

Subnetwork Resource

Subnetwork: get API Documentation

Example

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

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

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