当前位置: 首页>>代码示例>>Python>>正文


Python constants.type2name函数代码示例

本文整理汇总了Python中vdsm.storage.constants.type2name函数的典型用法代码示例。如果您正苦于以下问题:Python type2name函数的具体用法?Python type2name怎么用?Python type2name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了type2name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_file_volume

def make_file_volume(sd_manifest, size, imguuid, voluuid,
                     parent_vol_id=sc.BLANK_UUID,
                     vol_format=sc.RAW_FORMAT,
                     vol_type=sc.LEAF_VOL,
                     prealloc=sc.SPARSE_VOL,
                     disk_type=image.UNKNOWN_DISK_TYPE,
                     desc='fake volume'):
    volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid)
    mdfiles = [volpath + '.meta', volpath + '.lease']
    make_file(volpath, size)
    for mdfile in mdfiles:
        make_file(mdfile)

    size_blk = size / sc.BLOCK_SIZE
    vol_class = sd_manifest.getVolumeClass()
    vol_class.newMetadata(
        (volpath,),
        sd_manifest.sdUUID,
        imguuid,
        parent_vol_id,
        size_blk,
        sc.type2name(vol_format),
        sc.type2name(prealloc),
        sc.type2name(vol_type),
        disk_type,
        desc,
        sc.LEGAL_VOL)
开发者ID:EdDev,项目名称:vdsm,代码行数:27,代码来源:storagetestlib.py

示例2: _create_metadata_artifact

    def _create_metadata_artifact(self, size, vol_format, prealloc, disk_type,
                                  desc, parent):
        if self._oop.fileUtils.pathExists(self.meta_path):
            raise se.VolumeAlreadyExists("metadata exists: %r" %
                                         self.meta_path)

        if self._oop.fileUtils.pathExists(self.meta_volatile_path):
            raise se.DomainHasGarbage("metadata artifact exists: %r" %
                                      self.meta_volatile_path)

        parent_vol_id = parent.vol_id if parent else sc.BLANK_UUID
        # Create the metadata artifact.  The metadata file is created with a
        # special extension to prevent these artifacts from being recognized as
        # a volume until FileVolumeArtifacts.commit() is called.
        meta = VolumeMetadata(
            self.sd_manifest.sdUUID,
            self.img_id,
            parent_vol_id,
            size / sc.BLOCK_SIZE,  # Size is stored as number of blocks
            sc.type2name(vol_format),
            sc.type2name(prealloc),
            sc.type2name(sc.LEAF_VOL),
            disk_type,
            desc,
            sc.LEGAL_VOL)
        self._oop.writeFile(self.meta_volatile_path, meta.storage_format())
开发者ID:andrewlukoshko,项目名称:vdsm,代码行数:26,代码来源:volume_artifacts.py

示例3: _create_metadata

    def _create_metadata(self, meta_slot, size, vol_format, prealloc,
                         disk_type, desc, parent):
        # When the volume format is RAW the real volume capacity is the device
        # size.  The device size may have been rounded up if 'size' is not
        # divisible by the domain's extent size.
        if vol_format == sc.RAW_FORMAT:
            size = int(self.sd_manifest.getVSize(self.img_id, self.vol_id))

        # We use the BlockVolumeManifest API here because we create the
        # metadata in the standard way.  We cannot do this for file volumes
        # because the metadata needs to be written to a specially named file.
        meta_id = (self.sd_manifest.sdUUID, meta_slot)
        parent_vol_id = parent.vol_id if parent else sc.BLANK_UUID
        size_blk = size / sc.BLOCK_SIZE
        self.vol_class.newMetadata(
            meta_id,
            self.sd_manifest.sdUUID,
            self.img_id,
            parent_vol_id,
            size_blk,
            sc.type2name(vol_format),
            sc.type2name(prealloc),
            sc.type2name(sc.LEAF_VOL),
            disk_type,
            desc,
            sc.LEGAL_VOL)
