Hi, Crístian

Thanks for your reply, from your clearly description, I understand what you mean.

Since problem appears only after snapshot reverted successfully. We can change the return value of ‘revert’ function in model/vmsnapshots.py once ‘revert’ action success, like [vm_new_name, snapshot_name]. ‘vm_new_name’ means back to ‘myvm’ in your example and ‘snapshot_name’ means the snapshot ‘ident’. We can get value of ‘vm_new_name’ from the snapshot xml. 

Then we need to modify several lines of Kimchi’s infrastructure to make sure the returned list of ‘revert’ action will be accepted and redirected.

changes in control/base.py (begin from line 61) :

    def _redirect(self, action_result, code=303):

        if isinstance(action_result, list):

            uri_params = []

            for arg in action_result:

                if arg is None:

                    arg = ''

                uri_params.append(urllib2.quote(arg.encode('utf-8'),safe=""))

            raise cherrypy.HTTPRedirect(self.uri_fmt % tuple(uri_params), code)

        elif action_result is not None and action_result != self.ident:

            uri_params = list(self.model_args[:-1])

            uri_params += [urllib2.quote(action_result.encode('utf-8'), safe="")]

            raise cherrypy.HTTPRedirect(self.uri_fmt % tuple(uri_params), code)  

 

The only difference is the ‘revert’ action now return ‘303’ and then send ‘GET’ method to get the snapshot info, not directly return snapshot info. I don’t think it matters. Or we can modify ‘_render_element’ function instead. 

I tested this in my environment and didn’t find any problems.

There may be some things I haven’t considered, so what’s your opinion about this? Thanks.

 

Best regards,

Zongmei Gou



-------- Original message --------
From: Crístian Viana <vianac@linux.vnet.ibm.com>
Date: 2014-12-17 24:39
To: 苟宗梅 <gouzongmei@ourfuture.cn>;Kimchi Devel
Subject: Re:Re: [Kimchi-devel] Problem of edit a guest while the guest has asnapshot


Hi Zongmei Gou,

You're right, that's exactly the problem which causes this issue. I
already have an in-progress patch which handles that correctly (i.e.
editing a guest which contains snapshots), but another problem comes up
now. Due to Kimchi's infrastructure, when the following command is executed:

POST /vms/myvm/snapshots/mysnap/revert

Kimchi looks up the VM "myvm", then it looks up the snapshot "mysnap"
from that VM, then revert to it, then it looks up "myvm" and "mysnap"
again to return data; you may notice that when you execute that command,
you get the snapshot data as return. However, let's suppose the VM
"myvm" has been renamed later to "foo" (which now works with my patch),
and then someone tries to revert to "mysnap":

POST /vms/foo/snapshots/mysnap/revert

Kimchi will look up the VM "foo", then "mysnap", then it will revert to
that snapshot. After reverting to that snapshot, the VM will be exactly
the same as it was when the snapshot was created, including having its
old name. So after reverting to that snapshot, Kimchi fails to return
data because it will try to look up "foo" and then "mysnap", but "foo"
won't exist anymore. And that's the current status of my patch for that
issue.

I'm working on other issue recently so I haven't had time to continue on
this one. But I will get back to it as soon as I can. If you have an
idea on how to fix this, let us know!

Best regards,
Crístian.