Exemplo n.º 1
0
    def lookup(self, pool, name):
        vol = self._get_storagevolume(pool, name)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        try:
            fmt = xmlutils.xpath_get_text(
                xml, "/volume/target/format/@type")[0]
        except IndexError:
            # Not all types of libvirt storage can provide volume format
            # infomation. When there is no format information, we assume
            # it's 'raw'.
            fmt = 'raw'
        ref_cnt = self._get_ref_cnt(pool, name, path)
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   ref_cnt=ref_cnt,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro, os_version=os_version, path=path,
                     bootable=bootable))

        return res
Exemplo n.º 2
0
    def lookup(self, pool, name):
        vol = self._get_storagevolume(pool, name)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        fmt = xmlutils.xpath_get_text(xml, "/volume/target/format/@type")[0]
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro, os_version=os_version, path=path,
                     bootable=bootable))

        return res
Exemplo n.º 3
0
 def lookup(self, pool, name):
     vol = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
     path = vol.path()
     info = vol.info()
     xml = vol.XMLDesc(0)
     try:
         fmt = xpath_get_text(xml, "/volume/target/format/@type")[0]
     except IndexError:
         # Not all types of libvirt storage can provide volume format
         # infomation. When there is no format information, we assume
         # it's 'raw'.
         fmt = 'raw'
     ref_cnt = get_disk_ref_cnt(self.objstore, self.conn, path)
     res = dict(type=VOLUME_TYPE_MAP[info[0]],
                capacity=info[1],
                allocation=info[2],
                path=path,
                ref_cnt=ref_cnt,
                format=fmt)
     if fmt == 'iso':
         if os.path.islink(path):
             path = os.path.join(os.path.dirname(path), os.readlink(path))
         os_distro = os_version = 'unknown'
         try:
             iso_img = IsoImage(path)
             os_distro, os_version = iso_img.probe()
             bootable = True
         except IsoFormatError:
             bootable = False
         res.update(
             dict(os_distro=os_distro,
                  os_version=os_version,
                  path=path,
                  bootable=bootable))
     return res
Exemplo n.º 4
0
    def lookup(self, pool, name):
        vol = self._get_storagevolume(pool, name)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        fmt = xmlutils.xpath_get_text(xml, "/volume/target/format/@type")[0]
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro,
                     os_version=os_version,
                     path=path,
                     bootable=bootable))

        return res
Exemplo n.º 5
0
 def get_iso_info(self, iso):
     iso_prefixes = ['/', 'http', 'https', 'ftp', 'ftps', 'tftp']
     if len(filter(iso.startswith, iso_prefixes)) == 0:
         raise InvalidParameter("KCHTMPL0006E", {'param': iso})
     try:
         iso_img = IsoImage(iso)
         return iso_img.probe()
     except IsoFormatError:
         raise InvalidParameter("KCHISO0001E", {'filename': iso})
Exemplo n.º 6
0
 def get_iso_info(self, iso):
     iso_prefixes = ['/', 'http', 'https', 'ftp', 'ftps', 'tftp']
     if len(filter(iso.startswith, iso_prefixes)) == 0:
         raise InvalidParameter("KCHTMPL0006E", {'param': iso})
     try:
         iso_img = IsoImage(iso)
         return iso_img.probe()
     except IsoFormatError:
         raise InvalidParameter("KCHISO0001E", {'filename': iso})
Exemplo n.º 7
0
 def get_iso_info(self, iso):
     iso_prefixes = ["/", "http", "https", "ftp", "ftps", "tftp"]
     if len(filter(iso.startswith, iso_prefixes)) == 0:
         raise InvalidParameter("KCHTMPL0006E", {"param": iso})
     try:
         iso_img = IsoImage(iso)
         return iso_img.probe()
     except IsoFormatError:
         raise InvalidParameter("KCHISO0001E", {"filename": iso})
Exemplo n.º 8
0
        def updater(iso_info):
            iso_name = os.path.basename(iso_info['path'])[:-3]

            duplicates = "%s/%s*" % (params['pool_path'], iso_name)
            for f in glob.glob(duplicates):
                iso_img = IsoImage(f)
                if (iso_info['distro'], iso_info['version']) == iso_img.probe():
                    return

            iso_path = iso_name + hashlib.md5(iso_info['path']).hexdigest() + '.iso'
            link_name = os.path.join(params['pool_path'],
                                     os.path.basename(iso_path))
            os.symlink(iso_info['path'], link_name)