开发者ID:andrewlukoshko,项目名称:vdsm,代码行数:26,代码来源:volume_artifacts.py

示例4: make_block_volume

def make_block_volume(lvm, sd_manifest, size, imguuid, voluuid,
                      parent_vol_id=sc.BLANK_UUID,
                      vol_format=sc.RAW_FORMAT,
                      vol_type=sc.LEAF_VOL,
                      prealloc=sc.PREALLOCATED_VOL,
                      disk_type=sc.DATA_DISKTYPE,
                      desc='fake volume', qcow2_compat='0.10'):
    sduuid = sd_manifest.sdUUID
    imagedir = sd_manifest.getImageDir(imguuid)
    if not os.path.exists(imagedir):
        os.makedirs(imagedir)

    size_blk = (size + sc.BLOCK_SIZE - 1) // sc.BLOCK_SIZE
    lv_size = sd_manifest.getVolumeClass().calculate_volume_alloc_size(
        prealloc, size_blk, None)
    lvm.createLV(sduuid, voluuid, lv_size)
    # LVM may create the volume with a larger size due to extent granularity
    lv_size_blk = int(lvm.getLV(sduuid, voluuid).size) // sc.BLOCK_SIZE
    if lv_size_blk > size_blk:
        size_blk = lv_size_blk

    if vol_format == sc.COW_FORMAT:
        volpath = lvm.lvPath(sduuid, voluuid)
        backing = parent_vol_id if parent_vol_id != sc.BLANK_UUID else None

        # Write qcow2 image to the fake block device - truncating the file.
        op = qemuimg.create(
            volpath,
            size=size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat=qcow2_compat,
            backing=backing)
        op.run()

        # Truncate fake block device back ot the proper size.
        with open(volpath, "r+") as f:
            f.truncate(int(lvm.getLV(sduuid, voluuid).size))

    with sd_manifest.acquireVolumeMetadataSlot(voluuid) as slot:
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_MD, slot))
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_PARENT,
                                              parent_vol_id))
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_IMAGE, imguuid))

    vol_class = sd_manifest.getVolumeClass()
    vol_class.newMetadata(
        (sduuid, slot),
        sduuid,
        imguuid,
        parent_vol_id,
        size_blk,
        sc.type2name(vol_format),
        sc.type2name(prealloc),
        sc.type2name(vol_type),
        disk_type,
        desc,
        sc.LEGAL_VOL)
开发者ID:oVirt,项目名称:vdsm,代码行数:57,代码来源:storagetestlib.py

示例5: test_set_type

 def test_set_type(self, env_type):
     with self.make_env(env_type) as env:
         leaf_vol = env.chain[0]
         generation = leaf_vol.getMetaParam(sc.GENERATION)
         job = update_volume.Job(make_uuid(), 0,
                                 make_endpoint_from_volume(leaf_vol),
                                 dict(type=sc.type2name(sc.SHARED_VOL)))
         job.run()
         self.assertEqual(jobs.STATUS.DONE, job.status)
         self.assertEqual(sc.type2name(sc.SHARED_VOL),
                          leaf_vol.getMetaParam(sc.VOLTYPE))
         self.assertEqual(generation + 1,
                          leaf_vol.getMetaParam(sc.GENERATION))
开发者ID:nirs,项目名称:vdsm,代码行数:13,代码来源:sdm_update_volume_test.py

示例6: test_set_type_leaf_with_parent

 def test_set_type_leaf_with_parent(self, env_type):
     with self.make_env(env_type, chain_length=2) as env:
         top_vol = env.chain[1]
         generation = top_vol.getMetaParam(sc.GENERATION)
         job = update_volume.Job(make_uuid(), 0,
                                 make_endpoint_from_volume(top_vol),
                                 dict(type=sc.type2name(sc.SHARED_VOL)))
         job.run()
         self.assertEqual(job.status, jobs.STATUS.FAILED)
         self.assertEqual(type(job.error), se.InvalidVolumeUpdate)
         self.assertEqual(sc.type2name(sc.LEAF_VOL),
                          top_vol.getMetaParam(sc.VOLTYPE))
         self.assertEqual(generation,
                          top_vol.getMetaParam(sc.GENERATION))
