InstanceGroup
Source: instance-group.
You can create and manage groups of virtual machine instances so that you don't have to individually control each instance in your project.
new InstanceGroup(zone, name)
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
zone |
|
|
|
|
name |
|
|
Properties
getVMsStream
Get a list of VM instances in this instance group as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
instanceGroup.getVMsStream()
.on('error', console.error)
.on('data', function(vm) {
// `vm` is a `VM` object.
})
.on('end', function() {
// All instances retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
instanceGroup.getVMsStream()
.on('data', function(vm) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See InstanceGroup#getVMs for a complete list of options. |
- Returns
-
stream
id string
name string
name string
zone Zone
The parent Zone instance of this InstanceGroup instance.
zone Zone
The parent Zone instance of this InstanceGroup instance.
Methods
add(vms, callback)
Add one or more VMs to this instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
const vms = [
gce.zone('us-central1-a').vm('http-server'),
gce.zone('us-central1-a').vm('https-server')
];
instanceGroup.add(vms, 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.
//-
instanceGroup.add(vms).then(function(data) {
const operation = data[0];
const apiResponse = data[1];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
vms |
|
VM instances to add to this instance group. |
|||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
create([options])
Create an instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
function onCreated(err, instanceGroup, operation, apiResponse) {
// `instanceGroup` is an InstanceGroup object.
// `operation` is an Operation object that can be used to check the
// status of the request.
}
instanceGroup.create(onCreated);
//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.create().then(function(data) {
const instanceGroup = data[0];
const operation = data[1];
const apiResponse = data[2];
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
delete([callback])
Delete the instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
instanceGroup.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.
//-
instanceGroup.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 instance group exists.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
instanceGroup.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.exists().then(function(data) {
const exists = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function() |
|
The callback function. Values in
|
get([options])
Get an instance group 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 zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
instanceGroup.get(function(err, instanceGroup, apiResponse) {
// `instanceGroup` is an InstanceGroup object.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.get().then(function(data) {
const instanceGroup = data[0];
const apiResponse = data[1];
});
Parameters
| Name | Type | Optional | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
options |
Yes |
Configuration object. Values in
|
getMetadata([callback])
Get the instance group's metadata.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
instanceGroup.getMetadata(function(err, metadata, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.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
|
getVMs([options], callback)
Get a list of VM instances in this instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
instanceGroup.getVMs(function(err, vms) {
// `vms` is an array of `VM` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, vms, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
instanceGroup.getVMs(nextQuery, callback);
}
}
instanceGroup.getVMs({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
instanceGroup.getVMs().then(function(data) {
const vms = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Instance search options. Values in
|
||||||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
remove(vms, callback)
Remove one or more VMs from this instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
const vms = [
gce.zone('us-central1-a').vm('http-server'),
gce.zone('us-central1-a').vm('https-server')
];
instanceGroup.remove(vms, 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.
//-
instanceGroup.remove(vms).then(function(data) {
const operation = data[0];
const apiResponse = data[1];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
vms |
|
VM instances to remove from this instance group. |
|||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
setPorts(ports[, callback])
Set the named ports for this instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('web-servers');
const ports = {
http: 80,
https: 443
};
instanceGroup.setPorts(ports, 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.
//-
instanceGroup.setPorts(ports).then(function(data) {
const operation = data[0];
const apiResponse = data[1];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
ports |
object |
|
A map of names to ports. The key should be the name, and the value the port number. |
||||||||||||||||
|
callback |
function() |
Yes |
The callback function. Values in
|