From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Add a shutdown API and shutdown botton in UI.
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.api.js | 11 +++++++++++
ui/js/src/kimchi.guest_main.js | 23 +++++++++++++++++++++++
ui/pages/guest.html.tmpl | 1 +
ui/pages/i18n.html.tmpl | 2 ++
4 files changed, 37 insertions(+)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index e96a67a..29a5770 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -230,6 +230,17 @@ var kimchi = {
});
},
+ shutdownVM : function(vm, suc, err) {
+ kimchi.requestJSON({
+ url : kimchi.url + 'vms/' + encodeURIComponent(vm) +
'/shutdown',
+ type : 'POST',
+ contentType : 'application/json',
+ dataType : 'json',
+ success : suc,
+ error : err
+ });
+ },
+
resetVM : function(vm, suc, err) {
kimchi.requestJSON({
url : kimchi.url + 'vms/' + encodeURIComponent(vm) +
'/reset',
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index 891e717..510e7f9 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -64,6 +64,26 @@ kimchi.vmpoweroff = function(event) {
}
};
+kimchi.vmshutdown = function(event){
+ var vm=$(this).closest('li[name=guest]');
+ var vm_id=vm.attr("id");
+ var settings = {
+ title : i18n['KCHVM6006M'],
+ content : i18n['KCHVM6007M'],
+ confirm : i18n['KCHAPI6002M'],
+ cancel : i18n['KCHAPI6003M']
+ };
+ kimchi.confirm(settings, function() {
+ kimchi.shutdownVM(vm_id, function(result) {
+ kimchi.listVmsAuto();
+ }, function(err) {
+ kimchi.message.error(err.responseJSON.reason);
+ }
+ );
+ }, function() {
+ });
+};
+
kimchi.vmreset = function(event){
var vm=$(this).closest('li[name=guest]');
var vm_id=vm.attr("id");
@@ -270,6 +290,9 @@ kimchi.createGuestLi = function(vmObject, prevScreenImage, openMenu)
{
if (vmRunningBool) { //If the guest is not running, do not enable reset
guestActions.find("[name=vm-reset]").on({click : kimchi.vmreset});
}
+ if (vmRunningBool) { //If the guest is not running, do not enable shutdown
+ guestActions.find("[name=vm-shutdown]").on({click :
kimchi.vmshutdown});
+ }
guestActions.find("[name=vm-media]").on({click : kimchi.vmmedia});
guestActions.find("[name=vm-edit]").on({click : kimchi.vmedit});
guestActions.find("[name=vm-delete]").on({click : kimchi.vmdelete});
diff --git a/ui/pages/guest.html.tmpl b/ui/pages/guest.html.tmpl
index 588b7b0..c7335c8 100644
--- a/ui/pages/guest.html.tmpl
+++ b/ui/pages/guest.html.tmpl
@@ -59,6 +59,7 @@
<button class="button-big shutoff-disabled"
name="vm-media"><span class="text">$_("Manage
Media")</span></button>
<button class="button-big running-disabled"
name="vm-edit"><span
class="text">$_("Edit")</span></button>
<button class="button-big shutoff-hidden"
name="vm-reset"><span
class="text">$_("Reset")</span></button>
+ <button class="button-big shutoff-hidden"
name="vm-shutdown"><span class="text">$_("Shut
Down")</span></button>
<button class="button-big running-hidden"
name="vm-start"><span
class="text">$_("Start")</span></button>
<button class="button-big shutoff-hidden"
name="vm-poweroff"><span class="text">$_("Power
Off")</span></button>
<a class="button-big red "
name="vm-delete">$_("Delete")</a>
diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl
index 6588dff..98da828 100644
--- a/ui/pages/i18n.html.tmpl
+++ b/ui/pages/i18n.html.tmpl
@@ -132,6 +132,8 @@ var i18n = {
'KCHVM6004M': "$_("Reset Confirmation")",
'KCHVM6005M': "$_("There is a risk of data loss caused by reset
without"
" the guest OS shutdown. Would you like to
continue?")",
+ 'KCHVM6006M': "$_("Shut Down Confirmation")",
+ 'KCHVM6007M': "$_("Note the guest OS may ignore this request. Would
you like to continue?")",
'KCHVMCD6001M': "$_("This CDROM will be detached permanently and
you can re-attach it. Continue to detach it?")",
'KCHVMCD6002M': "$_("Attach")",
--
1.9.0