Skip to content

Commit ae93a1e

Browse files
fix(createVM): do not define machineType or networkInterfaces when template provided (#530)
Fixes #529
1 parent 73ec192 commit ae93a1e

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

packages/google-cloud-compute/src/zone.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -582,23 +582,18 @@ class Zone extends common.ServiceObject {
582582
createVM(name, config, callback) {
583583
const self = this;
584584
const query = {};
585-
const body = Object.assign(
586-
{
587-
name: name,
588-
machineType: 'n1-standard-1',
589-
networkInterfaces: [
590-
{
591-
network: 'global/networks/default',
592-
},
593-
],
594-
},
595-
config
596-
);
585+
const body = Object.assign({name}, config);
597586
if (body.template) {
598587
query.sourceInstanceTemplate = body.template;
599588
delete body.template;
600589
}
601-
if (body.machineType.indexOf('/') === -1) {
590+
if (!is.defined(query.sourceInstanceTemplate)) {
591+
body.machineType = body.machineType || 'n1-standard-1';
592+
body.networkInterfaces = body.networkInterfaces || [
593+
{network: 'global/networks/default'},
594+
];
595+
}
596+
if (body.machineType && body.machineType.indexOf('/') === -1) {
602597
// The specified machineType is only a partial name, e.g. 'n1-standard-1'.
603598
body.machineType = format('zones/{zoneName}/machineTypes/{machineType}', {
604599
zoneName: this.name,

packages/google-cloud-compute/test/zone.js

+21
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,27 @@ describe('Zone', () => {
791791

792792
zone.createVM(NAME, CONFIG, assert.ifError);
793793
});
794+
795+
it('should not set default value for machineType', done => {
796+
zone.request = function (reqOpts) {
797+
assert.strictEqual(typeof reqOpts.json.machineType, 'undefined');
798+
done();
799+
};
800+
801+
zone.createVM(NAME, CONFIG, assert.ifError);
802+
});
803+
804+
it('should not set default value for network', done => {
805+
zone.request = function (reqOpts) {
806+
assert.strictEqual(
807+
typeof reqOpts.json.networkInterfaces,
808+
'undefined'
809+
);
810+
done();
811+
};
812+
813+
zone.createVM(NAME, CONFIG, assert.ifError);
814+
});
794815
});
795816

796817
describe('config.machineType', () => {

0 commit comments

Comments
 (0)