开发者ID:nirs,项目名称:vdsm,代码行数:14,代码来源:sdm_update_volume_test.py

示例7: make_init_params

def make_init_params(**kwargs):
    res = dict(
        domain=str(uuid.uuid4()),
        image=str(uuid.uuid4()),
        puuid=str(uuid.uuid4()),
        size=1024 * MB,
        format=sc.type2name(sc.RAW_FORMAT),
        type=sc.type2name(sc.SPARSE_VOL),
        voltype=sc.type2name(sc.LEAF_VOL),
        disktype=image.SYSTEM_DISK_TYPE,
        description="",
        legality=sc.LEGAL_VOL)
    res.update(kwargs)
    return res
开发者ID:andrewlukoshko,项目名称:vdsm,代码行数:14,代码来源:storage_volume_metadata_test.py

示例8: make_init_params

def make_init_params(**kwargs):
    res = dict(
        domain=make_uuid(),
        image=make_uuid(),
        puuid=make_uuid(),
        capacity=1024 * MB,
        format=sc.type2name(sc.RAW_FORMAT),
        type=sc.type2name(sc.SPARSE_VOL),
        voltype=sc.type2name(sc.LEAF_VOL),
        disktype=image.SYSTEM_DISK_TYPE,
        description="",
        legality=sc.LEGAL_VOL,
        generation=sc.DEFAULT_GENERATION)
    res.update(kwargs)
    return res
开发者ID:nirs,项目名称:vdsm,代码行数:15,代码来源:volume_metadata_test.py

示例9: test_volume_type

 def test_volume_type(self, vol_type):
     with fake_block_env() as env:
         img_id = make_uuid()
         vol_id = make_uuid()
         make_block_volume(env.lvm, env.sd_manifest, 0,
                           img_id, vol_id, vol_type=vol_type)
         vol = env.sd_manifest.produceVolume(img_id, vol_id)
         self.assertEqual(vol.getVolType(), sc.type2name(vol_type))
开发者ID:nirs,项目名称:vdsm,代码行数:8,代码来源:testlib_test.py

示例10: _create

    def _create(cls, dom, imgUUID, volUUID, size, volFormat, preallocate,
                volParent, srcImgUUID, srcVolUUID, volPath,
                initialSize=None):
        """
        Class specific implementation of volumeCreate. All the exceptions are
        properly handled and logged in volume.create()
        """
        if initialSize:
            cls.log.error("initialSize is not supported for file-based "
                          "volumes")
            raise se.InvalidParameterException("initial size",
                                               initialSize)

        sizeBytes = size * BLOCK_SIZE
        truncSize = sizeBytes if volFormat == sc.RAW_FORMAT else 0

        try:
            oop.getProcessPool(dom.sdUUID).truncateFile(
                volPath, truncSize, mode=sc.FILE_VOLUME_PERMISSIONS,
                creatExcl=True)
        except OSError as e:
            if e.errno == errno.EEXIST:
                raise se.VolumeAlreadyExists(volUUID)
            raise

        if preallocate == sc.PREALLOCATED_VOL:
            try:
                operation = fallocate.allocate(volPath,
                                               sizeBytes)
                with vars.task.abort_callback(operation.abort):
                    with utils.stopwatch("Preallocating volume %s" % volPath):
                        operation.run()
            except exception.ActionStopped:
                raise
            except Exception:
                cls.log.error("Unexpected error", exc_info=True)
                raise se.VolumesZeroingError(volPath)

        if not volParent:
            cls.log.info("Request to create %s volume %s with size = %s "
                         "sectors", sc.type2name(volFormat), volPath,
                         size)
            if volFormat == sc.COW_FORMAT:
                qemuimg.create(volPath,
                               size=sizeBytes,
                               format=sc.fmt2str(volFormat),
                               qcow2Compat=dom.qcow2_compat())
        else:
            # Create hardlink to template and its meta file
            cls.log.info("Request to create snapshot %s/%s of volume %s/%s",
                         imgUUID, volUUID, srcImgUUID, srcVolUUID)
            volParent.clone(volPath, volFormat)

        # Forcing the volume permissions in case one of the tools we use
        # (dd, qemu-img, etc.) will mistakenly change the file permissiosn.
        dom.oop.os.chmod(volPath, sc.FILE_VOLUME_PERMISSIONS)

        return (volPath,)
