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


Python VMHelper.determine_disk_image_type方法代码示例

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


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

示例1: _create_disk

# 需要导入模块: from nova.virt.xenapi.vm_utils import VMHelper [as 别名]
# 或者: from nova.virt.xenapi.vm_utils.VMHelper import determine_disk_image_type [as 别名]
 def _create_disk(self, instance):
     user = AuthManager().get_user(instance.user_id)
     project = AuthManager().get_project(instance.project_id)
     disk_image_type = VMHelper.determine_disk_image_type(instance)
     vdi_uuid = VMHelper.fetch_image(self._session, instance.id,
             instance.image_id, user, project, disk_image_type)
     return vdi_uuid
开发者ID:pombredanne,项目名称:nova,代码行数:9,代码来源:vmops.py

示例2: _create_vm

# 需要导入模块: from nova.virt.xenapi.vm_utils import VMHelper [as 别名]
# 或者: from nova.virt.xenapi.vm_utils.VMHelper import determine_disk_image_type [as 别名]
    def _create_vm(self, instance, vdi_uuid, network_info=None):
        """Create VM instance."""
        instance_name = instance.name
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is not None:
            raise exception.InstanceExists(name=instance_name)

        #ensure enough free memory is available
        if not VMHelper.ensure_free_mem(self._session, instance):
            LOG.exception(_('instance %(instance_name)s: not enough free '
                          'memory') % locals())
            db.instance_set_state(context.get_admin_context(),
                                  instance['id'],
                                  power_state.SHUTDOWN)
            return

        user = AuthManager().get_user(instance.user_id)
        project = AuthManager().get_project(instance.project_id)

        # Are we building from a pre-existing disk?
        vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdi_uuid)

        disk_image_type = VMHelper.determine_disk_image_type(instance)

        kernel = None
        if instance.kernel_id:
            kernel = VMHelper.fetch_image(self._session, instance.id,
                instance.kernel_id, user, project, ImageType.KERNEL_RAMDISK)

        ramdisk = None
        if instance.ramdisk_id:
            ramdisk = VMHelper.fetch_image(self._session, instance.id,
                instance.ramdisk_id, user, project, ImageType.KERNEL_RAMDISK)

        use_pv_kernel = VMHelper.determine_is_pv(self._session, instance.id,
            vdi_ref, disk_image_type, instance.os_type)
        vm_ref = VMHelper.create_vm(self._session, instance, kernel, ramdisk,
                                    use_pv_kernel)

        VMHelper.create_vbd(session=self._session, vm_ref=vm_ref,
                vdi_ref=vdi_ref, userdevice=0, bootable=True)

        # TODO(tr3buchet) - check to make sure we have network info, otherwise
        # create it now. This goes away once nova-multi-nic hits.
        if network_info is None:
            network_info = self._get_network_info(instance)

        # Alter the image before VM start for, e.g. network injection
        if FLAGS.xenapi_inject_image:
            VMHelper.preconfigure_instance(self._session, instance,
                                           vdi_ref, network_info)

        self.create_vifs(vm_ref, network_info)
        self.inject_network_info(instance, network_info, vm_ref)
        return vm_ref
开发者ID:superstack,项目名称:nova,代码行数:57,代码来源:vmops.py

示例3: spawn

# 需要导入模块: from nova.virt.xenapi.vm_utils import VMHelper [as 别名]
# 或者: from nova.virt.xenapi.vm_utils.VMHelper import determine_disk_image_type [as 别名]
    def spawn(self, instance, disk):
        """Create VM instance"""
        instance_name = instance.name
        vm = VMHelper.lookup(self._session, instance_name)
        if vm is not None:
            raise exception.Duplicate(_('Attempted to create'
            ' non-unique name %s') % instance_name)

        #ensure enough free memory is available
        if not VMHelper.ensure_free_mem(self._session, instance):
            LOG.exception(_('instance %(instance_name)s: not enough free '
                          'memory') % locals())
            db.instance_set_state(context.get_admin_context(),
                                  instance['id'],
                                  power_state.SHUTDOWN)
            return

        user = AuthManager().get_user(instance.user_id)
        project = AuthManager().get_project(instance.project_id)

        vdi_ref = kernel = ramdisk = pv_kernel = None

        # Are we building from a pre-existing disk?
        if not disk:
            #if kernel is not present we must download a raw disk

            disk_image_type = VMHelper.determine_disk_image_type(instance)
            vdi_uuid = VMHelper.fetch_image(self._session, instance.id,
                    instance.image_id, user, project, disk_image_type)
            vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdi_uuid)

        else:
            vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', disk)

        if disk_image_type == ImageType.DISK_RAW:
            # Have a look at the VDI and see if it has a PV kernel
            pv_kernel = VMHelper.lookup_image(self._session, instance.id,
                                              vdi_ref)
        elif disk_image_type == ImageType.DISK_VHD:
            # TODO(sirp): Assuming PV for now; this will need to be
            # configurable as Windows will use HVM.
            pv_kernel = True

        if instance.kernel_id:
            kernel = VMHelper.fetch_image(self._session, instance.id,
                instance.kernel_id, user, project, ImageType.KERNEL_RAMDISK)

        if instance.ramdisk_id:
            ramdisk = VMHelper.fetch_image(self._session, instance.id,
                instance.ramdisk_id, user, project, ImageType.KERNEL_RAMDISK)

        vm_ref = VMHelper.create_vm(self._session,
                                          instance, kernel, ramdisk, pv_kernel)
        VMHelper.create_vbd(session=self._session, vm_ref=vm_ref,
                vdi_ref=vdi_ref, userdevice=0, bootable=True)

        # inject_network_info and create vifs
        networks = self.inject_network_info(instance)
        self.create_vifs(instance, networks)

        LOG.debug(_('Starting VM %s...'), vm_ref)
        self._start(instance, vm_ref)
        LOG.info(_('Spawning VM %(instance_name)s created %(vm_ref)s.')
                 % locals())

        def _inject_onset_files():
            onset_files = instance.onset_files
            if onset_files:
                # Check if this is a JSON-encoded string and convert if needed.
                if isinstance(onset_files, basestring):
                    try:
                        onset_files = json.loads(onset_files)
                    except ValueError:
                        LOG.exception(_("Invalid value for onset_files: '%s'")
                                % onset_files)
                        onset_files = []
                # Inject any files, if specified
                for path, contents in instance.onset_files:
                    LOG.debug(_("Injecting file path: '%s'") % path)
                    self.inject_file(instance, path, contents)
        # NOTE(armando): Do we really need to do this in virt?
        # NOTE(tr3buchet): not sure but wherever we do it, we need to call
        #                  reset_network afterwards
        timer = utils.LoopingCall(f=None)

        def _wait_for_boot():
            try:
                state = self.get_info(instance_name)['state']
                db.instance_set_state(context.get_admin_context(),
                                      instance['id'], state)
                if state == power_state.RUNNING:
                    LOG.debug(_('Instance %s: booted'), instance_name)
                    timer.stop()
                    _inject_onset_files()
                    return True
            except Exception, exc:
                LOG.warn(exc)
                LOG.exception(_('instance %s: failed to boot'),
                              instance_name)
                db.instance_set_state(context.get_admin_context(),
#.........这里部分代码省略.........
开发者ID:yosh,项目名称:nova,代码行数:103,代码来源:vmops.py


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