On 11/25/2015 03:40 PM, Aline Manera wrote:
On 25/11/2015 04:45, Rodrigo Trujillo wrote:
> This patch fixes the backend code in order to allow create templates
> with multiple disks and update them correctly.
> Backend supports disks jsons like:
>
> "disks": [{"size": 3,
> "format": "qcow"},
> {"size": 5,
> "storagepool":"/plugins/kimchi/storagepools/poolX"},
> {"size": 7,
> "format": "raw",
> "storagepool":
"/plugins/kimchi/storagepools/poolY"}
> ]
>
> If any information is missing, Kimchi will use values from
> template.conf.
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
> ---
> src/wok/plugins/kimchi/API.json | 19 ++++++++++++++++++-
> src/wok/plugins/kimchi/docs/API.md | 3 +++
> src/wok/plugins/kimchi/model/templates.py | 9 +++++----
> src/wok/plugins/kimchi/osinfo.py | 1 +
> src/wok/plugins/kimchi/vmtemplate.py | 13 ++++++++++---
> 5 files changed, 37 insertions(+), 8 deletions(-)
>
> diff --git a/src/wok/plugins/kimchi/API.json
> b/src/wok/plugins/kimchi/API.json
> index ab9ac9b..e4cabd6 100644
> --- a/src/wok/plugins/kimchi/API.json
> +++ b/src/wok/plugins/kimchi/API.json
> @@ -477,6 +477,12 @@
> "type": "integer",
> "minimum": 0
> },
> + "format": {
> + "description": "Type of the image of
> the disk",
> + "type": "string",
> + "pattern":
> "^(bochs|cloop|cow|dmg|qcow|qcow2|qed|raw|vmdk|vpc)$",
> + "error": "KCHTMPL0027E"
> + },
> "size": {
> "description": "Size (GB) of the
> disk",
> "type": "number",
> @@ -488,8 +494,13 @@
> "type": "string",
> "pattern": "^/.+$",
> "error": "KCHTMPL0023E"
> + },
> + "storagepool": {
> + "description": "Location of the
> storage pool",
> + "type": "string",
> + "pattern":
> "^/plugins/kimchi/storagepools/[^/]+/?$",
> + "error": "KCHTMPL0015E"
> }
> -
> }
> },
> "minItems": 1,
> @@ -660,6 +671,12 @@
> "type": "string",
> "pattern":
> "^(bochs|cloop|cow|dmg|qcow|qcow2|qed|raw|vmdk|vpc)$",
> "error": "KCHTMPL0027E"
> + },
> + "storagepool": {
> + "description": "Location of the
> storage pool",
> + "type": "string",
> + "pattern":
> "^/plugins/kimchi/storagepools/[^/]+/?$",
> + "error": "KCHTMPL0015E"
> }
> }
> },
> diff --git a/src/wok/plugins/kimchi/docs/API.md
> b/src/wok/plugins/kimchi/docs/API.md
> index 5787755..93da547 100644
> --- a/src/wok/plugins/kimchi/docs/API.md
> +++ b/src/wok/plugins/kimchi/docs/API.md
> @@ -289,6 +289,8 @@ Represents a snapshot of the Virtual Machine's
> primary monitor.
> (either *size* or *volume* must be specified):
> * index: The device index
> * size: The device size in GB
> + * format: Format of the image. Valid formats: bochs, cloop,
> cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc
> + * storagepool: URI of the storagepool where disk will be
> created
> * base: Base image of this disk
>
> * graphics *(optional)*: The graphics paramenters of this template
> @@ -422,6 +424,7 @@ A interface represents available network
> interface on VM.
> * size: The device size in GB
> * volume: A volume name that contains the initial disk
> contents
> * format: Format of the image. Valid formats: bochs, cloop,
> cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc.
> + * storagepool: URI of the storagepool where template
> allocates vm disk.
> * graphics *(optional)*: A dict of graphics paramenters of this
> template
> * type: The type of graphics. It can be VNC or spice or None.
> * vnc: Graphical display using the Virtual Network
> diff --git a/src/wok/plugins/kimchi/model/templates.py
> b/src/wok/plugins/kimchi/model/templates.py
> index 47b2c9e..bac6e47 100644
> --- a/src/wok/plugins/kimchi/model/templates.py
> +++ b/src/wok/plugins/kimchi/model/templates.py
> @@ -234,8 +234,9 @@ class LibvirtVMTemplate(VMTemplate):
> self.conn = conn
> VMTemplate.__init__(self, args, scan)
>
> - def _storage_validate(self):
> - pool_uri = self.info['storagepool']
> + def _storage_validate(self, pool_uri=None):
> + if pool_uri is None:
> + pool_uri = self.info['storagepool']
> pool_name = pool_name_from_uri(pool_uri)
> try:
> conn = self.conn.get()
> @@ -278,8 +279,8 @@ class LibvirtVMTemplate(VMTemplate):
> xml = pool.XMLDesc(0)
> return xpath_get_text(xml, "/pool/target/path")[0]
>
> - def _get_storage_type(self):
> - pool = self._storage_validate()
> + def _get_storage_type(self, pool_uri=None):
> + pool = self._storage_validate(pool_uri)
> xml = pool.XMLDesc(0)
> return xpath_get_text(xml, "/pool/@type")[0]
>
> diff --git a/src/wok/plugins/kimchi/osinfo.py
> b/src/wok/plugins/kimchi/osinfo.py
> index 30ecd4f..12e5b4b 100644
> --- a/src/wok/plugins/kimchi/osinfo.py
> +++ b/src/wok/plugins/kimchi/osinfo.py
> @@ -158,6 +158,7 @@ def _get_tmpl_defaults():
> for disk in storage_section.keys():
> data = storage_section[disk]
> data['index'] = int(disk.split('.')[1])
> + data['storagepool'] = defaults['storagepool']
> defaults['disks'].append(data)
>
> # Parse processor section to get cpus and cpu_topology values
> diff --git a/src/wok/plugins/kimchi/vmtemplate.py
> b/src/wok/plugins/kimchi/vmtemplate.py
> index 3097b66..35210a3 100644
> --- a/src/wok/plugins/kimchi/vmtemplate.py
> +++ b/src/wok/plugins/kimchi/vmtemplate.py
> @@ -76,14 +76,21 @@ class VMTemplate(object):
> graphics.update(graph_args)
> args['graphics'] = graphics
> + # Support to create Template with multiple disks
> + for i, disk in enumerate(self.info['disks']):
> + self.info['disks'][i]['storagepooltype'] = \
> + self._get_storage_type(disk['storagepool'])
> +
So the pool type will be also returned in the API, right?
I think I have already suggested it before, but.... Keep the data
grouped, ie, for the storage pool information use a single JSON object
to care about that information:
disk: {pool: {name:..., 'type':...},
index: ...,
size:...
}
Also update the docs/API.md to reflect the addition of 'type'
Done in previous patch
> # Merge disks dict
> default_disk = self.info['disks'][0]
> for i, d in enumerate(args.get('disks', [])):
> disk = dict(default_disk)
> + disk['index'] = i
> disk.update(d)
> -
> + disk['storagepooltype'] = self._get_storage_type(
> + disk['storagepool'])
> # Assign right disk format to logical and [i]scsi
> storagepools
> - if self._get_storage_type() in ['logical', 'iscsi',
> 'scsi']:
> + if disk['storagepooltype'] in ['logical',
'iscsi', 'scsi']:
> disk['format'] = 'raw'
> args['disks'][i] = disk
>
> @@ -401,7 +408,7 @@ class VMTemplate(object):
> def _get_storage_path(self):
> return ''
>
> - def _get_storage_type(self):
> + def _get_storage_type(self, pool=None):
> return ''
>
> def _get_volume_path(self):
_______________________________________________
Kimchi-devel mailing list
Kimchi-devel(a)ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel