From fc4f19f915e8edc5ccc0076122fb20c19ad2646a Mon Sep 17 00:00:00 2001 From: Pranav Saxena Date: Fri, 19 Apr 2013 18:27:07 +0530 Subject: [PATCH] Storage Motion UI development --- ui/css/cloudstack3.css | 11 +++++++ ui/scripts/instances.js | 64 +++++++++++++++++++++++++----------- ui/scripts/storage.js | 73 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 128 insertions(+), 20 deletions(-) diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css index d4c670cbdbf..b971cbf729c 100644 --- a/ui/css/cloudstack3.css +++ b/ui/css/cloudstack3.css @@ -11603,6 +11603,17 @@ div.ui-dialog div.autoscaler div.field-group div.form-container form div.form-it background-position: 0px -707px; } +.migrate .icon, +.migrateVolume .icon { + background-position: 0px -125px; +} + +.migrate:hover .icon, +.migrateVolume:hover .icon { + background-position: 0px -707px; +} + + .attach .icon, .attachISO .icon, .attachDisk .icon { diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js index b2d9ddeb0f6..bd8b7f64c09 100644 --- a/ui/scripts/instances.js +++ b/ui/scripts/instances.js @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. (function($, cloudStack) { + var requiresStorageMotion = false; cloudStack.sections.instances = { title: 'label.instances', id: 'instances', @@ -958,17 +959,31 @@ validation: { required: true }, select: function(args) { $.ajax({ - url: createURL("listHosts&VirtualMachineId=" + args.context.instances[0].id), + url: createURL("findHostsForMigration&VirtualMachineId=" + args.context.instances[0].id), //url: createURL("listHosts"), //for testing only, comment it out before checking in. dataType: "json", async: true, success: function(json) { - var hosts = json.listhostsresponse.host; + if(json.findhostsformigrationresponse.host != undefined){ + var hosts = json.findhostsformigrationresponse.host; + requiresStorageMotion = json.findhostsformigrationresponse.host[0].requiresStorageMotion; var items = []; $(hosts).each(function() { - items.push({id: this.id, description: (this.name + " (" + (this.suitableformigration? "Suitable": "Not Suitable") + ")")}); - }); + if(this.requiresStorageMotion == true){ + items.push({id: this.id, description: (this.name + " (" + (this.suitableformigration? "Suitable, ": "Not Suitable, ") + "Storage migration required)" )}); + + } + else { + + items.push({id: this.id, description: (this.name + " (" + (this.suitableformigration? "Suitable": "Not Suitable") + ")" )}); + + } + }); args.response.success({data: items}); + } + else + cloudStack.dialog.notice({ message: _l('No Hosts are avaialble for Migration') }); //Only a single host in the set up + } }); } @@ -976,7 +991,31 @@ } }, action: function(args) { + + if(requiresStorageMotion == true){ $.ajax({ + url: createURL("migrateVirtualMachineWithVolume&hostid=" + args.data.hostId + "&virtualmachineid=" + args.context.instances[0].id), + dataType: "json", + async: true, + success: function(json) { + var jid = json.migratevirtualmachinewithvolumeresponse.jobid; + args.response.success( + {_custom: + {jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.virtualmachine; + }, + getActionFilter: function() { + return vmActionfilter; + } + } + } + ); + } + }); + } + else{ + $.ajax({ url: createURL("migrateVirtualMachine&hostid=" + args.data.hostId + "&virtualmachineid=" + args.context.instances[0].id), dataType: "json", async: true, @@ -987,21 +1026,6 @@ {jobId: jid, getUpdatedItem: function(json) { return json.queryasyncjobresultresponse.jobresult.virtualmachine; - /* - var vmObj; - $.ajax({ - url: createURL("listVirtualMachines&id=" + args.context.instances[0].id), - dataType: "json", - async: false, - success: function(json) { - var items = json.listvirtualmachinesresponse.virtualmachine; - if(items != null && items.length > 0) { - vmObj = items[0]; - } - } - }); - return vmObj; - */ }, getActionFilter: function() { return vmActionfilter; @@ -1011,6 +1035,8 @@ ); } }); + + } }, notification: { poll: pollAsyncJobResult diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index 54605e266ae..8fd95944290 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -395,6 +395,69 @@ name: 'Volume details', viewAll: { path: 'storage.snapshots', label: 'label.snapshots' }, actions: { + + migrateVolume:{ + label:'Migrate Volume', + messages: { + confirm: function(args) { + return 'Do you want to migrate this volume ?' ; + }, + notification: function(args) { + return 'Volume migrated'; + } + }, + + createForm: { + title: 'Migrate Volume', + desc: '', + fields: { + storagePool: { + label: 'Storage Pool', + validation: { required: true }, + select: function(args) { + $.ajax({ + url: createURL("findStoragePoolsForMigration&id=" + args.context.volumes[0].id), + dataType: "json", + async: true, + success: function(json) { + var pools = json.findstoragepoolsformigrationresponse.storagepool; + var items = []; + $(pools).each(function() { + items.push({id: this.id, description: this.name + " (" + (this.suitableformigration? "Suitable": "Not Suitable")+")" }); + }); + args.response.success({data: items}); + + } + }); + } + } + } + + }, + + action: function(args) { + $.ajax({ + url: createURL("migrateVolume&livemigrate=true&storageid=" + args.data.storagePool + "&volumeid=" + args.context.volumes[0].id ), + dataType: "json", + async: true, + success: function(json) { + var jid = json.migratevolumeresponse.jobid; + args.response.success( + {_custom: + { + jobId: jid + } + } + ); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } + + }, + takeSnapshot: { label: 'label.action.take.snapshot', messages: { @@ -961,7 +1024,7 @@ }, action: function(args) { $.ajax({ - url: createURL("migrateVolume&storageid=" + args.data.storageId + "&volumeid=" + args.context.volumes[0].id), + url: createURL("migrateVolume&storageid=" + args.data.storagePool + "&volumeid=" + args.context.volumes[0].id), dataType: "json", async: true, success: function(json) { @@ -1538,6 +1601,7 @@ var jsonObj = args.context.item; var allowedActions = []; + if (jsonObj.state == 'Destroyed' || jsonObj.state == 'Migrating' || jsonObj.state == 'Uploading') { return []; } @@ -1557,6 +1621,13 @@ allowedActions.push("downloadVolume"); } } + + if(jsonObj.type == "ROOT" || jsonObj.type =="DATADISK"){ + if(jsonObj.state == "Ready" && isAdmin() && jsonObj.virtualmachineid != null ){ + allowedActions.push("migrateVolume"); + } + } + if(jsonObj.state != "Creating") { if(jsonObj.type == "ROOT") { if (jsonObj.vmstate == "Stopped") {