Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: support a source template when creating a VM (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alw3ys committed Sep 30, 2020
1 parent a9e6f9b commit 62f33be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ class Zone extends common.ServiceObject {
*/
createVM(name, config, callback) {
const self = this;
const query = {};
const body = Object.assign(
{
name: name,
Expand All @@ -593,6 +594,10 @@ class Zone extends common.ServiceObject {
},
config
);
if (body.template) {
query.sourceInstanceTemplate = body.template;
delete body.template;
}
if (body.machineType.indexOf('/') === -1) {
// The specified machineType is only a partial name, e.g. 'n1-standard-1'.
body.machineType = format('zones/{zoneName}/machineTypes/{machineType}', {
Expand Down Expand Up @@ -664,6 +669,7 @@ class Zone extends common.ServiceObject {
{
method: 'POST',
uri: '/instances',
qs: query,
json: body,
},
(err, resp) => {
Expand Down
18 changes: 18 additions & 0 deletions test/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,24 @@ describe('Zone', () => {
],
};

describe('config.template', () => {
const CONFIG = {
template: '/path/to/template',
};

it('should define sourceInstanceTemplate', done => {
zone.request = function (reqOpts) {
assert.strictEqual(
reqOpts.qs.sourceInstanceTemplate,
CONFIG.template
);
done();
};

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

describe('config.machineType', () => {
const CONFIG = {
machineType: 'f1-micro',
Expand Down

0 comments on commit 62f33be

Please sign in to comment.