[PATCH] Disk image type in vm template - backend

A new parameter called "type" is now allowed in the backend to choose the image type of the VM template. The default image type, if this parameter isn't used, is "qcow2". Examples: - creates a VM template called "opensuse_disktype" with 2 disks, one of them is of type "raw": $ curl -u user:passwd -H "Content-Type: application/json" -H "Accept: application/json" http://localhost:8010/templates -X POST -d'{"name": "opensuse_disktype", "cdrom":"/home/danielhb/Downloads/openSUSE-13.1-DVD-x86_64.iso", "disks":[{"index":0,"size":3}, {"index":1, "size":4, "type":"raw"}]}' - changing the disk types of the template: $ curl -u user:passwd -H "Content-Type: application/json" -H "Accept: application/json" http://localhost:8010/templates/opensuse_disktype -X PUT -d'{"disks":[{"index":0,"size":3, "type":"raw"}, {"index":1, "size":4}]}' Daniel Henrique Barboza (1): Choose disk image type in vm template - backend docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) -- 1.8.3.1

These changes implements the backend support for setting the disk image type in the VM template, by using a new parameter called "type" in the 'disk' object of the template_create schema. If the parameter is not used, the template will use the default disk type (qcow2). Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index 298441f..11dba67 100644 --- a/docs/API.md +++ b/docs/API.md @@ -195,6 +195,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. * index: The device index * size: The device size in GB * base: Base image of this disk + * type: Type of the image (qcow2 or raw) * graphics *(optional)*: The graphics paramenters of this template * type: The type of graphics. It can be VNC or spice or None. diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2e2f9b0..67ffaf7 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -419,6 +419,12 @@ "type": "string", "pattern": "^/.+$", "error": "KCHTMPL0023E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } @@ -590,6 +596,12 @@ "type": "number", "minimum": 1, "error": "KCHTMPL0022E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 1e8b47a..9c81ea0 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -130,6 +130,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be greater than 1GB."), "KCHTMPL0023E": _("Template base image must be a valid local image file"), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), + "KCHTMPL0025E": _("Invalid disk image type. Types supported: 'qcow2', 'raw'"), "KCHPOOL0001E": _("Storage pool %(name)s already exists"), "KCHPOOL0002E": _("Storage pool %(name)s does not exist"), diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index c5bb7b3..9b8349d 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -195,7 +195,10 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/> src = os.path.join(storage_path, volume) dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']], string.lowercase[index]) - fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2' + if self._get_storage_type() in ['logical']: + fmt = 'raw' + else: + fmt = disk.get('type', 'qcow2') params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'], 'type': fmt} ret += """ -- 1.8.3.1

-- Reviewed-by: Paulo Vital <pvital@linux.vnet.ibm.com> On Thu, 2014-09-04 at 17:50 -0300, Daniel Henrique Barboza wrote:
These changes implements the backend support for setting the disk image type in the VM template, by using a new parameter called "type" in the 'disk' object of the template_create schema.
If the parameter is not used, the template will use the default disk type (qcow2).
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/docs/API.md b/docs/API.md index 298441f..11dba67 100644 --- a/docs/API.md +++ b/docs/API.md @@ -195,6 +195,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. * index: The device index * size: The device size in GB * base: Base image of this disk + * type: Type of the image (qcow2 or raw)
* graphics *(optional)*: The graphics paramenters of this template * type: The type of graphics. It can be VNC or spice or None. diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2e2f9b0..67ffaf7 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -419,6 +419,12 @@ "type": "string", "pattern": "^/.+$", "error": "KCHTMPL0023E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" }
} @@ -590,6 +596,12 @@ "type": "number", "minimum": 1, "error": "KCHTMPL0022E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 1e8b47a..9c81ea0 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -130,6 +130,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be greater than 1GB."), "KCHTMPL0023E": _("Template base image must be a valid local image file"), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), + "KCHTMPL0025E": _("Invalid disk image type. Types supported: 'qcow2', 'raw'"),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"), "KCHPOOL0002E": _("Storage pool %(name)s does not exist"), diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index c5bb7b3..9b8349d 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -195,7 +195,10 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/> src = os.path.join(storage_path, volume) dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']], string.lowercase[index]) - fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2' + if self._get_storage_type() in ['logical']: + fmt = 'raw' + else: + fmt = disk.get('type', 'qcow2') params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'], 'type': fmt} ret += """

