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

Implement create instance from instance template #500

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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