[Kimchi-devel] [PATCH] Do not reuse names when cloning the same VM more than once at the same time

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 9 12:53:21 UTC 2015


Please, add a test case to cover this scenario.

On 07/01/2015 17:45, Crístian Viana wrote:
> If the user tries to clone a VM while it's already being cloned, the
> name of the VM being cloned may be reused because Kimchi only avoids name
> conflicts by looking at the existing VMs, not the ones being created at
> the moment. When the second clone operation finishes, an error is raised
> because that name is already defined.
>
> Look at the names of the VMs being cloned, as well as the existing VMs',
> in order to avoid name conflicts when cloning a VM.
>
> Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/vms.py | 19 ++++++++++++++++---
>   1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index 3aa1145..9472b1c 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -314,9 +314,22 @@ class VMModel(object):
>           if info['state'] != u'shutoff':
>               raise InvalidParameter('KCHVM0033E', {'name': name})
>   
> -        # this name will be used as the Task's 'target_uri' so it needs to be
> -        # defined now.
> -        new_name = get_next_clone_name(self.vms.get_list(), name)
> +        # the new VM's name will be used as the Task's 'target_uri' so it needs
> +        # to be defined now.
> +
> +        vms_being_created = []
> +
> +        # lookup names of VMs being created right now
> +        with self.objstore as session:
> +            task_names = session.get_list('task')
> +            for tn in task_names:
> +                t = session.get('task', tn)
> +                if t['target_uri'].startswith('/vms/'):
> +                    uri_name = t['target_uri'][5:]  # 5 = len('/vms/')
> +                    vms_being_created.append(uri_name)
> +
> +        current_vm_names = self.vms.get_list() + vms_being_created
> +        new_name = get_next_clone_name(current_vm_names, name)
>   
>           # create a task with the actual clone function
>           taskid = add_task(u'/vms/%s' % new_name, self._clone_task,




More information about the Kimchi-devel mailing list