From 3953cbe35edfd7ee98a07c09cc271fdcc399bfcb Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 2 Jul 2013 16:14:54 -0700 Subject: [PATCH] CLOUDSTACK-3164: UI - VPC section - tier - Internal LB - detailView - add assignVMs action in detailView (will show on Quickview in listView as well). --- ui/scripts/vpc.js | 110 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js index e31121ef120..d5a02f63065 100644 --- a/ui/scripts/vpc.js +++ b/ui/scripts/vpc.js @@ -584,7 +584,98 @@ detailView: { isMaximized: true, name: 'Internal LB details', - actions: { + actions: { + assignVMs: { + label: 'Assign VMs', + messages: { + notification: function(args) { return 'Assign VMs'; } + }, + needsRefresh: true, + listView: $.extend(true, {}, cloudStack.sections.instances.listView, { + type: 'checkbox', + filters: false, + dataProvider: function(args) { + var assignedInstances; + $.ajax({ + url: createURL('listLoadBalancers'), + data: { + id: args.context.internalLoadBalancers[0].id + }, + async: false, + success: function(json) { + assignedInstances = json.listloadbalancerssresponse.loadbalancer[0].loadbalancerinstance; + if(assignedInstances == null) + assignedInstances = []; + } + }); + + $.ajax({ + url: createURL('listVirtualMachines'), + data: { + networkid: args.context.networks[0].id, + listAll: true + }, + success: function(json) { + var instances = json.listvirtualmachinesresponse.virtualmachine; + + // Pre-select existing instances in LB rule + $(instances).map(function(index, instance) { + instance._isSelected = $.grep(assignedInstances, + function(assignedInstance) { + return assignedInstance.id == instance.id; + } + ).length ? true : false; + }); + + //remove assigned VMs (i.e. instance._isSelected == true) + var items = []; + if(instances != null) { + for(var i = 0; i < instances.length; i++) { + if(instances[i]._isSelected == true) + continue; + else + items.push(instances[i]); + } + } + + args.response.success({ + data: items + }); + } + }); + } + }), + action: function(args) { + var vms = args.context.instances; + var array1 = []; + for(var i = 0; i < vms.length; i++) { + array1.push(vms[i].id); + } + var virtualmachineids = array1.join(','); + + $.ajax({ + url: createURL('assignToLoadBalancerRule'), + data: { + id: args.context.internalLoadBalancers[0].id, + virtualmachineids: virtualmachineids + }, + dataType: 'json', + async: true, + success: function(data) { + var jid = data.assigntoloadbalancerruleresponse.jobid; + args.response.success({ + _custom: { + jobId: jid + } + }); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } + }, + remove: { label: 'Delete Internal LB', messages: { @@ -632,7 +723,22 @@ sourceipaddress: { label: 'Source IP Address' }, sourceport: { label: 'Source Port' }, instanceport: { label: 'Instance Port' }, - algorithm: { label: 'label.algorithm' } + algorithm: { label: 'label.algorithm' }, + loadbalancerinstance: { + label: 'Assigned VMs', + converter: function(objArray) { + var s = ''; + if(objArray != null) { + for(var i = 0; i < objArray.length; i++) { + if(i > 0) { + s += ', '; + } + s += objArray[i].name + ' ('+ objArray[i].ipaddress + ')'; + } + } + return s; + } + } } ], dataProvider: function(args) {