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


Python vm_utils.VMHelper类代码示例

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


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

示例1: snapshot

    def snapshot(self, instance, image_id):
        """Create snapshot from a running VM instance

        :param instance: instance to be snapshotted
        :param image_id: id of image to upload to

        Steps involved in a XenServer snapshot:

        1. XAPI-Snapshot: Snapshotting the instance using XenAPI. This
            creates: Snapshot (Template) VM, Snapshot VBD, Snapshot VDI,
            Snapshot VHD

        2. Wait-for-coalesce: The Snapshot VDI and Instance VDI both point to
            a 'base-copy' VDI.  The base_copy is immutable and may be chained
            with other base_copies.  If chained, the base_copies
            coalesce together, so, we must wait for this coalescing to occur to
            get a stable representation of the data on disk.

        3. Push-to-glance: Once coalesced, we call a plugin on the XenServer
            that will bundle the VHDs together and then push the bundle into
            Glance.
        """
        template_vm_ref = None
        try:
            template_vm_ref, template_vdi_uuids = self._get_snapshot(instance)
            # call plugin to ship snapshot off to glance
            VMHelper.upload_image(
                    self._session, instance, template_vdi_uuids, image_id)
        finally:
            if template_vm_ref:
                self._destroy(instance, template_vm_ref,
                        shutdown=False, destroy_kernel_ramdisk=False)

        logging.debug(_("Finished snapshot and upload for VM %s"), instance)
开发者ID:pombredanne,项目名称:nova,代码行数:34,代码来源:vmops.py

示例2: rescue

    def rescue(self, instance, callback):
        """Rescue the specified instance
            - shutdown the instance VM
            - set 'bootlock' to prevent the instance from starting in rescue
            - spawn a rescue VM (the vm name-label will be instance-N-rescue)

        """
        rescue_vm_ref = VMHelper.lookup(self._session,
                                        instance.name + "-rescue")
        if rescue_vm_ref:
            raise RuntimeError(_(
                "Instance is already in Rescue Mode: %s" % instance.name))

        vm_ref = self._get_vm_opaque_ref(instance)
        self._shutdown(instance, vm_ref)
        self._acquire_bootlock(vm_ref)

        instance._rescue = True
        self.spawn(instance)
        rescue_vm_ref = self._get_vm_opaque_ref(instance)

        vbd_ref = self._session.get_xenapi().VM.get_VBDs(vm_ref)[0]
        vdi_ref = self._session.get_xenapi().VBD.get_record(vbd_ref)["VDI"]
        rescue_vbd_ref = VMHelper.create_vbd(self._session, rescue_vm_ref,
                                             vdi_ref, 1, False)

        self._session.call_xenapi("Async.VBD.plug", rescue_vbd_ref)
开发者ID:pombredanne,项目名称:nova,代码行数:27,代码来源:vmops.py

示例3: _create_disk

 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,代码行数:7,代码来源:vmops.py

示例4: create_vifs

    def create_vifs(self, instance, networks=None):
        """
        Creates vifs for an instance

        """
        vm_opaque_ref = self._get_vm_opaque_ref(instance.id)
        logging.debug(_("creating vif(s) for vm: |%s|"), vm_opaque_ref)
        if networks is None:
            networks = db.network_get_all_by_instance(admin_context,
                                                      instance['id'])
        # TODO(tr3buchet) - remove comment in multi-nic
        # this bit here about creating the vifs will be updated
        # in multi-nic to handle multiple IPs on the same network
        # and multiple networks
        # for now it works as there is only one of each
        for network in networks:
            bridge = network['bridge']
            network_ref = \
                NetworkHelper.find_network_with_bridge(self._session, bridge)

            if network_ref:
                try:
                    device = "1" if instance._rescue else "0"
                except AttributeError:
                    device = "0"

                VMHelper.create_vif(
                    self._session,
                    vm_opaque_ref,
                    network_ref,
                    instance.mac_address,
                    device)
