From 16510dee5906027585e355e369dea061d86e8c4f Mon Sep 17 00:00:00 2001 From: Jan Krcmar Date: Thu, 11 Feb 2016 14:46:42 +0100 Subject: [PATCH] instance/clone block new instance creating if instance with same name found --- instances/views.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/instances/views.py b/instances/views.py index 1f1f9c1..361c1c2 100644 --- a/instances/views.py +++ b/instances/views.py @@ -498,14 +498,19 @@ def instance(request, compute_id, vname): clone_data = {} clone_data['name'] = request.POST.get('name', '') - for post in request.POST: - if 'disk' or 'meta' in post: - clone_data[post] = request.POST.get(post, '') + check_instance = Instance.objects.filter(name=clone_data['name']) + if check_instance: + msg = _("Instance '%s' already exists!" % clone_data['name']) + error_messages.append(msg) + else: + for post in request.POST: + if 'disk' or 'meta' in post: + clone_data[post] = request.POST.get(post, '') - conn.clone_instance(clone_data) - msg = _("Clone") - addlogmsg(request.user.username, instance.name, msg) - return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']])) + conn.clone_instance(clone_data) + msg = _("Clone") + addlogmsg(request.user.username, instance.name, msg) + return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']])) if 'change_network' in request.POST: network_data = {}