Skip to content

Commit 457e882

Browse files
add start option
1 parent 5152158 commit 457e882

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

packages/compute/src/vm.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,46 @@ VM.prototype.reset = function(callback) {
424424
* @param {string} machineType - Full or partial machine type. See a list of
425425
* predefined machine types
426426
* [here](https://cloud.google.com/compute/docs/machine-types#predefined_machine_types).
427+
* @param {object=} options - Configuration object.
428+
* @param {boolean} options.start - Start the VM after successfully updating the
429+
* machine type. Default: `false`.
427430
* @param {function} callback - The callback function.
428431
* @param {?error} callback.err - An error returned while making this request.
429432
* @param {object} callback.apiResponse - The full API response.
430433
*
431434
* @example
432-
* vm.resize('n1-standard-1', function(err, apiResponse) {});
435+
* vm.resize('n1-standard-1', function(err, apiResponse) {
436+
* if (!err) {
437+
* // The VM is running and its machine type was changed successfully.
438+
* }
439+
* });
440+
*
441+
* //-
442+
* // By default, calling `resize` will start your server after updating its
443+
* // machine type. If you want to leave it stopped, set `options.start` to
444+
* // `false`.
445+
* //-
446+
* var options = {
447+
* start: false
448+
* };
449+
*
450+
* vm.resize('ns-standard-1', options, function(err, apiResponse) {
451+
* if (!err) {
452+
* // The VM is stopped and its machine type was changed successfully.
453+
* }
454+
* });
433455
*/
434-
VM.prototype.resize = function(machineType, callback) {
456+
VM.prototype.resize = function(machineType, options, callback) {
435457
var self = this;
436458
var compute = this.zone.parent;
437459

460+
if (is.fn(options)) {
461+
callback = options;
462+
options = {};
463+
}
464+
465+
options = options || {};
466+
438467
var isPartialMachineType = machineType.indexOf('/') === -1;
439468

440469
if (isPartialMachineType) {
@@ -469,8 +498,12 @@ VM.prototype.resize = function(machineType, callback) {
469498
return;
470499
}
471500

472-
// The machine type was changed successfully. Start the VM.
473-
self.start(compute.execAfterOperation_(callback));
501+
// The machine type was changed successfully.
502+
if (options.start === false) {
503+
callback(null, apiResponse);
504+
} else {
505+
self.start(compute.execAfterOperation_(callback));
506+
}
474507
}));
475508
};
476509

packages/compute/test/vm.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ describe('VM', function() {
611611
});
612612

613613
describe('success', function() {
614-
it('should start the VM', function(done) {
614+
it('should start the VM by default', function(done) {
615615
function userCallback() {}
616616
function onVmStart() {}
617617

@@ -632,6 +632,24 @@ describe('VM', function() {
632632
vm.resize(MACHINE_TYPE, userCallback);
633633
});
634634
});
635+
636+
it('should not start the VM by request', function(done) {
637+
var apiResponse = {};
638+
639+
vm.zone.parent.execAfterOperation_ = function(callback) {
640+
callback(null, apiResponse);
641+
};
642+
643+
vm.start = function() {
644+
done(); // Test will fail if called.
645+
};
646+
647+
vm.resize(MACHINE_TYPE, { start: false }, function(err, apiResponse_) {
648+
assert.ifError(err);
649+
assert.strictEqual(apiResponse_, apiResponse);
650+
done();
651+
});
652+
});
635653
});
636654

637655
describe('setMetadata', function() {

0 commit comments

Comments
 (0)