开发者ID:EdDev,项目名称:vdsm,代码行数:58,代码来源:fileVolume.py

示例11: make_block_volume

def make_block_volume(lvm, sd_manifest, size, imguuid, voluuid,
                      parent_vol_id=sc.BLANK_UUID,
                      vol_format=sc.RAW_FORMAT,
                      vol_type=sc.LEAF_VOL,
                      prealloc=sc.PREALLOCATED_VOL,
                      disk_type=image.UNKNOWN_DISK_TYPE,
                      desc='fake volume'):
    sduuid = sd_manifest.sdUUID
    image_manifest = image.ImageManifest(sd_manifest.getRepoPath())
    imagedir = image_manifest.getImageDir(sduuid, imguuid)
    if not os.path.exists(imagedir):
        os.makedirs(imagedir)

    size_blk = (size + sc.BLOCK_SIZE - 1) / sc.BLOCK_SIZE
    lv_size = sd_manifest.getVolumeClass().calculate_volume_alloc_size(
        prealloc, size_blk, None)
    lvm.createLV(sduuid, voluuid, lv_size)
    # LVM may create the volume with a larger size due to extent granularity
    lv_size_blk = int(lvm.getLV(sduuid, voluuid).size) / sc.BLOCK_SIZE
    if lv_size_blk > size_blk:
        size_blk = lv_size_blk

    with sd_manifest.acquireVolumeMetadataSlot(
            voluuid, sc.VOLUME_MDNUMBLKS) as slot:
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_MD, slot))
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_PARENT,
                                              parent_vol_id))
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_IMAGE, imguuid))

    vol_class = sd_manifest.getVolumeClass()
    vol_class.newMetadata(
        (sduuid, slot),
        sduuid,
        imguuid,
        parent_vol_id,
        size_blk,
        sc.type2name(vol_format),
        sc.type2name(prealloc),
        sc.type2name(vol_type),
        disk_type,
        desc,
        sc.LEGAL_VOL)
开发者ID:EdDev,项目名称:vdsm,代码行数:42,代码来源:storagetestlib.py

示例12: make_file_volume

def make_file_volume(sd_manifest, size, imguuid, voluuid,
                     parent_vol_id=sc.BLANK_UUID,
                     vol_format=sc.RAW_FORMAT,
                     vol_type=sc.LEAF_VOL,
                     prealloc=sc.SPARSE_VOL,
                     disk_type=sc.DATA_DISKTYPE,
                     desc='fake volume', qcow2_compat='0.10'):
    volpath = os.path.join(sd_manifest.domaindir, "images", imguuid, voluuid)

    # Create needed path components.
    make_file(volpath, size)

    # Create qcow2 file if needed.
    if vol_format == sc.COW_FORMAT:
        backing = parent_vol_id if parent_vol_id != sc.BLANK_UUID else None
        op = qemuimg.create(
            volpath,
            size=size,
            format=qemuimg.FORMAT.QCOW2,
            qcow2Compat=qcow2_compat,
            backing=backing)
        op.run()

    # Create meta files.
    mdfiles = [volpath + '.meta', volpath + '.lease']
    for mdfile in mdfiles:
        make_file(mdfile)

    size_blk = size // sc.BLOCK_SIZE
    vol_class = sd_manifest.getVolumeClass()
    vol_class.newMetadata(
        (volpath,),
        sd_manifest.sdUUID,
        imguuid,
        parent_vol_id,
        size_blk,
        sc.type2name(vol_format),
        sc.type2name(prealloc),
        sc.type2name(vol_type),
        disk_type,
        desc,
        sc.LEGAL_VOL)
