Constructor
new Service(compute, name)
Parameters:
| Name | Type | Description |
|---|---|---|
compute |
Compute |
The Compute instance this service inherits from. |
name |
string |
Name of the service. |
Members
compute
id
name
Methods
create(config)
Create a backend service.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
object |
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const service = const.service('service-name');
const config = {
backends: [
{
group: 'URL of an Instance Group resource'
}
],
healthChecks: [
'URL of an HTTP/HTTPS health check resource'
]
};
service.create(config, function(err, service, operation, apiResponse) {
// `service` is a Service 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.
//-
service.create(config).then(function(data) {
const service = data[0];
const operation = data[1];
const apiResponse = data[2];
});
delete(callbackopt)
Delete the backend service.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const service = const.service('service-name');
service.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.
//-
service.delete().then(function(data) {
const operation = data[0];
const apiResponse = data[1];
});
exists(callback)
Check if the backend service exists.
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const service = const.service('service-name');
service.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
service.exists().then(function(data) {
const exists = data[0];
});
get(optionsopt)
Get a Service object 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 service = const.service('service-name');
service.get(function(err, service, apiResponse) {
// `service` is a Service object.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
service.get().then(function(data) {
const service = data[0];
const apiResponse = data[1];
});
getHealth(group, callback)
Get the most recent health check results.
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
group |
string | object |
The fully-qualified URL of an Instance Group resource. Properties
|
||||||||||||||||
callback |
function |
The callback function. Properties
|
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const service = const.service('service-name');
const group = {
name: 'instance-group-name',
zone: 'us-central1-a'
};
service.getHealth(group, function(err, status, apiResponse) {
if (!err) {
// status = [
// {
// ipAddress: '...',
// instance: '...',
// healthState: '...',
// port: '...'
// }
// ]
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
service.getHealth(group).then(function(data) {
const status = data[0];
const apiResponse = data[1];
});
getMetadata(callbackopt)
Get the metadata of this backend service.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const service = const.service('service-name');
service.getMetadata(function(err, metadata, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
service.getMetadata().then(function(data) {
const metadata = data[0];
const apiResponse = data[1];
});
setMetadata(metadata, callbackopt)
Set the backend service's metadata.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metadata |
object |
See a BackendService resource. |
|||||||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const service = const.service('service-name');
const metadata = {
description: 'New description'
};
service.setMetadata(metadata, 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.
//-
service.setMetadata(metadata).then(function(data) {
const operation = data[0];
const apiResponse = data[1];
});