cloudstack 3.0 UI - autoscale - implement enableAutoScaleVmGroup API, disableAutoScaleVmGroup API.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/f348fcfb Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/f348fcfb Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/f348fcfb Branch: refs/heads/master Commit: f348fcfb0e12f8448871dbea313e20e8ec001be8 Parents: 2f40e78 Author: Jessica Wang <[email protected]> Authored: Tue Aug 7 16:33:04 2012 -0700 Committer: Vijay Venkatachalam <[email protected]> Committed: Fri Nov 16 10:56:48 2012 +0530 ---------------------------------------------------------------------- ui/scripts/autoscaler.js | 113 +++++++++++++++++-------------- ui/scripts/ui-custom/autoscaler.js | 3 + 2 files changed, 65 insertions(+), 51 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f348fcfb/ui/scripts/autoscaler.js ---------------------------------------------------------------------- diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index db708e4..1dc90b9 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -25,63 +25,74 @@ // UI actions to appear in dialog autoscaleActions: { enable: { - label: 'Enable Autoscaler', - action: function(args) { - args.response.success({ - _custom: { jobId: 12345 }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'Enabled' } - }); - } - } - }); + label: 'Enable Autoscale VM Group', + action: function(args) { + $.ajax({ + url: createURL('enableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var jid = json.enableautoscalevmGroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; + }, + getActionFilter: function() { + return cloudStack.autoscaler.actionFilter; + } + }, + notification: { + poll: pollAsyncJobResult + } + }); + } + }); } }, disable: { - label: 'Disable Autoscaler', - action: function(args) { - args.response.success({ - _custom: { jobId: 12345 }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'Disabled' } - }); - } - } - }); - } - }, - restart: { - label: 'Restart Autoscaler', - action: function(args) { - args.response.success({ - _custom: { jobId: 12345 }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'Enabled' } - }); - } - } - }); + label: 'Disable Autoscale VM Group', + action: function(args) { + $.ajax({ + url: createURL('disableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var jid = json.disableautoscalevmGroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; + }, + getActionFilter: function() { + return cloudStack.autoscaler.actionFilter; + } + }, + notification: { + poll: pollAsyncJobResult + } + }); + } + }); } } }, - actionFilter: function(args) { - var data = $.isArray(args.context.originalAutoscaleData) ? - args.context.originalAutoscaleData[0] : {}; - - if (data.state == 'Enabled') { - return ['disable', 'restart']; - } else if (data.state == 'Disabled') { - return ['enable']; - } - - // No existing data, so actions are not visible - return []; + actionFilter: function(args) { + var allowedActions = []; + if(args.context.originalAutoscaleData == null) { //new LB rule + //no actions for new LB rule + } + else { //existing LB rule + if(args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'disabled') + allowedActions.push('enable'); + else if(args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'enabled') + allowedActions.push('disable'); + } + return allowedActions; }, dataProvider: function(args) { // Reset data http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f348fcfb/ui/scripts/ui-custom/autoscaler.js ---------------------------------------------------------------------- diff --git a/ui/scripts/ui-custom/autoscaler.js b/ui/scripts/ui-custom/autoscaler.js index ceec5a7..8e9c5c2 100644 --- a/ui/scripts/ui-custom/autoscaler.js +++ b/ui/scripts/ui-custom/autoscaler.js @@ -115,6 +115,9 @@ }; action.action({ + context: { + originalAutoscaleData: args.data, + }, response: { success: function(args) { var notification = $.extend(args.notification, {