On 09/04/2014 05:50 PM, Daniel Henrique Barboza wrote:
These changes implements the backend support for setting the disk image type in the VM template, by using a new parameter called "type" in the 'disk' object of the template_create schema.
If the parameter is not used, the template will use the default disk type (qcow2).
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/docs/API.md b/docs/API.md index 298441f..11dba67 100644 --- a/docs/API.md +++ b/docs/API.md @@ -195,6 +195,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. * index: The device index * size: The device size in GB * base: Base image of this disk + * type: Type of the image (qcow2 or raw)
From libvirt the supported formats are: "raw", "bochs", "qcow", "qcow2", "qed", "vmdk" Shouldn't we support all those too?
* graphics *(optional)*: The graphics paramenters of this template * type: The type of graphics. It can be VNC or spice or None. diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2e2f9b0..67ffaf7 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -419,6 +419,12 @@ "type": "string", "pattern": "^/.+$", "error": "KCHTMPL0023E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" }
} @@ -590,6 +596,12 @@ "type": "number", "minimum": 1, "error": "KCHTMPL0022E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 1e8b47a..9c81ea0 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -130,6 +130,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be greater than 1GB."), "KCHTMPL0023E": _("Template base image must be a valid local image file"), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), + "KCHTMPL0025E": _("Invalid disk image type. Types supported: 'qcow2', 'raw'"),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"), "KCHPOOL0002E": _("Storage pool %(name)s does not exist"), diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index c5bb7b3..9b8349d 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -195,7 +195,10 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/> src = os.path.join(storage_path, volume) dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']], string.lowercase[index])
- fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2' + if self._get_storage_type() in ['logical']: + fmt = 'raw' + else: + fmt = disk.get('type', 'qcow2')
If user passes a different type of 'raw' to a logical volume we should raise an error.
params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'], 'type': fmt} ret += """

On 09/16/2014 08:58 PM, Aline Manera wrote:
On 09/04/2014 05:50 PM, Daniel Henrique Barboza wrote:
These changes implements the backend support for setting the disk image type in the VM template, by using a new parameter called "type" in the 'disk' object of the template_create schema.
If the parameter is not used, the template will use the default disk type (qcow2).
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/docs/API.md b/docs/API.md index 298441f..11dba67 100644 --- a/docs/API.md +++ b/docs/API.md @@ -195,6 +195,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. * index: The device index * size: The device size in GB * base: Base image of this disk + * type: Type of the image (qcow2 or raw)
From libvirt the supported formats are: "raw", "bochs", "qcow", "qcow2", "qed", "vmdk" Shouldn't we support all those too?
From libvirt doc: http://libvirt.org/storage.html When listing existing volumes all these formats are supported natively. When creating new volumes, only a subset may be available. The|raw|type is guaranteed always available. The|qcow2|type can be created if either|qemu-img|or|qcow-create|tools are present. The others are dependent on support of the|qemu-img|tool. This is why I considered only raw and qcow2. The other types are dependent on qemu-img tool, which can support different types according to distro and arch.
* graphics *(optional)*: The graphics paramenters of this template * type: The type of graphics. It can be VNC or spice or None. diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2e2f9b0..67ffaf7 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -419,6 +419,12 @@ "type": "string", "pattern": "^/.+$", "error": "KCHTMPL0023E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" }
} @@ -590,6 +596,12 @@ "type": "number", "minimum": 1, "error": "KCHTMPL0022E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 1e8b47a..9c81ea0 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -130,6 +130,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be greater than 1GB."), "KCHTMPL0023E": _("Template base image must be a valid local image file"), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), + "KCHTMPL0025E": _("Invalid disk image type. Types supported: 'qcow2', 'raw'"),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"), "KCHPOOL0002E": _("Storage pool %(name)s does not exist"), diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index c5bb7b3..9b8349d 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -195,7 +195,10 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/> src = os.path.join(storage_path, volume) dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']], string.lowercase[index])
- fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2' + if self._get_storage_type() in ['logical']: + fmt = 'raw' + else: + fmt = disk.get('type', 'qcow2')
If user passes a different type of 'raw' to a logical volume we should raise an error.
params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'], 'type': fmt} ret += """

