Skip to content

Commit 4396fbd

Browse files
system testage
1 parent 2b303b6 commit 4396fbd

6 files changed

Lines changed: 231 additions & 288 deletions

File tree

lib/compute/index.js

Lines changed: 4 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ 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-
7468
/**
7569
* @type {module:compute/zone}
7670
* @private
@@ -173,7 +167,7 @@ Compute.prototype.createFirewall = function(name, config, callback) {
173167
throw new Error('A firewall name must be provided.');
174168
}
175169

176-
if (!is.obj(config)) {
170+
if (!is.object(config)) {
177171
throw new Error('A firewall configuration object must be provided.');
178172
}
179173

@@ -248,90 +242,6 @@ Compute.prototype.createNetwork = function(name, config, callback) {
248242
});
249243
};
250244

251-
/**
252-
* Create a virtual machine. This is a convenience method that wraps
253-
* {module:compute/zone#createVM}. See that method for a full list of supported
254-
* arguments.
255-
*
256-
* @param {string} name - Name of the instance.
257-
* @param {object} config - See an
258-
* [Instance resource](https://goo.gl/fuLRMj) for more information.
259-
* @param {string|module:compute/zone} config.zone - The zone to create the VM
260-
* in.
261-
* @param {function} callback - The callback function.
262-
*
263-
* @example
264-
* //-
265-
* // Create a new instance using the latest Debian version as the source image
266-
* // for a new boot disk.
267-
* //-
268-
* var config = {
269-
* os: 'debian',
270-
* http: true,
271-
* zone: 'us-central1-a'
272-
* };
273-
*
274-
* //-
275-
* // The above object will auto-expand behind the scenes to something like the
276-
* // following. The Debian version may be different when you run the command.
277-
* //-
278-
* var config = {
279-
* machineType: 'n1-standard-1',
280-
* disks: [
281-
* {
282-
* boot: true,
283-
* initializeParams: {
284-
* sourceImage:
285-
* 'https://www.googleapis.com/compute/v1/projects' +
286-
* '/debian-cloud/global/images/debian-7-wheezy-v20150710'
287-
* }
288-
* }
289-
* ],
290-
* networkInterfaces: [
291-
* {
292-
* network: 'global/networks/default'
293-
* }
294-
* ],
295-
* tags: [
296-
* {
297-
* items: [
298-
* 'http-server'
299-
* ]
300-
* }
301-
* ],
302-
* zone: 'us-central1-a'
303-
* };
304-
*
305-
* function callback(err, instance, operation, apiResponse) {
306-
* // `instance` is an Instance object.
307-
*
308-
* // `operation` is an Operation object that can be used to check the status
309-
* // of the request.
310-
* }
311-
*
312-
* gce.createVM('new-vm-name', config, callback);
313-
*/
314-
Compute.prototype.createVM = function(name, config, callback) {
315-
config = config || {};
316-
317-
var zoneName = config.zone;
318-
delete config.zone;
319-
320-
if (!zoneName) {
321-
throw new Error('A zone is required to create a virtual machine.');
322-
}
323-
324-
var zone;
325-
326-
if (zoneName instanceof Zone) {
327-
zone = zoneName;
328-
} else {
329-
zone = this.zone(zoneName);
330-
}
331-
332-
zone.createVM(name, config, callback);
333-
};
334-
335245
/**
336246
* Get a reference to a Google Compute Engine firewall.
337247
*
@@ -438,9 +348,7 @@ Compute.prototype.getAddresses = function(options, callback) {
438348
var regions = resp.items || {};
439349

440350
var addresses = Object.keys(regions).reduce(function(acc, regionName) {
441-
regionName = regionName.replace('regions/', '');
442-
443-
var region = self.region(regionName);
351+
var region = self.region(regionName.replace('regions/', ''));
444352
var regionAddresses = regions[regionName].addresses || [];
445353

446354
regionAddresses.forEach(function(address) {
@@ -543,9 +451,7 @@ Compute.prototype.getDisks = function(options, callback) {
543451
var zones = resp.items || {};
544452

545453
var disks = Object.keys(zones).reduce(function(acc, zoneName) {
546-
zoneName = zoneName.replace('zones/', '');
547-
548-
var zone = self.zone(zoneName);
454+
var zone = self.zone(zoneName.replace('zones/', ''));
549455
var disks = zones[zoneName].disks || [];
550456

551457
disks.forEach(function(disk) {
@@ -555,7 +461,7 @@ Compute.prototype.getDisks = function(options, callback) {
555461
});
556462

557463
return acc;
558-
});
464+
}, []);
559465

560466
callback(null, disks, nextQuery, resp);
561467
});
@@ -1096,19 +1002,6 @@ Compute.prototype.snapshot = function(name) {
10961002
return new Snapshot(this, name);
10971003
};
10981004

1099-
/**
1100-
* Get a reference to a Google Compute Engine virtual machine instance.
1101-
*
1102-
* @param {string} name - Name of the existing virtual machine.
1103-
* @return {module:compute/vm}
1104-
*
1105-
* @example
1106-
* var vm = gce.vm('vm-name');
1107-
*/
1108-
Compute.prototype.vm = function(name) {
1109-
return new VM(this, null, name);
1110-
};
1111-
11121005
/**
11131006
* Get a reference to a Google Compute Engine zone.
11141007
*

lib/compute/operation.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ var util = require('../common/util.js');
5858
* //-
5959
* // Reference a zone operation.
6060
* //-
61-
* var zone = compute.zone('us-central1-a');
61+
* var zone = gce.zone('us-central1-a');
6262
* var operation = zone.operation('operation-id');
6363
*
6464
* //-
6565
* // Reference a regional operation.
6666
* //-
67-
* var region = compute.region('us-central1');
67+
* var region = gce.region('us-central1');
6868
* var operation = region.operation('operation-id');
6969
*/
7070
function Operation(scope, name) {
@@ -152,36 +152,32 @@ Operation.prototype.onComplete = function(options, callback) {
152152
interval: 3000
153153
}, options);
154154

