Zone
Source: zone.
A Zone object allows you to interact with a Google Compute Engine zone.
Properties
Methods
new Zone(compute, name)
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
compute |
|
|
Compute object this zone belongs to. |
|
name |
|
|
Name of the zone. |
- See also
Properties
compute Compute
The parent Compute instance of this Zone instance.
getAutoscalersStream
Get a list of Autoscaler objects from this zone as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getAutoscalersStream()
.on('error', console.error)
.on('data', function(autoscaler) {
// `autoscaler` is an `Autoscaler` object.
})
.on('end', function() {
// All autoscalers retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getAutoscalersStream()
.on('data', function(autoscaler) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Zone#getAutoscalers for a complete list of options. |
- Returns
-
stream
getDisksStream
Get a list of Disk objects in this zone as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getDisksStream()
.on('error', console.error)
.on('data', function(disk) {
// `disk` is a `Disk` object.
})
.on('end', function() {
// All disks retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getDisksStream()
.on('data', function(disk) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Zone#getDisks for a complete list of options. |
- Returns
-
stream
getInstanceGroupsStream
Get a list of InstanceGroup objects for this zone as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getInstanceGroupsStream()
.on('error', console.error)
.on('data', function(instanceGroup) {
// `instanceGroup` is an `InstanceGroup` object.
})
.on('end', function() {
// All instance groups retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getInstanceGroupsStream()
.on('data', function(instanceGroup) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Zone#getInstanceGroups for a complete list of options. |
- Returns
-
stream
getMachineTypesStream
Get a list of MachineType objects for this zone as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getMachineTypesStream()
.on('error', console.error)
.on('data', function(machineType) {
// `machineType` is a `MachineType` object.
})
.on('end', function() {
// All machine types retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getMachineTypesStream()
.on('data', function(machineType) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Zone#getMachineTypes for a complete list of options. |
- Returns
-
stream
getOperationsStream
Get a list of Operation objects for this zone as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getOperationsStream()
.on('error', console.error)
.on('data', function(operation) {
// `operation` is an `Operation` object.
})
.on('end', function() {
// All operations retrieved.
});
//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
zone.getOperationsStream()
.on('data', function(operation) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Zone#getOperations for a complete list of options. |
- Returns
-
stream
getVMsStream
Get a list of VM instances in this zone as a readable object stream.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.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.
//-
zone.getVMsStream()
.on('data', function(vm) {
this.end();
});
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
options |
object |
Yes |
Configuration object. See Zone#getVMs for a complete list of options. |
- Returns
-
stream
id string
name string
Methods
autoscaler(name) → Autoscaler
Get a reference to a Google Compute Engine autoscaler in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const autoscaler = zone.autoscaler('autoscaler-name');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the autoscaler. |
- Returns
createAutoscaler(name, config, callback)
Create an autoscaler in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const config = {
coolDown: 30,
cpu: 80,
loadBalance: 40,
maxReplicas: 5,
minReplicas: 0,
target: 'instance-group-manager-1'
};
function callback(err, autoscaler, operation, apiResponse) {
// `autoscaler` is an Autoscaler object.
// `operation` is an Operation object that can be used to check the status
// of the request.
}
zone.createAutoscaler('name', config, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createAutoscaler('name', config).then(function(data) {
const autoscaler = data[0];
const operation = data[1];
const apiResponse = data[2];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
name |
string |
|
Name of the autoscaler. |
||||||||||||||||||||||||||||
|
config |
object |
|
See an Autoscaler resource. Values in
|
||||||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
- See also
- Throws
-
ErrorIf
config.targetis not provided.
createDisk(name, config, callback)
Create a persistent disk in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
//-
// Create a persistent disk using the latest Ubuntu version
// as the source image.
//-
const config = {
os: 'ubuntu',
sizeGb: 10
};
//-
// Create a persistent disk using the latest Ubuntu version from your project
// as the source image.
//-
const config = {
os: 'your-project-id-or-name/ubuntu',
sizeGb: 10
};
zone.createDisk('name', config, function(err, disk, operation, apiResponse) {
// `disk` is a Disk object.
// `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.
//-
zone.createDisk('name', config).then(function(data) {
const disk = data[0];
const operation = data[1];
const apiResponse = data[2];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
name |
string |
|
Name of the disk. |
||||||||||||||||||||
|
config |
object |
|
See a Disk resource. Values in
|
||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
createInstanceGroup(name, options, callback)
Create an instance group in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
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.
}
zone.createInstanceGroup('instance-group-name', onCreated);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createInstanceGroup('instance-group-name', config).then(function(data) {
const instanceGroup = data[0];
const operation = data[1];
const apiResponse = data[2];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
name |
string |
|
Name of the instance group. |
||||||||||||||||||||
|
options |
object |
|
See an InstanceGroup resource. Values in
|
||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
createVM(name, config, callback)
Create a virtual machine in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
//-
// Create a new instance using the latest Debian version from your project
// as the source image for a new boot disk.
//-
const config = {
os: 'your-project-id-or-name/debian',
http: true,
tags: ['debian-server']
};
//-
// Create a new instance using the latest Debian version as the source image
// for a new boot disk.
//-
const config = {
os: 'debian',
http: true,
tags: ['debian-server']
};
//-
// The above object will auto-expand behind the scenes to something like the
// following. The Debian version may be different when you run the command.
//-
const config = {
machineType: 'n1-standard-1',
disks: [
{
boot: true,
initializeParams: {
sourceImage:
'https://www.googleapis.com/compute/v1/projects' +
'/debian-cloud/global/images/debian-7-wheezy-v20150710'
}
}
],
networkInterfaces: [
{
network: 'global/networks/default'
}
],
tags: [
{
items: [
'debian-server',
'http-server'
]
}
]
};
function callback(err, vm, operation, apiResponse) {
// `vm` is a VM object.
// `operation` is an Operation object that can be used to check the status
// of the request.
}
zone.createVM('new-vm-name', config, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.createVM('new-vm-name', config).then(function(data) {
const vm = data[0];
const operation = data[1];
const apiResponse = data[2];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
name |
string |
|
Name of the instance. |
||||||||||||||||||||||||||||||||
|
config |
object |
|
See an Instance resource. Values in
|
||||||||||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
disk(name) → Disk
Get a reference to a Google Compute Engine disk in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const disk = zone.disk('disk1');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the disk. |
- See also
- Returns
exists(callback)
Check if the zone exists.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.exists().then(function(data) {
const exists = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
callback |
function() |
|
The callback function. Values in
|
get()
Get a zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.get(function(err, zone, apiResponse) {
// `zone` is a Zone object.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.get().then(function(data) {
const zone = data[0];
const apiResponse = data[1];
});
getAutoscalers([options], callback)
Get a list of autoscalers from this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getAutoscalers(function(err, autoscalers) {
// autoscalers is an array of `Autoscaler` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, autoscalers, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
zone.getAutoscalers(nextQuery, callback);
}
}
zone.getAutoscalers({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getAutoscalers().then(function(data) {
const autoscalers = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Autoscaler search options. Values in
|
||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
- See also
getDisks([options], callback)
Get a list of disks in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getDisks(function(err, disks) {
// `disks` is an array of `Disk` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, disks, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
zone.getDisks(nextQuery, callback);
}
}
zone.getDisks({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getDisks().then(function(data) {
const disks = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Disk search options. Values in
|
||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getInstanceGroupManagers([options], callback)
Get a list of instance group managers for this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getInstanceGroupManagers(function(err, instanceGroupManagers) {
// `instanceGroupManagers` is an array of `InstanceGroupManager` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, instanceGroupManagers, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
zone.getInstanceGroupManagers(nextQuery, callback);
}
}
zone.getInstanceGroupManagers({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getInstanceGroupManagers().then(function(data) {
const instanceGroupManagerss = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Instance group manager search options. Values in
|
||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getInstanceGroups([options], callback)
Get a list of instance groups for this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getInstanceGroups(function(err, instanceGroups) {
// `instanceGroups` is an array of `InstanceGroup` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, instanceGroups, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
zone.getInstanceGroups(nextQuery, callback);
}
}
zone.getInstanceGroups({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getInstanceGroups().then(function(data) {
const instanceGroups = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Instance group search options. Values in
|
||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getMachineTypes([options], callback)
Get a list of machine types for this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getMachineTypes(function(err, machineTypes) {
// `machineTypes` is an array of `MachineType` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, machineTypes, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
zone.getMachineTypes(nextQuery, callback);
}
}
zone.getMachineTypes({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getMachineTypes().then(function(data) {
const machineTypes = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Machine type search options. Values in
|
||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getMetadata([callback])
Get the zone's metadata.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getMetadata(function(err, metadata, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.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
|
getOperations([options], callback)
Get a list of operations for this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.getOperations(function(err, operations) {
// `operations` is an array of `Operation` objects.
});
//-
// To control how many API requests are made and page through the results
// manually, set `autoPaginate` to `false`.
//-
function callback(err, operations, nextQuery, apiResponse) {
if (nextQuery) {
// More results exist.
zone.getOperations(nextQuery, callback);
}
}
zone.getOperations({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.getOperations().then(function(data) {
const operations = data[0];
});
Parameters
| Name | Type | Optional | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
options |
object |
Yes |
Operation search options. Values in
|
||||||||||||||||||||||||
|
callback |
function() |
|
The callback function. Values in
|
getVMs([options], callback)
Get a list of VM instances in this zone.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
zone.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.
zone.getVMs(nextQuery, callback);
}
}
zone.getVMs({
autoPaginate: false
}, callback);
//-
// If the callback is omitted, we'll return a Promise.
//-
zone.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
|
instanceGroup(name) → InstanceGroup
Get a reference to a Google Compute Engine instance group.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroup = zone.instanceGroup('my-instance-group');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the existing instance group. |
- See also
- Returns
instanceGroupManager(name) → InstanceGroupManager
Get a reference to a Google Compute Engine instance group manager.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const instanceGroupManager = zone.instanceGroupManager('my-instance-group-manager');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the existing instance group manager. |
- See also
- Returns
machineType(name) → MachineType
Get a reference to a Google Compute Engine machine type.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const machineType = zone.machineType('g1-small');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the existing machine type. |
- See also
- Returns
operation(name) → Operation
Get a reference to a Google Compute Engine zone operation.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const operation = zone.operation('operation-1445532685163-8b137d2a-1822afe7');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the existing operation. |
- See also
- Returns
vm(name) → VM
Get a reference to a Google Compute Engine virtual machine instance.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const vm = zone.vm('vm-name');
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
name |
string |
|
Name of the virtual machine. |
- See also
- Returns