Network
Source: network.
A Network object allows you to interact with a Google Compute Engine network.
Properties
Methods
new Network(compute, name)
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const network = compute.network('network-name');
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
compute |
|
|
|
|
name |
|
|
- See also
Properties
compute Compute
The parent Compute instance of this Network instance.
formattedName string
id string
name string
Methods
create(config)
Create a network.
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];
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
config |
object |
|
createFirewall(name, config, callback)
Create a firewall for this network.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
name |
string |
|
Name of the firewall. |
||||||||||||||||||||
|
config |
object |
|
See a Firewall resource. Values in
|
||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
createSubnetwork(name, config, callback)
Create a subnetwork in this network.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
name |
string |
|
Name of the subnetwork. |
||||||||||||||||||||
|
config |
object |
|
See a Subnetwork resource. Values in
|
||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
delete([callback])
Delete the network.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function() |
Yes |
The callback function. Values in
|
- See also
exists(callback)
Check if the network exists.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function() |
|
The callback function. Values in
|
firewall(name)
Get a reference to a Google Compute Engine firewall in this network.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const network = compute.network('network-name');
const firewall = network.firewall('firewall-name');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the firewall. |
- See also
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.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
options |
Yes |
Configuration object. Values in
|
getFirewalls([options], callback)
Get a list of firewalls for this network.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Firewall search options. Values in
|
||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getFirewallsStream([options]) → stream
Get a list of Firewall objects for this network as a readable object 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();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Network#getFirewalls for a complete list of options. |
- Returns
-
stream
getMetadata([callback])
Get the network's metadata.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function() |
Yes |
The callback function. Values in
|
getSubnetworks([options], callback)
Get a list of subnetworks in this network.
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];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Subnetwork search options. Values in
|
||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getSubnetworksStream([options]) → stream
Get a Subnetwork list within this network as a readable object 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();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Network#getSubnetworks for a complete list of options. |
- Returns
-
stream