155-
var attempts = 0;
155+
var numAttempts = 1;
156156

157-
checkIfComplete();
157+
this.getMetadata(onMetadata);
158158

159-
function checkIfComplete() {
160-
setTimeout(function() {
161-
attempts++;
162-
163-
self.getMetadata(function(err, metadata) {
164-
if (err) {
165-
callback(err);
166-
return;
167-
}
159+
function onMetadata(err, metadata) {
160+
if (err) {
161+
callback(err);
162+
return;
163+
}
168164

169-
if (metadata.status !== 'DONE') {
170-
if (attempts < options.maxAttempts) {
171-
checkIfComplete();
172-
} else {
173-
var didNotCompleteError = new Error('Operation did not complete.');
174-
didNotCompleteError.code = 'OPERATION_INCOMPLETE';
175-
callback(didNotCompleteError, metadata);
176-
}
165+
if (metadata.status !== 'DONE') {
166+
if (numAttempts < options.maxAttempts) {
167+
setTimeout(function() {
168+
self.getMetadata(onMetadata);
169+
}, options.interval);
170+
} else {
171+
var didNotCompleteError = new Error('Operation did not complete.');
172+
didNotCompleteError.code = 'OPERATION_INCOMPLETE';
173+
callback(didNotCompleteError, metadata);
174+
}
177175

178-
return;
179-
}
176+
return;
177+
}
180178

181-
// The operation is complete.
182-
callback(null, metadata);
183-
});
184-
}, options.interval);
179+
// The operation is complete.
180+
callback(null, metadata);
185181
}
186182
};
187183

lib/compute/region.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var streamRouter = require('../common/stream-router.js');
6060
*
6161
* var gce = gcloud.compute();
6262
*
63-
* var region = gce.region('region-name');
63+
* var region = gce.region('us-central1');
6464
*/
6565
function Region(compute, name) {
6666
this.compute = compute;
@@ -85,6 +85,8 @@ Region.prototype.address = function(name) {
8585
* options see [API reference](https://goo.gl/lY8Y3u).
8686
*
8787
* @param {string} name - Name of the address.
88+
* @param {object=} options - See an
89+
* [Address resource](https://goo.gl/TyL9SS) for more information.
8890
* @param {function} callback - The callback function.
8991
*
9092
* @example
@@ -97,12 +99,17 @@ Region.prototype.address = function(name) {
9799
*
98100
* region.createAddress('new-address', callback);
99101
*/
100-
Region.prototype.createAddress = function(name, callback) {
102+
Region.prototype.createAddress = function(name, options, callback) {
101103
var self = this;
102104

103-
var body = {
105+
if (is.fn(options)) {
106+
callback = options;
107+
options = {};
108+
}
109+
110+
var body = extend({}, options, {
104111
name: name
105-
};
112+
});
106113

107114
this.makeReq_('POST', '/addresses', null, body, function(err, resp) {
108115
if (err) {

0 commit comments

Comments
 (0)