Rule
Source: rule.
Forwarding rules work in conjunction with target pools and target instances to support load balancing and protocol forwarding features. To use load balancing and protocol forwarding, you must create a forwarding rule that directs traffic to specific target pools (for load balancing) or target instances (for protocol forwarding).
new Rule(scope, name)
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
//-
// Reference a global rule.
//-
const rule = compute.rule('rule-name');
//-
// Reference a region rule.
//-
const region = compute.region('us-central1');
const rule = region.rule('rule-name');
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
scope |
|
|
The parent scope this firewall rule belongs to. |
|
name |
|
|
Rule name. |
- See also
Properties
id string
scope (Compute or Region)
Methods
create(config)
Create a forwarding rule.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const rule = region.rule('rule-name');
const config = {
// `target` will be different depending of this is a Regional or Global
// forwarding rule
target: 'global/targetHttpProxies/my-proxy',
portRange: '8080-8089'
};
rule.create(config, function(err, rule, operation, apiResponse) {
// `rule` is a Rule object.
// `operation` is an Operation object that can be used to check the
// of the request.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
rule.create(config).then(function(data) {
const rule = data[0];
const operation = data[1];
const apiResponse = data[2];
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
config |
object |
|
See Compute#createRule or Region#createRule if accessing this object through a Region. |
delete([callback])
Delete the rule.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const rule = compute.rule('rule-name');
rule.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.
//-
rule.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
|
exists(callback)
Check if the forwarding rule exists.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const rule = region.rule('rule-name');
rule.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
rule.exists().then(function(data) {
const exists = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function() |
|
The callback function. Values in
|
get([options])
Get a forwarding rule 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 rule = region.rule('rule-name');
rule.get(function(err, rule, apiResponse) {
// `rule` is a Rule object.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
rule.get().then(function(data) {
const rule = data[0];
const apiResponse = data[1];
});
Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
options |
Yes |
Configuration object. Values in
|
getMetadata([callback])
Get the metadata of this rule.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const rule = region.rule('rule-name');
rule.getMetadata(function(err, metadata, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
rule.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
|
- See also
setTarget(target, callback)
Set the target for this forwarding rule.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const rule = compute.rule('rule-name');
rule.setTarget('new-target', 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.
//-
rule.setTarget('new-target').then(function(data) {
const operation = data[0];
const apiResponse = data[1];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
target |
string |
|
The full or valid partial URL of the target resource
to receive the matched traffic. For regional forwarding rules, this
target must live in the same region as the forwarding rule. For global
forwarding rules, this target must be a global |
||||||||||||
|
callback |
function() |
|
The callback function. Values in
|