开发者ID:yosh,项目名称:nova,代码行数:32,代码来源:vmops.py

示例5: _destroy_rescue_vbds

 def _destroy_rescue_vbds(self, rescue_vm_ref):
     """Destroys all VBDs tied to a rescue VM."""
     vbd_refs = self._session.get_xenapi().VM.get_VBDs(rescue_vm_ref)
     for vbd_ref in vbd_refs:
         vbd_rec = self._session.get_xenapi().VBD.get_record(vbd_ref)
         if vbd_rec.get("userdevice", None) == "1":  # VBD is always 1
             VMHelper.unplug_vbd(self._session, vbd_ref)
             VMHelper.destroy_vbd(self._session, vbd_ref)
开发者ID:superstack,项目名称:nova,代码行数:8,代码来源:vmops.py

示例6: migrate_disk_and_power_off

    def migrate_disk_and_power_off(self, instance, dest):
        """Copies a VHD from one host machine to another.

        :param instance: the instance that owns the VHD in question.
        :param dest: the destination host machine.
        :param disk_type: values are 'primary' or 'cow'.

        """
        vm_ref = VMHelper.lookup(self._session, instance.name)

        # The primary VDI becomes the COW after the snapshot, and we can
        # identify it via the VBD. The base copy is the parent_uuid returned
        # from the snapshot creation

        base_copy_uuid = cow_uuid = None
        template_vdi_uuids = template_vm_ref = None
        try:
            # transfer the base copy
            template_vm_ref, template_vdi_uuids = self._get_snapshot(instance)
            base_copy_uuid = template_vdi_uuids['image']
            vdi_ref, vm_vdi_rec = \
                    VMHelper.get_vdi_for_vm_safely(self._session, vm_ref)
            cow_uuid = vm_vdi_rec['uuid']

            params = {'host': dest,
                      'vdi_uuid': base_copy_uuid,
                      'instance_id': instance.id,
                      'sr_path': VMHelper.get_sr_path(self._session)}

            task = self._session.async_call_plugin('migration', 'transfer_vhd',
                    {'params': pickle.dumps(params)})
            self._session.wait_for_task(task, instance.id)

            # Now power down the instance and transfer the COW VHD
            self._shutdown(instance, vm_ref, hard=False)

            params = {'host': dest,
                      'vdi_uuid': cow_uuid,
                      'instance_id': instance.id,
                      'sr_path': VMHelper.get_sr_path(self._session), }

            task = self._session.async_call_plugin('migration', 'transfer_vhd',
                    {'params': pickle.dumps(params)})
            self._session.wait_for_task(task, instance.id)

        finally:
            if template_vm_ref:
                self._destroy(instance, template_vm_ref,
                        shutdown=False, destroy_kernel_ramdisk=False)

        # TODO(mdietz): we could also consider renaming these to something
        # sensible so we don't need to blindly pass around dictionaries
        return {'base_copy': base_copy_uuid, 'cow': cow_uuid}
开发者ID:superstack,项目名称:nova,代码行数:53,代码来源:vmops.py