Exemplo n.º 9
0
    def lookup(self, pool, name):
        vol = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        try:
            fmt = xpath_get_text(xml, "/volume/target/format/@type")[0]
        except IndexError:
            # Not all types of libvirt storage can provide volume format
            # infomation. When there is no format information, we assume
            # it's 'raw'.
            fmt = 'raw'

        iso_img = None

        # 'raw' volumes from 'logical' pools may actually be 'iso';
        # libvirt always reports them as 'raw'
        pool_info = self.storagepool.lookup(pool)
        if pool_info['type'] == 'logical' and fmt == 'raw':
            try:
                iso_img = IsoImage(path)
            except IsoFormatError:
                # not 'iso' afterall
                pass
            else:
                fmt = 'iso'

        used_by = get_disk_used_by(self.objstore, self.conn, path)
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   used_by=used_by,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                if iso_img is None:
                    iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro,
                     os_version=os_version,
                     path=path,
                     bootable=bootable))
        return res
Exemplo n.º 10
0
    def lookup(self, pool, name):
        vol = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        try:
            fmt = xpath_get_text(xml, "/volume/target/format/@type")[0]
        except IndexError:
            # Not all types of libvirt storage can provide volume format
            # infomation. When there is no format information, we assume
            # it's 'raw'.
            fmt = 'raw'

        iso_img = None

        # 'raw' volumes from 'logical' pools may actually be 'iso';
        # libvirt always reports them as 'raw'
        pool_info = self.storagepool.lookup(pool)
        if pool_info['type'] == 'logical' and fmt == 'raw':
            try:
                iso_img = IsoImage(path)
            except IsoFormatError:
                # not 'iso' afterall
                pass
            else:
                fmt = 'iso'

        used_by = get_disk_used_by(self.objstore, self.conn, path)
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   used_by=used_by,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                if iso_img is None:
                    iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro, os_version=os_version, path=path,
                     bootable=bootable))
        return res
Exemplo n.º 11
0
        def updater(iso_info):
            iso_name = os.path.basename(iso_info['path'])[:-3]

            duplicates = "%s/%s*" % (params['pool_path'], iso_name)
            for f in glob.glob(duplicates):
                iso_img = IsoImage(f)
                if (iso_info['distro'],
                        iso_info['version']) == iso_img.probe():
                    return

            iso_path = iso_name + hashlib.md5(
                iso_info['path']).hexdigest() + '.iso'
            link_name = os.path.join(params['pool_path'],
                                     os.path.basename(iso_path))
            os.symlink(iso_info['path'], link_name)
Exemplo n.º 12
0
    def __init__(self, args, scan=False):
        """
        Construct a VM Template from a widely variable amount of information.
        The only required parameter is a name for the VMTemplate.  If present,
        the os_distro and os_version fields are used to lookup recommended
        settings.  Any parameters provided by the caller will override the
        defaults.  If scan is True and a cdrom is present, the operating system
        will be detected by probing the installation media.
        """
        self.name = args['name']
        self.info = {}

        # Identify the cdrom if present
        iso_distro = iso_version = 'unknown'
        iso = args.get('cdrom', '')

        if scan and len(iso) > 0:

            iso_prefixes = ['/', 'http', 'https', 'ftp', 'ftps', 'tftp']
            if len(filter(iso.startswith, iso_prefixes)) == 0:
                raise InvalidParameter("KCHTMPL0006E", {'param': iso})

            if not iso.startswith('/'):
                self.info.update({'iso_stream': True})

            try:
                iso_img = IsoImage(iso)
                iso_distro, iso_version = iso_img.probe()
            except IsoFormatError:
                raise InvalidParameter("KCHISO0001E", {'filename': iso})

        # Fetch defaults based on the os distro and version
        os_distro = args.get('os_distro', iso_distro)
        os_version = args.get('os_version', iso_version)
        entry = osinfo.lookup(os_distro, os_version)
        self.info.update(entry)

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)
Exemplo n.º 13
0
    def lookup(self, pool, name):
        vol = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        try:
            fmt = xpath_get_text(xml, "/volume/target/format/@type")[0]
        except IndexError:
            # Not all types of libvirt storage can provide volume format
            # infomation. When there is no format information, we assume
            # it's 'raw'.
            fmt = 'raw'

        iso_img = None

        # 'raw' volumes from 'logical' pools may actually be 'iso';
        # libvirt always reports them as 'raw'
        pool_info = self.storagepool.lookup(pool)
        if pool_info['type'] == 'logical' and fmt == 'raw':
            try:
                iso_img = IsoImage(path)
            except IsoFormatError:
                # not 'iso' afterall
                pass
            else:
                fmt = 'iso'

        # 'raw' volumes can not be valid image disks (e.g. XML, PDF, TXT are
        # raw files), so it's necessary check the 'content' of them
        isvalid = True
        if fmt == 'raw':
            try:
                ms = magic.open(magic.NONE)
                ms.load()
                if ms.file(path).lower() not in VALID_RAW_CONTENT:
                    isvalid = False
                ms.close()
            except UnicodeDecodeError:
                isvalid = False

        used_by = get_disk_used_by(self.objstore, self.conn, path)
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   used_by=used_by,
                   format=fmt,
                   isvalid=isvalid)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                if iso_img is None:
                    iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro, os_version=os_version, path=path,
                     bootable=bootable))
        return res