Skip to content

Instantly share code, notes, and snippets.

@kenperkins
Last active August 29, 2015 14:06
Show Gist options
  • Save kenperkins/6576fe8442902cbf3d5b to your computer and use it in GitHub Desktop.
Save kenperkins/6576fe8442902cbf3d5b to your computer and use it in GitHub Desktop.
/**
* client.createStack
*
* @description Creates a stack with the specified options.
* @param {object} details the details to create this stack
* @param {String} details.name the name of the new stack
* @param {String} details.environment the environment for the stack
* @param {Number} details.timeout timeout in minutes for stack creation
* @param {Object} [details.template] template for the stack, required unless templateUrl is provided
* @param {String} [details.templateUrl] url for the template, required if no template
* @param {Object} [details.parameters] optional parameters configuration
* @param {Object} [details.files] optional files configuration
* @param callback
* @returns {request|*}
*/
exports.createStack = function (details, callback) {
if (typeof details === 'function') {
callback = details;
details = {};
}
details = details || {};
if (!validateProperties(['name', 'environment', 'timeout'], details,
'options.%s is a required argument.', callback)) {
return;
}
if (!details.templateUrl && !details.template) {
callback(new Error('one of template or templateUrl are required'));
return;
}
var self = this,
createOptions = {
method: 'POST',
path: _urlPrefix,
body: {
stack_name: details.name,
environment: details.environment,
timeout_mins: details.timeout
}
};
if (details.template) {
createOptions.body.template = details.template;
}
else if (details.templateUrl) {
createOptions.body.template = details.templateUrl;
}
if (details.parameters) {
createOptions.body.parameters = details.parameters;
}
if (details.files) {
createOptions.body.files = details.files;
}
return this._request(createOptions, function (err, body) {
if (err) {
return callback(err);
}
if (!body || !body.stack) {
return new Error('Stack not passed back from OpenStack.');
}
callback(err, body.stack);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment