From 42143704fb7aa31e235f56aba974d477e1b3eae9 Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Mon, 9 Nov 2015 12:10:14 -0500 Subject: [PATCH 1/6] Add method to retrieve stack template Gets the template that was used to create the stack. --- heat/v1/client.js | 4 +++- heat/v1/templates.js | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 heat/v1/templates.js diff --git a/heat/v1/client.js b/heat/v1/client.js index 8dfda0a..8cc8685 100644 --- a/heat/v1/client.js +++ b/heat/v1/client.js @@ -1,6 +1,7 @@ var base = require("../../client/base"), ResourcesManager = require("./resources"), - StacksManager = require("./stacks"); + StacksManager = require("./stacks"), + TemplatesManager = require("./templates"); var Heat = base.Client.extend({ @@ -11,6 +12,7 @@ var Heat = base.Client.extend({ this._super(options); this.resources = new ResourcesManager(this); this.stacks = new StacksManager(this); + this.templates = new TemplatesManager(this); } }); diff --git a/heat/v1/templates.js b/heat/v1/templates.js new file mode 100644 index 0000000..2971e05 --- /dev/null +++ b/heat/v1/templates.js @@ -0,0 +1,27 @@ +var base = require("../../client/base"), + utils = require("../../client/utils"), + urljoin = require("../../client/utils").urljoin; + + +var TemplatesManager = base.Manager.extend({ + namespace: "/stacks/{stack_id}/template", + plural: "templates", + + prepare_namespace: function (params) { + params.data = params.data || {}; + + var stack_id = params.data.stack_id; + delete params.data.stack_id; + return utils.interpolate(this.namespace, {stack_id: stack_id}); + }, + + get: function (params, callback) { + var url = urljoin(this.get_base_url(params)); + params = this.prepare_params(params, url); + this.client.get(params, callback); + } + +}); + + +module.exports = TemplatesManager; From 79ee72b76cbcaa35dd0e419f38f5915d51cb9f15 Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Mon, 9 Nov 2015 14:50:59 -0500 Subject: [PATCH 2/6] Allow the user to avoid stack URL redirects If you go to the path ../stacks/, you are (supposed to be) redirected to the proper path, ../stacks//. Whether it's a bug with our deployment or OpenStack in general, the redirect for stack updates is broken. This allows the user to go directly to the correct path. --- heat/v1/stacks.js | 10 ++++++++++ heat/v1/templates.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/heat/v1/stacks.js b/heat/v1/stacks.js index c88b9fa..33b4dca 100644 --- a/heat/v1/stacks.js +++ b/heat/v1/stacks.js @@ -6,6 +6,16 @@ var StacksManager = base.Manager.extend({ namespace: "stacks", use_raw_data: true, + get_base_url: function (params) { + var base_url = this._super(params); + + if (params.id !== null && params.name != null) { + base_url = urljoin(base_url, params.name); + } + + return base_url; + }, + create: function (params, callback) { var success = params.success, error = params.error, diff --git a/heat/v1/templates.js b/heat/v1/templates.js index 2971e05..d1a8796 100644 --- a/heat/v1/templates.js +++ b/heat/v1/templates.js @@ -9,9 +9,9 @@ var TemplatesManager = base.Manager.extend({ prepare_namespace: function (params) { params.data = params.data || {}; - var stack_id = params.data.stack_id; delete params.data.stack_id; + return utils.interpolate(this.namespace, {stack_id: stack_id}); }, From 3b231fd74ffa028186a310dcf165e6d5cbdfab61 Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Mon, 9 Nov 2015 15:56:06 -0500 Subject: [PATCH 3/6] Remove useless urljoin No need to join a single piece. --- heat/v1/templates.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/heat/v1/templates.js b/heat/v1/templates.js index d1a8796..7c92194 100644 --- a/heat/v1/templates.js +++ b/heat/v1/templates.js @@ -1,6 +1,5 @@ var base = require("../../client/base"), - utils = require("../../client/utils"), - urljoin = require("../../client/utils").urljoin; + utils = require("../../client/utils"); var TemplatesManager = base.Manager.extend({ @@ -16,7 +15,7 @@ var TemplatesManager = base.Manager.extend({ }, get: function (params, callback) { - var url = urljoin(this.get_base_url(params)); + var url = this.get_base_url(params); params = this.prepare_params(params, url); this.client.get(params, callback); } From a00bf462c4f3b53061a0cf8359e23c900c5111d5 Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Wed, 11 Nov 2015 11:08:42 -0500 Subject: [PATCH 4/6] Require urljoin in stacks.js I forgot to add it. --- heat/v1/stacks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/heat/v1/stacks.js b/heat/v1/stacks.js index 33b4dca..92f43f8 100644 --- a/heat/v1/stacks.js +++ b/heat/v1/stacks.js @@ -1,5 +1,6 @@ var async = require('async'), - base = require("../../client/base"); + base = require("../../client/base"), + urljoin = require("../../client/utils").urljoin; var StacksManager = base.Manager.extend({ From f32e3d1ae26f4dbd960a97da8c7d7042d803918a Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Thu, 12 Nov 2015 10:24:58 -0500 Subject: [PATCH 5/6] Pass the error callback to safe_complete for stack creation params.error gets deleted, but the error callback needs to get passed through. Addresses issue: https://github.com/gabrielhurley/js-openclient/issues/34 --- heat/v1/stacks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heat/v1/stacks.js b/heat/v1/stacks.js index 92f43f8..49e4c6a 100644 --- a/heat/v1/stacks.js +++ b/heat/v1/stacks.js @@ -38,7 +38,7 @@ var StacksManager = base.Manager.extend({ }); this._super(params, function (err, result, xhr) { - if (err) return manager.safe_complete(err, null, null, params, callback); + if (err) return manager.safe_complete(err, null, xhr, { error: error }, callback); manager.get({ url: xhr.getResponseHeader('location'), success: success, From 7fad256fc767afa70db8f8dd96c6079689f16bc8 Mon Sep 17 00:00:00 2001 From: Matthew Hill Date: Fri, 13 Nov 2015 09:41:29 -0500 Subject: [PATCH 6/6] Add stack actions Adds the four actions supported by the orchestration API: suspend, resume, cancel_update, and check. --- heat/v1/stacks.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/heat/v1/stacks.js b/heat/v1/stacks.js index 49e4c6a..2a9ee20 100644 --- a/heat/v1/stacks.js +++ b/heat/v1/stacks.js @@ -88,7 +88,22 @@ var StacksManager = base.Manager.extend({ params.url = this.urljoin(this.get_base_url(params), data.stack_name, params.id); params.headers['Content-Length'] = 0; this._super(params, callback); - } + }, + + _action: function (params, action, info, callback) { + var url = urljoin(this.get_base_url(params), params.id || params.data.id, "actions"); + if (params.data && params.data.id) delete params.data.id; + params = this.prepare_params(params, url, "singular"); + params.data[action] = info || null; + return this.client.post(params, callback); + }, + + suspend: function (params, callback) { return this._action(params, "suspend", null, callback); }, + resume: function (params, callback) { return this._action(params, "resume", null, callback); }, + + cancel_update: function (params, callback) { return this._action(params, "cancel_update", null, callback); }, + + check: function (params, callback) { return this._actions(params, "check", null, callback); } });