Пример #1
0
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, dev_number,
                             hotplug):
        LOG.debug('Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s', {
            'vdi_ref': vdi_ref,
            'vm_ref': vm_ref
        })

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session,
                                      vm_ref,
                                      vdi_ref,
                                      dev_number,
                                      bootable=False,
                                      osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info(
            _LI('Dev %(dev_number)s attached to'
                ' instance %(instance_name)s'), {
                    'instance_name': instance_name,
                    'dev_number': dev_number
                })
Пример #2
0
    def _detach_vbds_and_srs(self, vm_ref, vbd_refs):
        is_vm_shutdown = vm_utils.is_vm_shutdown(self._session, vm_ref)

        for vbd_ref in vbd_refs:
            # find sr before we destroy the vbd
            sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref)

            if not is_vm_shutdown:
                vm_utils.unplug_vbd(self._session, vbd_ref, vm_ref)

            vm_utils.destroy_vbd(self._session, vbd_ref)
            # Forget (i.e. disconnect) SR only if not in use
            volume_utils.purge_sr(self._session, sr_ref)
Пример #3
0
    def _detach_vbds_and_srs(self, vm_ref, vbd_refs):
        is_vm_shutdown = vm_utils.is_vm_shutdown(self._session, vm_ref)

        for vbd_ref in vbd_refs:
            # find sr before we destroy the vbd
            sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref)

            if not is_vm_shutdown:
                vm_utils.unplug_vbd(self._session, vbd_ref, vm_ref)

            vm_utils.destroy_vbd(self._session, vbd_ref)
            # Forget (i.e. disconnect) SR only if not in use
            volume_utils.purge_sr(self._session, sr_ref)
Пример #4
0
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, dev_number,
                             hotplug):
        LOG.debug('Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s',
                  {'vdi_ref': vdi_ref, 'vm_ref': vm_ref})

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref,
                                      dev_number, bootable=False,
                                      osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info(_LI('Dev %(dev_number)s attached to'
                     ' instance %(instance_name)s'),
                 {'instance_name': instance_name, 'dev_number': dev_number})