Skip to content

Commit

Permalink
fix(createVM): do not define machineType or networkInterfaces when te…
Browse files Browse the repository at this point in the history
…mplate provided (#530)

Fixes #529
  • Loading branch information
stephenplusplus authored Jan 7, 2021
1 parent 73ec192 commit ae93a1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
21 changes: 8 additions & 13 deletions packages/google-cloud-compute/src/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,23 +582,18 @@ class Zone extends common.ServiceObject {
createVM(name, config, callback) {
const self = this;
const query = {};
const body = Object.assign(
{
name: name,
machineType: 'n1-standard-1',
networkInterfaces: [
{
network: 'global/networks/default',
},
],
},
config
);
const body = Object.assign({name}, config);
if (body.template) {
query.sourceInstanceTemplate = body.template;
delete body.template;
}
if (body.machineType.indexOf('/') === -1) {
if (!is.defined(query.sourceInstanceTemplate)) {
body.machineType = body.machineType || 'n1-standard-1';
body.networkInterfaces = body.networkInterfaces || [
{network: 'global/networks/default'},
];
}
if (body.machineType && body.machineType.indexOf('/') === -1) {
// The specified machineType is only a partial name, e.g. 'n1-standard-1'.
body.machineType = format('zones/{zoneName}/machineTypes/{machineType}', {
zoneName: this.name,
Expand Down
21 changes: 21 additions & 0 deletions packages/google-cloud-compute/test/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,27 @@ describe('Zone', () => {

zone.createVM(NAME, CONFIG, assert.ifError);
});

it('should not set default value for machineType', done => {
zone.request = function (reqOpts) {
assert.strictEqual(typeof reqOpts.json.machineType, 'undefined');
done();
};

zone.createVM(NAME, CONFIG, assert.ifError);
});

it('should not set default value for network', done => {
zone.request = function (reqOpts) {
assert.strictEqual(
typeof reqOpts.json.networkInterfaces,
'undefined'
);
done();
};

zone.createVM(NAME, CONFIG, assert.ifError);
});
});

describe('config.machineType', () => {
Expand Down

0 comments on commit ae93a1e

Please sign in to comment.