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


Python KaresansuiVirtConnection.create_storage_volume方法代码示例

本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.create_storage_volume方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.create_storage_volume方法的具体用法?Python KaresansuiVirtConnection.create_storage_volume怎么用?Python KaresansuiVirtConnection.create_storage_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karesansui.lib.virt.virt.KaresansuiVirtConnection的用法示例。


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

示例1: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import create_storage_volume [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)

        self.up_progress(10)
        conn = KaresansuiVirtConnection(readonly=False)

        try:
            try:
                #inactive_storage_pools = conn.list_inactive_storage_pool()
                inactive_storage_pools = []
                active_storage_pools = conn.list_active_storage_pool()
                if not (opts.pool_name in active_storage_pools or \
                        opts.pool_name in inactive_storage_pools):
                    raise KssCommandException('Storage pool does not exist. Alternatively, the storage pool is not started. - pool=%s'
                                              % opts.pool_name)

                if conn.get_storage_volume(opts.pool_name, opts.volume_name) is not None:
                    raise KssCommandException(
                        'We already have a storage volume. - pool=%s, vol=%s'
                        % (opts.pool_name, opts.volume_name))

                pool_obj = conn.search_kvn_storage_pools(opts.pool_name)[0]
                pool_info = pool_obj.get_info()
                if not pool_info['allocation'] or pool_info['allocation'] == 0:
                    storage_volume_allocation_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
                else:
                    storage_volume_allocation_max_size = long(pool_info['allocation']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
                    if pool_info['type'] == 'dir' or pool_info['type'] == 'fs':
                        storage_volume_allocation_max_size = long(pool_info["available"]) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
                if not pool_info['capacity'] or pool_info['capacity'] == 0:
                    storage_volume_capacity_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
                else:
                    storage_volume_capacity_max_size = long(pool_info['capacity']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)

                if opts.allocation < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_allocation_max_size < opts.allocation:
                    raise KssCommandException('Allocation "%s%s" is out of available range. available=%s-%s%s'
                                              % (opts.allocation, opts.unit, STORAGE_VOLUME_SIZE_MIN_LENGTH, storage_volume_allocation_max_size, opts.unit))
                if opts.capacity < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_capacity_max_size < opts.capacity:
                    raise KssCommandException('Capacity "%s%s" is out of available range. available=%s-%s%s'
                                              % (opts.capacity, opts.unit, STORAGE_VOLUME_SIZE_MIN_LENGTH, storage_volume_capacity_max_size, opts.unit))

                if conn.create_storage_volume(opts.name,
                                              opts.pool_name,
                                              opts.format,
                                              use=opts.use,
                                              volume_name=opts.volume_name,
                                              capacity=opts.capacity,
                                              allocation=opts.allocation,
                                              c_unit=opts.unit,
                                              t_p_owner=opts.permission_owner,
                                              t_p_group=opts.permission_group,
                                              t_p_mode=opts.permission_mode,
                                           ) is False:
                    raise KssCommandException('Failed to create storage volume. (libvirt) - pool=%s, vol=%s'
                                              % (opts.pool_name, opts.volume_name))

                self.up_progress(40)

                vol_path = conn.get_storage_volume_path(opts.pool_name, opts.volume_name)
                if vol_path is None:
                    raise KssCommandException(
                        'Could not get the normal storage pool or storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                if os.path.isfile(vol_path) is False:
                    raise KssCommandException(
                        'File does not exist in the path of a storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                vol_obj = conn.get_storage_volume(opts.pool_name, opts.volume_name)
                if vol_obj is None:
                    raise KssCommandException(
                        'Could not get the normal storage pool or storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                vol_link = "%s/%s" % (pool_info['target']['path'], vol_obj.name())
                if os.path.islink(vol_link) is False:
                    raise KssCommandException(
                        'Symbolic link does not exist in the path of a storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                self.logger.info('Created storage volume. - vol=%s' % (opts.volume_name))
                print >>sys.stdout, _('Created storage volume. - vol=%s') % (opts.volume_name)
                return True
            except KssCommandException, e:
                raise e
        finally:
            conn.close()
开发者ID:fkei,项目名称:karesansui,代码行数:91,代码来源:create_storage_volume.py


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