Members
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();
});
id
name
name
zone
The parent Zone instance of this InstanceGroup instance.
zone
The parent Zone instance of this InstanceGroup instance.
Methods
add(vms, callback)
Add one or more VMs to this instance group.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
vms |
VM | Array.<VM> |
VM instances to add to this instance group. |
||||||||||||||||
callback |
function |
The callback function. Properties
|
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];
});
create(optionsopt)
Create an instance group.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object |
<optional> |
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];
});
delete(callbackopt)
Delete the instance group.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
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];
});
exists(callback)
Check if the instance group exists.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
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];
});
get(optionsopt)
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.
Parameters:
Name | Type | Attributes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
options |
options |
<optional> |
Configuration object. Properties
|
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];
});
getMetadata(callbackopt)
Get the instance group'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 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];
});
getVMs(optionsopt, callback)
Get a list of VM instances in this instance group.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Instance search options. Properties
|
|||||||||||||||||||||
callback |
function |
The callback function. Properties
|
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];
});
remove(vms, callback)
Remove one or more VMs from this instance group.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
vms |
VM | Array.<VM> |
VM instances to remove from this instance group. |
||||||||||||||||
callback |
function |
The callback function. Properties
|
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];
});
setPorts(ports, callbackopt)
Set the named ports for this instance group.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ports |
object |
A map of names to ports. The key should be the name, and the value the port number. |
|||||||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
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];
});