Skip to content

Commit cee66d9

Browse files
rename Instance to VM
1 parent d8add07 commit cee66d9

8 files changed

Lines changed: 395 additions & 236 deletions

File tree

docs/site/components/docs/docs-values.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ angular.module('gcloud.docs')
5555
title: 'Firewall',
5656
url: '/firewall'
5757
},
58-
{
59-
title: 'Instance',
60-
url: '/instance'
61-
},
6258
{
6359
title: 'Network',
6460
url: '/network'
@@ -75,6 +71,10 @@ angular.module('gcloud.docs')
7571
title: 'Snapshot',
7672
url: '/snapshot'
7773
},
74+
{
75+
title: 'VM',
76+
url: '/vm'
77+
},
7878
{
7979
title: 'Zone',
8080
url: '/zone'

lib/compute/index.js

Lines changed: 121 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ var streamRouter = require('../common/stream-router.js');
6565
*/
6666
var util = require('../common/util.js');
6767

68+
/**
69+
* @type {module:compute/vm}
70+
* @private
71+
*/
72+
var VM = require('./vm.js');
73+
6874
/**
6975
* @type {module:compute/zone}
7076
* @private
@@ -231,6 +237,90 @@ Compute.prototype.createNetwork = function(name, config, callback) {
231237
});
232238
};
233239

240+
/**
241+
* Create a virtual machine. This is a convenience method that wraps
242+
* {module:compute/zone#createVM}. See that method for a full list of supported
243+
* arguments.
244+
*
245+
* @param {string} name - Name of the instance.
246+
* @param {object} config - See an
247+
* [Instance resource](https://goo.gl/fuLRMj) for more information.
248+
* @param {string|module:compute/zone} config.zone - The zone to create the VM
249+
* in.
250+
* @param {function} callback - The callback function.
251+
*
252+
* @example
253+
* //-
254+
* // Create a new instance using the latest Debian version as the source image
255+
* // for a new boot disk.
256+
* //-
257+
* var config = {
258+
* os: 'debian',
259+
* http: true,
260+
* zone: 'us-central1-a'
261+
* };
262+
*
263+
* //-
264+
* // The above object will auto-expand behind the scenes to something like the
265+
* // following. The Debian version may be different when you run the command.
266+
* //-
267+
* var config = {
268+
* machineType: 'n1-standard-1',
269+
* disks: [
270+
* {
271+
* boot: true,
272+
* initializeParams: {
273+
* sourceImage:
274+
* 'https://www.googleapis.com/compute/v1/projects' +
275+
* '/debian-cloud/global/images/debian-7-wheezy-v20150710'
276+
* }
277+
* }
278+
* ],
279+
* networkInterfaces: [
280+
* {
281+
* network: 'global/networks/default'
282+
* }
283+
* ],
284+
* tags: [
285+
* {
286+
* items: [
287+
* 'http-server'
288+
* ]
289+
* }
290+
* ],
291+
* zone: 'us-central1-a'
292+
* };
293+
*
294+
* function callback(err, instance, operation, apiResponse) {
295+
* // `instance` is an Instance object.
296+
*
297+
* // `operation` is an Operation object that can be used to check the status
298+
* // of the request.
299+
* }
300+
*
301+
* compute.createVM('new-vm-name', config, callback);
302+
*/
303+
Compute.prototype.createVM = function(name, config, callback) {
304+
config = config || {};
305+
306+
var zoneName = config.zone;
307+
delete config.zone;
308+
309+
if (!zoneName) {
310+
throw new Error('A zone is required to create a virtual machine.');
311+
}
312+
313+
var zone;
314+
315+
if (zoneName instanceof Zone) {
316+
zone = zoneName;
317+
} else {
318+
zone = this.zone(zoneName);
319+
}
320+
321+
zone.createVM(name, config, callback);
322+
};
323+
234324
/**
235325
* Get a reference to a Google Compute Engine firewall.
236326
*
@@ -574,47 +664,47 @@ Compute.prototype.getFirewalls = function(options, callback) {
574664
* @param {function} callback - The callback function.
575665
*
576666
* @example
577-
* compute.getInstances(function(err, instances) {
578-
* // `instances` is an array of `Instance` objects.
667+
* compute.getVMs(function(err, vms) {
668+
* // `vms` is an array of `VM` objects.
579669
* });
580670
*
581671
* //-
582672
* // To control how many API requests are made and page through the results
583673
* // manually, set `autoPaginate` to `false`.
584674
* //-
585-
* function callback(err, instances, nextQuery, apiResponse) {
675+
* function callback(err, vms, nextQuery, apiResponse) {
586676
* if (nextQuery) {
587677
* // More results exist.
588-
* compute.getInstances(nextQuery, callback);
678+
* compute.getVMs(nextQuery, callback);
589679
* }
590680
* }
591681
*
592-
* compute.getInstances({
682+
* compute.getVMs({
593683
* autoPaginate: false
594684
* }, callback);
595685
*
596686
* //-
597-
* // Get the instances from your project as a readable object stream.
687+
* // Get the VM instances from your project as a readable object stream.
598688
* //-
599-
* compute.getInstances()
689+
* compute.getVMs()
600690
* .on('error', console.error)
601691
* .on('data', function(instance) {
602-
* // `instance` is an `Instance` object.
692+
* // `vm` is a `VM` object.
603693
* })
604694
* .on('end', function() {
605-
* // All instances retrieved.
695+
* // All vms retrieved.
606696
* });
607697
*
608698
* //-
609699
* // If you anticipate many results, you can end a stream early to prevent
610700
* // unnecessary processing and API requests.
611701
* //-
612-
* compute.getInstances()
702+
* compute.getVMs()
613703
* .on('data', function(instance) {
614704
* this.end();
615705
* });
616706
*/
617-
Compute.prototype.getInstances = function(options, callback) {
707+
Compute.prototype.getVMs = function(options, callback) {
618708
var self = this;
619709

620710
if (is.fn(options)) {
@@ -642,20 +732,20 @@ Compute.prototype.getInstances = function(options, callback) {
642732

643733
var zones = resp.items || {};
644734

645-
var instances = Object.keys(zones).reduce(function(acc, zoneName) {
735+
var vms = Object.keys(zones).reduce(function(acc, zoneName) {
646736
var zone = self.zone(zoneName.replace('zones/', ''));
647737
var instances = zones[zoneName].instances || [];
648738

649739
instances.forEach(function(instance) {
650-
var instanceInstance = zone.instance(instance.name);
651-
instanceInstance.metadata = instance;
652-
acc.push(instanceInstance);
740+
var vmInstance = zone.vm(instance.name);
741+
vmInstance.metadata = instance;
742+
acc.push(vmInstance);
653743
});
654744

655745
return acc;
656746
}, []);
657747

658-
callback(null, instances, nextQuery, resp);
748+
callback(null, vms, nextQuery, resp);
659749
});
660750
};
661751

@@ -995,6 +1085,19 @@ Compute.prototype.snapshot = function(name) {
9951085
return new Snapshot(this, name);
9961086
};
9971087

1088+
/**
1089+
* Get a reference to a Google Compute Engine virtual machine instance.
1090+
*
1091+
* @param {string} name - Name of the existing virtual machine.
1092+
* @return {module:compute/vm}
1093+
*
1094+
* @example
1095+
* var vm = compute.vm('vm-name');
1096+
*/
1097+
Compute.prototype.vm = function(name) {
1098+
return new VM(this, null, name);
1099+
};
1100+
9981101
/**
9991102
* Get a reference to a Google Compute Engine zone.
10001103
*
@@ -1044,10 +1147,10 @@ streamRouter.extend(Compute, [
10441147
'getDisks',
10451148
'getFirewalls',
10461149
'getImages',
1047-
'getInstances',
10481150
'getNetworks',
10491151
'getOperations',
1050-
'getSnapshots'
1152+
'getSnapshots',
1153+
'getVMs'
10511154
]);
10521155

10531156
module.exports = Compute;

0 commit comments

Comments
 (0)