def _get_os_info(self, args, scan): distro = version = 'unknown' # Identify the cdrom if present iso = args.get('cdrom', '') if len(iso) > 0: if not iso.startswith('/'): self.info.update({'iso_stream': True}) if scan: distro, version = self.get_iso_info(iso) return distro, version # CDROM is not presented: check for base image base_imgs = [] for d in args.get('disks', []): if 'base' in d.keys(): base_imgs.append(d) if scan: distro, version = imageinfo.probe_image(d['base']) if 'size' not in d.keys(): d_info = imageinfo.probe_img_info(d['base']) d['size'] = d_info['virtual-size'] if len(base_imgs) == 0: raise MissingParameter("KCHTMPL0016E") return distro, version
def to_volume_list(self, vm_uuid): storage_path = self._get_storage_path() ret = [] for i, d in enumerate(self.info['disks']): index = d.get('index', i) volume = "%s-%s.img" % (vm_uuid, index) info = { 'name': volume, 'capacity': d['size'], 'format': d['format'], 'path': '%s/%s' % (storage_path, volume) } if 'logical' == self._get_storage_type() or \ info['format'] not in ['qcow2', 'raw']: info['allocation'] = info['capacity'] else: info['allocation'] = 0 if 'base' in d: info['base'] = dict() base_fmt = imageinfo.probe_img_info(d['base'])['format'] if base_fmt is None: raise InvalidParameter("KCHTMPL0024E", {'path': d['base']}) info['base']['path'] = d['base'] info['base']['format'] = base_fmt v_tree = E.volume(E.name(info['name'])) v_tree.append(E.allocation(str(info['allocation']), unit='G')) v_tree.append(E.capacity(str(info['capacity']), unit='G')) target_fmt = info['format'] if 'base' in d: # target must be qcow2 in order to use a backing file target_fmt = 'qcow2' v_tree.append( E.backingStore(E.path(info['base']['path']), E.format(type=info['base']['format']))) target = E.target(E.format(type=target_fmt), E.path(info['path'])) v_tree.append(target) info['xml'] = etree.tostring(v_tree) ret.append(info) return ret
def to_volume_list(self, vm_uuid): storage_path = self._get_storage_path() ret = [] for i, d in enumerate(self.info['disks']): index = d.get('index', i) volume = "%s-%s.img" % (vm_uuid, index) info = {'name': volume, 'capacity': d['size'], 'format': d['format'], 'path': '%s/%s' % (storage_path, volume)} if 'logical' == self._get_storage_type() or \ info['format'] not in ['qcow2', 'raw']: info['allocation'] = info['capacity'] else: info['allocation'] = 0 if 'base' in d: info['base'] = dict() base_fmt = imageinfo.probe_img_info(d['base'])['format'] if base_fmt is None: raise InvalidParameter("KCHTMPL0024E", {'path': d['base']}) info['base']['path'] = d['base'] info['base']['format'] = base_fmt v_tree = E.volume(E.name(info['name'])) v_tree.append(E.allocation(str(info['allocation']), unit='G')) v_tree.append(E.capacity(str(info['capacity']), unit='G')) target_fmt = info['format'] if 'base' in d: # target must be qcow2 in order to use a backing file target_fmt = 'qcow2' v_tree.append(E.backingStore( E.path(info['base']['path']), E.format(type=info['base']['format']))) target = E.target( E.format(type=target_fmt), E.path(info['path'])) v_tree.append(target) info['xml'] = etree.tostring(v_tree) ret.append(info) return ret