Constructor
new Rule(scope, name)
Parameters:
| Name | Type | Description |
|---|---|---|
scope |
Compute | Region |
The parent scope this firewall rule belongs to. |
name |
string |
Rule name. |
- See:
Members
id
scope
Methods
create(config)
Create a forwarding rule.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
object |
See Compute#createRule or Region#createRule if accessing this object through a Region. |
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];
});
delete(callbackopt)
Delete the rule.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
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];
});
exists(callback)
Check if the forwarding rule exists.
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
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];
});
get(optionsopt)
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.
Parameters:
| Name | Type | Attributes | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
options |
options |
<optional> |
Configuration object. Properties
|
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];
});
getMetadata(callbackopt)
Get the metadata of this rule.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
- See:
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];
});
setTarget(target, callback)
Set the target for this forwarding rule.
Parameters:
| Name | Type | 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. Properties
|
- See:
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];
});