On 09/04/2014 05:50 PM, Daniel Henrique Barboza wrote:
These changes implements the backend support for setting the disk image type in the VM template, by using a new parameter called "type" in the 'disk' object of the template_create schema.
If the parameter is not used, the template will use the default disk type (qcow2).
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-)
You also need to update mockmodel.py and add tests for this new feature.
diff --git a/docs/API.md b/docs/API.md index 298441f..11dba67 100644 --- a/docs/API.md +++ b/docs/API.md @@ -195,6 +195,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. * index: The device index * size: The device size in GB * base: Base image of this disk + * type: Type of the image (qcow2 or raw)
* graphics *(optional)*: The graphics paramenters of this template * type: The type of graphics. It can be VNC or spice or None. diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2e2f9b0..67ffaf7 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -419,6 +419,12 @@ "type": "string", "pattern": "^/.+$", "error": "KCHTMPL0023E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" }
} @@ -590,6 +596,12 @@ "type": "number", "minimum": 1, "error": "KCHTMPL0022E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 1e8b47a..9c81ea0 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -130,6 +130,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be greater than 1GB."), "KCHTMPL0023E": _("Template base image must be a valid local image file"), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), + "KCHTMPL0025E": _("Invalid disk image type. Types supported: 'qcow2', 'raw'"),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"), "KCHPOOL0002E": _("Storage pool %(name)s does not exist"), diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index c5bb7b3..9b8349d 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -195,7 +195,10 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/> src = os.path.join(storage_path, volume) dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']], string.lowercase[index]) - fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2' + if self._get_storage_type() in ['logical']: + fmt = 'raw' + else: + fmt = disk.get('type', 'qcow2') params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'], 'type': fmt} ret += """

On 09/16/2014 09:01 PM, Aline Manera wrote:
On 09/04/2014 05:50 PM, Daniel Henrique Barboza wrote:
These changes implements the backend support for setting the disk image type in the VM template, by using a new parameter called "type" in the 'disk' object of the template_create schema.
If the parameter is not used, the template will use the default disk type (qcow2).
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/API.json | 12 ++++++++++++ src/kimchi/i18n.py | 1 + src/kimchi/vmtemplate.py | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-)
You also need to update mockmodel.py and add tests for this new feature.
Ok!
diff --git a/docs/API.md b/docs/API.md index 298441f..11dba67 100644 --- a/docs/API.md +++ b/docs/API.md @@ -195,6 +195,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. * index: The device index * size: The device size in GB * base: Base image of this disk + * type: Type of the image (qcow2 or raw)
* graphics *(optional)*: The graphics paramenters of this template * type: The type of graphics. It can be VNC or spice or None. diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 2e2f9b0..67ffaf7 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -419,6 +419,12 @@ "type": "string", "pattern": "^/.+$", "error": "KCHTMPL0023E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" }
} @@ -590,6 +596,12 @@ "type": "number", "minimum": 1, "error": "KCHTMPL0022E" + }, + "type": { + "description": "Type of the image of the disk", + "type": "string", + "pattern": "^qcow2|raw$", + "error": "KCHTMPL0025E" } } }, diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py index 1e8b47a..9c81ea0 100644 --- a/src/kimchi/i18n.py +++ b/src/kimchi/i18n.py @@ -130,6 +130,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be greater than 1GB."), "KCHTMPL0023E": _("Template base image must be a valid local image file"), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), + "KCHTMPL0025E": _("Invalid disk image type. Types supported: 'qcow2', 'raw'"),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"), "KCHPOOL0002E": _("Storage pool %(name)s does not exist"), diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index c5bb7b3..9b8349d 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -195,7 +195,10 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/> src = os.path.join(storage_path, volume) dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']], string.lowercase[index]) - fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2' + if self._get_storage_type() in ['logical']: + fmt = 'raw' + else: + fmt = disk.get('type', 'qcow2') params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'], 'type': fmt} ret += """
participants (4)
-
Aline Manera
-
Daniel H Barboza
-
Daniel Henrique Barboza
-
Paulo Ricardo Paz Vital