[PATCH 0/4] implement reset API

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Reset VM emulates the power reset button on a machine. There is a risk of data loss caused by reset without the guest OS shutdown. Also add a reset confirmation in UI. ShaoHe Feng (4): reset VM: update API.md reset VM in backend. reset vm in UI add confirmation for reset a VM docs/API.md | 3 +++ src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ ui/js/src/kimchi.api.js | 13 ++----------- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 8 files changed, 36 insertions(+), 17 deletions(-) -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Add reset action for VM. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/API.md b/docs/API.md index 143c70c..489f062 100644 --- a/docs/API.md +++ b/docs/API.md @@ -104,6 +104,9 @@ the following general conventions: * start: Power on a VM * poweroff: Power off a VM forcefully. Note this action may produce undesirable results, for example unflushed disk cache in the guest. +* reset: Reset a VM immediately without the guest OS shutdown. + It emulates the power reset button on a machine. Note that there is a + risk of data loss caused by reset without the guest OS shutdown. * connect: Prepare the connection for spice or vnc ### Sub-resource: Virtual Machine Screenshot -- 1.8.5.3

Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Add reset action for VM.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/docs/API.md b/docs/API.md index 143c70c..489f062 100644 --- a/docs/API.md +++ b/docs/API.md @@ -104,6 +104,9 @@ the following general conventions: * start: Power on a VM * poweroff: Power off a VM forcefully. Note this action may produce undesirable results, for example unflushed disk cache in the guest. +* reset: Reset a VM immediately without the guest OS shutdown. + It emulates the power reset button on a machine. Note that there is a + risk of data loss caused by reset without the guest OS shutdown. * connect: Prepare the connection for spice or vnc
### Sub-resource: Virtual Machine Screenshot

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> update mockmodel, model and controller. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ 4 files changed, 13 insertions(+) diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py index e75b27f..b84df76 100644 --- a/src/kimchi/control/vms.py +++ b/src/kimchi/control/vms.py @@ -39,6 +39,7 @@ class VM(Resource): setattr(self, ident, node(model, self.ident)) self.start = self.generate_action_handler('start') self.poweroff = self.generate_action_handler('poweroff') + self.reset = self.generate_action_handler('reset') self.connect = self.generate_action_handler('connect') @property diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 7cf0970..6a31428 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -78,6 +78,7 @@ messages = { "KCHVM0019E": _("Unable to start virtual machine %(name)s. Details: %(err)s"), "KCHVM0020E": _("Unable to poweroff virtual machine %(name)s. Details: %(err)s"), "KCHVM0021E": _("Unable to delete virtual machine %(name)s. Details: %(err)s"), + "KCHVM0022E": _("Unable to reset virtual machine %(name)s. Details: %(err)s"), "KCHVMIF0001E": _("Interface %(iface)s does not exist in virtual machine %(name)s"), "KCHVMIF0002E": _("Network %(network)s specified for virtual machine %(name)s does not exist"), diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 98fb080..1ed6861 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -132,6 +132,9 @@ class MockModel(object): def vm_poweroff(self, name): self._get_vm(name).info['state'] = 'shutoff' + def vm_reset(self, name): + pass + def vm_connect(self, name): pass diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 8334d9e..38ad180 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -380,6 +380,14 @@ class VMModel(object): raise OperationFailed("KCHVM0020E", {'name': name, 'err': e.get_error_message()}) + def reset(self, name): + dom = self.get_vm(name, self.conn) + try: + dom.reset(flags=0) + except libvirt.libvirtError as e: + raise OperationFailed("KCHVM0022E", + {'name': name, 'err': e.get_error_message()}) + def _vm_get_graphics(self, name): dom = self.get_vm(name, self.conn) xml = dom.XMLDesc(0) -- 1.8.5.3

Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
update mockmodel, model and controller.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ 4 files changed, 13 insertions(+)
diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py index e75b27f..b84df76 100644 --- a/src/kimchi/control/vms.py +++ b/src/kimchi/control/vms.py @@ -39,6 +39,7 @@ class VM(Resource): setattr(self, ident, node(model, self.ident)) self.start = self.generate_action_handler('start') self.poweroff = self.generate_action_handler('poweroff') + self.reset = self.generate_action_handler('reset') self.connect = self.generate_action_handler('connect')
@property diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 7cf0970..6a31428 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -78,6 +78,7 @@ messages = { "KCHVM0019E": _("Unable to start virtual machine %(name)s. Details: %(err)s"), "KCHVM0020E": _("Unable to poweroff virtual machine %(name)s. Details: %(err)s"), "KCHVM0021E": _("Unable to delete virtual machine %(name)s. Details: %(err)s"), + "KCHVM0022E": _("Unable to reset virtual machine %(name)s. Details: %(err)s"),
"KCHVMIF0001E": _("Interface %(iface)s does not exist in virtual machine %(name)s"), "KCHVMIF0002E": _("Network %(network)s specified for virtual machine %(name)s does not exist"), diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 98fb080..1ed6861 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -132,6 +132,9 @@ class MockModel(object): def vm_poweroff(self, name): self._get_vm(name).info['state'] = 'shutoff'
+ def vm_reset(self, name): + pass + def vm_connect(self, name): pass
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 8334d9e..38ad180 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -380,6 +380,14 @@ class VMModel(object): raise OperationFailed("KCHVM0020E", {'name': name, 'err': e.get_error_message()})
+ def reset(self, name): + dom = self.get_vm(name, self.conn) + try: + dom.reset(flags=0) + except libvirt.libvirtError as e: + raise OperationFailed("KCHVM0022E", + {'name': name, 'err': e.get_error_message()}) + def _vm_get_graphics(self, name): dom = self.get_vm(name, self.conn) xml = dom.XMLDesc(0)

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> The reset in UI is first shutdown VM and then start VM. Now UI call the reset API directly. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 84405b3..a2e869d 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -221,20 +221,11 @@ var kimchi = { resetVM : function(vm, suc, err) { kimchi.requestJSON({ - url : kimchi.url + 'vms/' + encodeURIComponent(vm) + '/poweroff', + url : kimchi.url + 'vms/' + encodeURIComponent(vm) + '/reset', type : 'POST', contentType : 'application/json', dataType : 'json', - success : function() { - kimchi.requestJSON({ - url : kimchi.url + 'vms/' + encodeURIComponent(vm) + '/start', - type : 'POST', - contentType : 'application/json', - dataType : 'json', - success : suc, - error : err - }); - }, + success : suc, error : err }); }, -- 1.8.5.3

Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
The reset in UI is first shutdown VM and then start VM.
Now UI call the reset API directly.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 84405b3..a2e869d 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -221,20 +221,11 @@ var kimchi = {
resetVM : function(vm, suc, err) { kimchi.requestJSON({ - url : kimchi.url + 'vms/' + encodeURIComponent(vm) + '/poweroff', + url : kimchi.url + 'vms/' + encodeURIComponent(vm) + '/reset', type : 'POST', contentType : 'application/json', dataType : 'json', - success : function() { - kimchi.requestJSON({ - url : kimchi.url + 'vms/' + encodeURIComponent(vm) + '/start', - type : 'POST', - contentType : 'application/json', - dataType : 'json', - success : suc, - error : err - }); - }, + success : suc, error : err }); },

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Reset a VM will cause data loss without the guest OS shutdown. We should let user confirm it. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js index ba93b1e..891e717 100644 --- a/ui/js/src/kimchi.guest_main.js +++ b/ui/js/src/kimchi.guest_main.js @@ -67,12 +67,21 @@ kimchi.vmpoweroff = function(event) { kimchi.vmreset = function(event){ var vm=$(this).closest('li[name=guest]'); var vm_id=vm.attr("id"); - kimchi.resetVM(vm_id, function(result) { - kimchi.listVmsAuto(); - }, function(err) { - kimchi.message.error(err.responseJSON.reason); - } - ); + var settings = { + title : i18n['KCHVM6004M'], + content : i18n['KCHVM6005M'], + confirm : i18n['KCHAPI6002M'], + cancel : i18n['KCHAPI6003M'] + }; + kimchi.confirm(settings, function() { + kimchi.resetVM(vm_id, function(result) { + kimchi.listVmsAuto(); + }, function(err) { + kimchi.message.error(err.responseJSON.reason); + } + ); + }, function() { + }); }; kimchi.vmdelete = function(event) { diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl index 6f655e2..6588dff 100644 --- a/ui/pages/i18n.html.tmpl +++ b/ui/pages/i18n.html.tmpl @@ -129,6 +129,9 @@ var i18n = { 'KCHVM6003M': "$_("This action may produce undesirable results, " "for example unflushed disk cache in the guest. " "Would you like to continue?")", + 'KCHVM6004M': "$_("Reset Confirmation")", + 'KCHVM6005M': "$_("There is a risk of data loss caused by reset without" + " the guest OS shutdown. 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.8.5.3

Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Reset a VM will cause data loss without the guest OS shutdown.
We should let user confirm it.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js index ba93b1e..891e717 100644 --- a/ui/js/src/kimchi.guest_main.js +++ b/ui/js/src/kimchi.guest_main.js @@ -67,12 +67,21 @@ kimchi.vmpoweroff = function(event) { kimchi.vmreset = function(event){ var vm=$(this).closest('li[name=guest]'); var vm_id=vm.attr("id"); - kimchi.resetVM(vm_id, function(result) { - kimchi.listVmsAuto(); - }, function(err) { - kimchi.message.error(err.responseJSON.reason); - } - ); + var settings = { + title : i18n['KCHVM6004M'], + content : i18n['KCHVM6005M'], + confirm : i18n['KCHAPI6002M'], + cancel : i18n['KCHAPI6003M'] + }; + kimchi.confirm(settings, function() { + kimchi.resetVM(vm_id, function(result) { + kimchi.listVmsAuto(); + }, function(err) { + kimchi.message.error(err.responseJSON.reason); + } + ); + }, function() { + }); };
kimchi.vmdelete = function(event) { diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl index 6f655e2..6588dff 100644 --- a/ui/pages/i18n.html.tmpl +++ b/ui/pages/i18n.html.tmpl @@ -129,6 +129,9 @@ var i18n = { 'KCHVM6003M': "$_("This action may produce undesirable results, " "for example unflushed disk cache in the guest. " "Would you like to continue?")", + 'KCHVM6004M': "$_("Reset Confirmation")", + 'KCHVM6005M': "$_("There is a risk of data loss caused by reset without" + " the guest OS shutdown. Would you like to continue?")",
'KCHVMCD6001M': "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", 'KCHVMCD6002M': "$_("Attach")",

I can't apply this patch set. Does it depend on other patch set? On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Reset VM emulates the power reset button on a machine. There is a risk of data loss caused by reset without the guest OS shutdown.
Also add a reset confirmation in UI.
ShaoHe Feng (4): reset VM: update API.md reset VM in backend. reset vm in UI add confirmation for reset a VM
docs/API.md | 3 +++ src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ ui/js/src/kimchi.api.js | 13 ++----------- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 8 files changed, 36 insertions(+), 17 deletions(-)

On 04/11/2014 09:53 AM, Aline Manera wrote:
I can't apply this patch set. Does it depend on other patch set?
sorry. it depends on [PATCH 0/3] bug fix: change power off to stop for VM and add a power off confirmation. and now the depend patch is merged. you can apply this patch again.
On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Reset VM emulates the power reset button on a machine. There is a risk of data loss caused by reset without the guest OS shutdown.
Also add a reset confirmation in UI.
ShaoHe Feng (4): reset VM: update API.md reset VM in backend. reset vm in UI add confirmation for reset a VM
docs/API.md | 3 +++ src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ ui/js/src/kimchi.api.js | 13 ++----------- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 8 files changed, 36 insertions(+), 17 deletions(-)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 04/11/2014 12:30 PM, Sheldon wrote:
On 04/11/2014 09:53 AM, Aline Manera wrote:
I can't apply this patch set. Does it depend on other patch set?
sorry. it depends on [PATCH 0/3] bug fix: change power off to stop for VM and add a power off confirmation.
and now the depend patch is merged.
you can apply this patch again.
I've just tried to apply again and it fails alinefm@alinefm:~/kimchi$ git am -3 ../mail-patches/\[Kimchi-devel\]\ \[PATCH\ * Applying: reset VM: update API.md Applying: reset VM in backend. fatal: sha1 information is lacking or useless (src/kimchi/i18n.py). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge. Patch failed at 0002 reset VM in backend. When you have resolved this problem run "git am --resolved". If you would prefer to skip this patch, instead run "git am --skip". To restore the original branch and stop patching run "git am --abort". Maybe some conflict to the recent merged patches. Please, rebase and re-send the patches
On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Reset VM emulates the power reset button on a machine. There is a risk of data loss caused by reset without the guest OS shutdown.
Also add a reset confirmation in UI.
ShaoHe Feng (4): reset VM: update API.md reset VM in backend. reset vm in UI add confirmation for reset a VM
docs/API.md | 3 +++ src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ ui/js/src/kimchi.api.js | 13 ++----------- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 8 files changed, 36 insertions(+), 17 deletions(-)

On 04/12/2014 12:43 AM, Aline Manera wrote:
On 04/11/2014 12:30 PM, Sheldon wrote:
On 04/11/2014 09:53 AM, Aline Manera wrote:
I can't apply this patch set. Does it depend on other patch set?
sorry. it depends on [PATCH 0/3] bug fix: change power off to stop for VM and add a power off confirmation.
and now the depend patch is merged.
you can apply this patch again.
I've just tried to apply again and it fails
alinefm@alinefm:~/kimchi$ git am -3 ../mail-patches/\[Kimchi-devel\]\ \[PATCH\ * Applying: reset VM: update API.md Applying: reset VM in backend. fatal: sha1 information is lacking or useless (src/kimchi/i18n.py). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge. Patch failed at 0002 reset VM in backend. When you have resolved this problem run "git am --resolved". If you would prefer to skip this patch, instead run "git am --skip". To restore the original branch and stop patching run "git am --abort".
Maybe some conflict to the recent merged patches. Please, rebase and re-send the patches re-send, done. Thanks.
On 04/10/2014 10:04 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Reset VM emulates the power reset button on a machine. There is a risk of data loss caused by reset without the guest OS shutdown.
Also add a reset confirmation in UI.
ShaoHe Feng (4): reset VM: update API.md reset VM in backend. reset vm in UI add confirmation for reset a VM
docs/API.md | 3 +++ src/kimchi/control/vms.py | 1 + src/kimchi/i18n.py | 1 + src/kimchi/mockmodel.py | 3 +++ src/kimchi/model/vms.py | 8 ++++++++ ui/js/src/kimchi.api.js | 13 ++----------- ui/js/src/kimchi.guest_main.js | 21 +++++++++++++++------ ui/pages/i18n.html.tmpl | 3 +++ 8 files changed, 36 insertions(+), 17 deletions(-)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center
participants (4)
-
Aline Manera
-
Daniel H Barboza
-
shaohef@linux.vnet.ibm.com
-
Sheldon