Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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)