
Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 24/03/2015 13:46, Rodrigo Trujillo wrote:
This patch adds a pattern to checks if vm name has slashes. It also replace slashes from template name by dashes, case user does not give any name to the new VM.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/API.json | 2 ++ src/kimchi/i18n.py | 2 +- src/kimchi/model/utils.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/API.json b/src/kimchi/API.json index f507251..2455745 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -228,6 +228,7 @@ "name": { "description": "The name of the new VM", "type": "string", + "pattern": "^[^/]*$", "error": "KCHVM0011E" }, "template": { @@ -252,6 +253,7 @@ "name": { "description": "New name of VM", "type": "string", + "pattern": "^[^/]*$", "minLength": 1, "error": "KCHVM0011E" }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index e4e1a89..7c11016 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -83,7 +83,7 @@ messages = { "KCHVM0008E": _("Unable to update virtual machine %(name)s. Details: %(err)s"), "KCHVM0009E": _("Unable to retrieve virtual machine %(name)s. Details: %(err)s"), "KCHVM0010E": _("Unable to connect to powered off virtual machine %(name)s."), - "KCHVM0011E": _("Virtual machine name must be a string"), + "KCHVM0011E": _("Virtual machine name must be a string without slashes (/)"), "KCHVM0012E": _("Invalid template URI %(value)s specified for virtual machine"), "KCHVM0013E": _("Invalid storage pool URI %(value)s specified for virtual machine"), "KCHVM0014E": _("Supported virtual machine graphics are Spice or VNC"), diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py index 9896289..80e7da0 100644 --- a/src/kimchi/model/utils.py +++ b/src/kimchi/model/utils.py @@ -34,7 +34,8 @@ def get_vm_name(vm_name, t_name, name_list): if vm_name: return vm_name for i in xrange(1, 1000): - vm_name = "%s-vm-%i" % (t_name, i) + # VM will have templace name, but without slashes + vm_name = "%s-vm-%i" % (t_name.replace('/', '-'), i) if vm_name not in name_list: return vm_name raise OperationFailed("KCHUTILS0003E")