Constructor
new Network(compute, name)
Parameters:
| Name | Type | Description |
|---|---|---|
compute |
Compute | |
name |
strign |
Members
compute
formattedName
id
name
Methods
create(config)
Create a network.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
object |
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(name, config, callback)
Create a firewall for this network.
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string |
Name of the firewall. |
||||||||||||||||||||
config |
object |
See a Firewall resource. Properties
|
||||||||||||||||||||
callback |
function |
The callback function. Properties
|
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(name, config, callback)
Create a subnetwork in this network.
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string |
Name of the subnetwork. |
||||||||||||||||||||
config |
object |
See a Subnetwork resource. Properties
|
||||||||||||||||||||
callback |
function |
The callback function. Properties
|
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(callbackopt)
Delete the network.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
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(callback)
Check if the network exists.
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
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(name)
Get a reference to a Google Compute Engine firewall in this network.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string |
Name of the firewall. |
- See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const network = compute.network('network-name');
const firewall = network.firewall('firewall-name');
get(optionsopt)
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.
Parameters:
| Name | Type | Attributes | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
options |
options |
<optional> |
Configuration object. Properties
|
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(optionsopt, callback)
Get a list of firewalls for this network.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Firewall search options. Properties
|
||||||||||||||||
callback |
function |
The callback function. Properties
|
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(optionsopt) → {stream}
Get a list of Firewall objects for this network as a readable object stream.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
options |
object |
<optional> |
Configuration object. See Network#getFirewalls for a complete list of options. |
Returns:
| Type | Description |
|---|---|
| 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(callbackopt)
Get the network's metadata.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
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(optionsopt, callback)
Get a list of subnetworks in this network.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Subnetwork search options. Properties
|
||||||||||||||||||
callback |
function |
The callback function. Properties
|
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(optionsopt) → {stream}
Get a Subnetwork list within this network as a readable object stream.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
options |
object |
<optional> |
Configuration object. See Network#getSubnetworks for a complete list of options. |
Returns:
| Type | Description |
|---|---|
| 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();
});