Example #1
0
    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
Example #2
0
    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
Example #3
0
    def to_volume_list(self, vm_uuid):
        storage_path = self._get_storage_path()
        fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2'
        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': fmt,
                    'path': '%s/%s' % (storage_path, volume)}
            info['allocation'] = 0 if fmt == 'qcow2' else info['capacity']

            if 'base' in d:
                info['base'] = dict()
                base_fmt = 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 = E.target(
                E.format(type=info['format']), E.path(info['path']))
            if 'base' in d:
                v_tree.append(E.backingStore(
                    E.path(info['base']['path']),
                    E.format(type=info['base']['format'])))
            v_tree.append(target)
            info['xml'] = etree.tostring(v_tree)
            ret.append(info)
        return ret
Example #4
0
    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
Example #5
0
    def to_volume_list(self, vm_uuid):
        storage_path = self._get_storage_path()
        fmt = "raw" if self._get_storage_type() in ["logical"] else "qcow2"
        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": fmt, "path": "%s/%s" % (storage_path, volume)}

            if "logical" == self._get_storage_type() or fmt 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 = E.target(E.format(type=info["format"]), E.path(info["path"]))
            if "base" in d:
                v_tree.append(E.backingStore(E.path(info["base"]["path"]), E.format(type=info["base"]["format"])))
            v_tree.append(target)
            info["xml"] = etree.tostring(v_tree)
            ret.append(info)
        return ret
Example #6
0
    def _get_os_info(self, args, scan):
        # Identify the cdrom if present
        distro = version = 'unknown'
        iso = args.get('cdrom', '')
        valid = False
        # if ISO not specified and base disk image specified,
        # prevent cdrom from filling automatically
        if len(iso) == 0 and 'disks' in args:
            for d in args['disks']:
                if 'base' in d:
                    valid = True
                    try:
                        distro, version = probe_image(d['base'])
                    except ImageFormatError:
                        pass
                    if 'size' not in d:
                        d['size'] = probe_img_info(d['base'])['virtual-size']

        if len(iso) > 0:
            valid = True
            if scan:
                distro, version = self.get_iso_info(iso)
            if not iso.startswith('/'):
                self.info.update({'iso_stream': True})

        if not valid:
            raise MissingParameter("KCHTMPL0016E")

        return distro, version
Example #7
0
    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