示例7: detach_volume

 def detach_volume(self, instance_name, mountpoint):
     """Detach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.InstanceNotFound(instance_id=instance_name)
     # Detach VBD from VM
     LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
     device_number = VolumeHelper.mountpoint_to_number(mountpoint)
     try:
         vbd_ref = VMHelper.find_vbd_by_number(self._session, vm_ref, device_number)
     except StorageError, exc:
         LOG.exception(exc)
         raise Exception(_("Unable to locate volume %s") % mountpoint)
开发者ID:rackerlabs,项目名称:reddwarf,代码行数:14,代码来源:volumeops.py

示例8: _inject_network_info

    def _inject_network_info(self, instance, network_info, vm_ref=None):
        """
        Generate the network info and make calls to place it into the
        xenstore and the xenstore param list.
        vm_ref can be passed in because it will sometimes be different than
        what VMHelper.lookup(session, instance.name) will find (ex: rescue)
        """
        logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref)

        if vm_ref:
            # this function raises if vm_ref is not a vm_opaque_ref
            self._session.get_xenapi().VM.get_record(vm_ref)
        else:
            vm_ref = VMHelper.lookup(self._session, instance.name)

        for (network, info) in network_info:
            location = 'vm-data/networking/%s' % info['mac'].replace(':', '')
            self.write_to_param_xenstore(vm_ref, {location: info})
            try:
                # TODO(tr3buchet): fix function call after refactor
                #self.write_to_xenstore(vm_ref, location, info)
                self._make_plugin_call('xenstore.py', 'write_record', instance,
                                       location, {'value': json.dumps(info)},
                                       vm_ref)
            except KeyError:
                # catch KeyError for domid if instance isn't running
                pass
开发者ID:superstack,项目名称:nova,代码行数:27,代码来源:vmops.py

示例9: plug

    def plug(self, instance, network, mapping, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = VMHelper.lookup(self._session, instance.name)
        if not device:
            device = 0

        if mapping.get('should_create_vlan'):
            network_ref = self._ensure_vlan_bridge(network)
        else:
            network_ref = NetworkHelper.find_network_with_bridge(
                                        self._session, network['bridge'])
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = mapping['mac']
        vif_rec['MTU'] = '1500'
        vif_rec['other_config'] = {}
        if "rxtx_cap" in mapping:
            vif_rec['qos_algorithm_type'] = "ratelimit"
            vif_rec['qos_algorithm_params'] = \
                {"kbps": str(mapping['rxtx_cap'] * 1024)}
        else:
            vif_rec['qos_algorithm_type'] = ""
            vif_rec['qos_algorithm_params'] = {}
        return vif_rec
开发者ID:KarimAllah,项目名称:nova,代码行数:26,代码来源:vif.py

示例10: _get_vm_opaque_ref

    def _get_vm_opaque_ref(self, instance_or_vm):
        """
        Refactored out the common code of many methods that receive either
        a vm name or a vm instance, and want a vm instance in return.
        """
        # if instance_or_vm is a string it must be opaque ref or instance name
        if isinstance(instance_or_vm, basestring):
            obj = None
            try:
                # check for opaque ref
                obj = self._session.get_xenapi().VM.get_uuid(instance_or_vm)
                return instance_or_vm
            except self.XenAPI.Failure:
                # wasn't an opaque ref, can be an instance name
                instance_name = instance_or_vm

        # if instance_or_vm is an int/long it must be instance id
        elif isinstance(instance_or_vm, (int, long)):
            ctx = context.get_admin_context()
            instance_obj = db.instance_get(ctx, instance_or_vm)
            instance_name = instance_obj.name
        else:
            instance_name = instance_or_vm.name
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_obj.id)
        return vm_ref
开发者ID:superstack,项目名称:nova,代码行数:27,代码来源:vmops.py

示例11: create_vifs

    def create_vifs(self, vm_ref, network_info):
        """Creates vifs for an instance"""
        logging.debug(_("creating vif(s) for vm: |%s|"), vm_ref)

        # this function raises if vm_ref is not a vm_opaque_ref
        self._session.get_xenapi().VM.get_record(vm_ref)

        for device, (network, info) in enumerate(network_info):
            mac_address = info['mac']
            bridge = network['bridge']
            rxtx_cap = info.pop('rxtx_cap')
            network_ref = \
                NetworkHelper.find_network_with_bridge(self._session, bridge)

            VMHelper.create_vif(self._session, vm_ref, network_ref,
                                mac_address, device, rxtx_cap)
开发者ID:pombredanne,项目名称:nova,代码行数:16,代码来源:vmops.py

示例12: attach_volume

 def attach_volume(self, instance_name, device_path, mountpoint):
     """Attach volume storage to VM instance"""
     # Before we start, check that the VM exists
     vm_ref = VMHelper.lookup(self._session, instance_name)
     if vm_ref is None:
         raise exception.NotFound(_('Instance %s not found')
                                   % instance_name)
     # NOTE: No Resource Pool concept so far
     LOG.debug(_("Attach_volume: %(instance_name)s, %(device_path)s,"
             " %(mountpoint)s") % locals())
     # Create the iSCSI SR, and the PDB through which hosts access SRs.
     # But first, retrieve target info, like Host, IQN, LUN and SCSIID
     vol_rec = VolumeHelper.parse_volume_info(device_path, mountpoint)
     label = 'SR-%s' % vol_rec['volumeId']
     description = 'Disk-for:%s' % instance_name
     # Create SR
     sr_ref = VolumeHelper.create_iscsi_storage(self._session,
                                                      vol_rec,
                                                      label,
                                                      description)
     # Introduce VDI  and attach VBD to VM
     try:
         vdi_ref = VolumeHelper.introduce_vdi(self._session, sr_ref)
     except StorageError, exc:
         LOG.exception(exc)
         VolumeHelper.destroy_iscsi_storage(self._session, sr_ref)
         raise Exception(_('Unable to create VDI on SR %(sr_ref)s for'
                 ' instance %(instance_name)s') % locals())
开发者ID:pombredanne,项目名称:nova,代码行数:28,代码来源:volumeops.py

示例13: _get_vm_opaque_ref

 def _get_vm_opaque_ref(self, instance_or_vm):
     """Refactored out the common code of many methods that receive either
     a vm name or a vm instance, and want a vm instance in return.
     """
     vm = None
     try:
         if instance_or_vm.startswith("OpaqueRef:"):
             # Got passed an opaque ref; return it
             return instance_or_vm
         else:
             # Must be the instance name
             instance_name = instance_or_vm
     except (AttributeError, KeyError):
         # Note the the KeyError will only happen with fakes.py
         # Not a string; must be an ID or a vm instance
         if isinstance(instance_or_vm, (int, long)):
             ctx = context.get_admin_context()
             try:
                 instance_obj = db.instance_get(ctx, instance_or_vm)
                 instance_name = instance_obj.name
             except exception.NotFound:
                 # The unit tests screw this up, as they use an integer for
                 # the vm name. I'd fix that up, but that's a matter for
                 # another bug report. So for now, just try with the passed
                 # value
                 instance_name = instance_or_vm
         else:
             instance_name = instance_or_vm.name
     vm = VMHelper.lookup(self._session, instance_name)
     if vm is None:
         raise exception.NotFound(
                         _('Instance not present %s') % instance_name)
     return vm
开发者ID:anotherjesse,项目名称:nova,代码行数:33,代码来源:vmops.py

示例14: _get_snapshot

    def _get_snapshot(self, instance):
        #TODO(sirp): Add quiesce and VSS locking support when Windows support
        # is added

        logging.debug(_("Starting snapshot for VM %s"), instance)
        vm_ref = VMHelper.lookup(self._session, instance.name)

        label = "%s-snapshot" % instance.name
        try:
            template_vm_ref, template_vdi_uuids = VMHelper.create_snapshot(
                self._session, instance.id, vm_ref, label)
            return template_vm_ref, template_vdi_uuids
        except self.XenAPI.Failure, exc:
            logging.error(_("Unable to Snapshot %(vm_ref)s: %(exc)s")
                    % locals())
            return
开发者ID:pombredanne,项目名称:nova,代码行数:16,代码来源:vmops.py

示例15: _destroy_rescue_vdis

 def _destroy_rescue_vdis(self, rescue_vm_ref):
     """Destroys all VDIs associated with a rescued VM."""
     vdi_refs = VMHelper.lookup_vm_vdis(self._session, rescue_vm_ref)
     for vdi_ref in vdi_refs:
         try:
             self._session.call_xenapi("Async.VDI.destroy", vdi_ref)
         except self.XenAPI.Failure:
             continue
开发者ID:superstack,项目名称:nova,代码行数:8,代码来源:vmops.py


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