开发者ID:oVirt,项目名称:vdsm,代码行数:42,代码来源:storagetestlib.py

示例13: test_set_type_internal

 def test_set_type_internal(self, env_type):
     with self.make_env(env_type, chain_length=1) as env:
         internal_vol = env.chain[0]
         generation = internal_vol.getMetaParam(sc.GENERATION)
         internal_vol.setInternal()
         job = update_volume.Job(make_uuid(), 0,
                                 make_endpoint_from_volume(internal_vol),
                                 dict(type=sc.type2name(sc.SHARED_VOL)))
         job.run()
         self.assertEqual(job.status, jobs.STATUS.FAILED)
         self.assertEqual(type(job.error), se.InvalidVolumeUpdate)
         self.assertEqual(generation,
                          internal_vol.getMetaParam(sc.GENERATION))
开发者ID:nirs,项目名称:vdsm,代码行数:13,代码来源:sdm_update_volume_test.py

示例14: validateCreateVolumeParams

    def validateCreateVolumeParams(self, volFormat, srcVolUUID,
                                   preallocate=None):
        """
        Validate create volume parameters
        """
        if volFormat not in sc.VOL_FORMAT:
            raise se.IncorrectFormat(volFormat)

        # Volumes with a parent must be cow
        if srcVolUUID != sc.BLANK_UUID and volFormat != sc.COW_FORMAT:
            raise se.IncorrectFormat(sc.type2name(volFormat))

        if preallocate is not None and preallocate not in sc.VOL_TYPE:
            raise se.IncorrectType(preallocate)
开发者ID:EdDev,项目名称:vdsm,代码行数:14,代码来源:sd.py

示例15: make_block_volume

def make_block_volume(lvm, sd_manifest, size, imguuid, voluuid,
                      parent_vol_id=sc.BLANK_UUID,
                      vol_format=sc.RAW_FORMAT,
                      prealloc=sc.PREALLOCATED_VOL,
                      disk_type=image.UNKNOWN_DISK_TYPE,
                      desc='fake volume'):
    sduuid = sd_manifest.sdUUID
    image_manifest = image.ImageManifest(sd_manifest.getRepoPath())
    imagedir = image_manifest.getImageDir(sduuid, imguuid)
    if not os.path.exists(imagedir):
        os.makedirs(imagedir)

    size_mb = utils.round(size, MB) / MB
    lvm.createLV(sduuid, voluuid, size_mb)
    lv_size = int(lvm.getLV(sduuid, voluuid).size)
    lv_size_blk = lv_size / sc.BLOCK_SIZE

    with sd_manifest.acquireVolumeMetadataSlot(
            voluuid, sc.VOLUME_MDNUMBLKS) as slot:
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_MD, slot))
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_PARENT,
                                              sc.BLANK_UUID))
        lvm.addtag(sduuid, voluuid, "%s%s" % (sc.TAG_PREFIX_IMAGE, imguuid))

    vol_class = sd_manifest.getVolumeClass()
    vol_class.newMetadata(
        (sduuid, slot),
        sduuid,
        imguuid,
        parent_vol_id,
        lv_size_blk,
        sc.type2name(vol_format),
        sc.type2name(prealloc),
        sc.type2name(sc.LEAF_VOL),
        disk_type,
        desc,
        sc.LEGAL_VOL)
开发者ID:yingyun001,项目名称:vdsm,代码行数:37,代码来源:storagetestlib.py


注:本文中的vdsm.storage.constants.type2name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。