Example #1
0
    def test_lookup_call(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup("session", "somename").AndReturn("ignored")

        mock.ReplayAll()
        vm_utils.vm_ref_or_raise("session", "somename")
        mock.VerifyAll()
Example #2
0
    def test_lookup_call(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn('ignored')

        mock.ReplayAll()
        vm_utils.vm_ref_or_raise('session', 'somename')
        mock.VerifyAll()
Example #3
0
    def test_lookup_call(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn('ignored')

        mock.ReplayAll()
        vm_utils.vm_ref_or_raise('session', 'somename')
        mock.VerifyAll()
Example #4
0
    def test_exception_msg_contains_vm_name(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn(None)

        mock.ReplayAll()
        try:
            vm_utils.vm_ref_or_raise('session', 'somename')
        except exception.InstanceNotFound as e:
            self.assertTrue('somename' in str(e))
        mock.VerifyAll()
Example #5
0
    def test_exception_msg_contains_vm_name(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup("session", "somename").AndReturn(None)

        mock.ReplayAll()
        try:
            vm_utils.vm_ref_or_raise("session", "somename")
        except exception.InstanceNotFound as e:
            self.assertTrue("somename" in str(e))
        mock.VerifyAll()
Example #6
0
    def attach_volume(self, connection_info, instance_name, mountpoint, hotplug=True):
        """Attach volume to VM instance."""
        # TODO(johngarbutt) move this into _attach_volume_to_vm
        dev_number = volume_utils.get_device_number(mountpoint)

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
        return self._attach_volume(connection_info, vm_ref, instance_name, dev_number, hotplug)
Example #7
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(
            _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())

        device_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)
        except volume_utils.StorageError:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warn(
                _('Skipping detach because VBD for %(instance_name)s was'
                  ' not found') % locals())
            return

        # Unplug VBD if we're NOT shutdown
        unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref)
        self._detach_vbd(vbd_ref, unplug=unplug)

        LOG.info(
            _('Mountpoint %(mountpoint)s detached from instance'
              ' %(instance_name)s') % locals())
Example #8
0
    def attach_volume(self,
                      connection_info,
                      instance_name,
                      mountpoint,
                      hotplug=True):
        """Attach volume storage to VM instance."""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # NOTE: No Resource Pool concept so far
        LOG.debug(
            _("Attach_volume: %(connection_info)s, %(instance_name)s,"
              " %(mountpoint)s") % locals())

        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        self._connect_volume(connection_data,
                             dev_number,
                             instance_name,
                             vm_ref,
                             hotplug=hotplug)

        LOG.info(
            _('Mountpoint %(mountpoint)s attached to'
              ' instance %(instance_name)s') % locals())
Example #9
0
    def attach_volume(self, connection_info, instance_name, mountpoint,
                      hotplug=True):
        """
        Attach volume storage to VM instance.
        """

        # NOTE: No Resource Pool concept so far
        LOG.debug(_('Attach_volume: %(connection_info)s, %(instance_name)s,'
                    '" %(mountpoint)s'),
                  {'connection_info': connection_info,
                   'instance_name': instance_name,
                   'mountpoint': mountpoint})

        dev_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        sr_uuid, vdi_uuid = self._connect_volume(connection_info, dev_number,
                                                 instance_name, vm_ref,
                                                 hotplug=hotplug)

        LOG.info(_('Mountpoint %(mountpoint)s attached to'
                   ' instance %(instance_name)s'),
                 {'instance_name': instance_name, 'mountpoint': mountpoint})

        return (sr_uuid, vdi_uuid)
Example #10
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug("Detach_volume: %(instance_name)s, %(mountpoint)s", {
            'instance_name': instance_name,
            'mountpoint': mountpoint
        })

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        device_number = volume_utils.get_device_number(mountpoint)
        vbd_ref = volume_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)

        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warning(
                _LW('Skipping detach because VBD for %s was '
                    'not found'), instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(
                _LI('Mountpoint %(mountpoint)s detached from instance'
                    ' %(instance_name)s'), {
                        'instance_name': instance_name,
                        'mountpoint': mountpoint
                    })
Example #11
0
    def attach_volume(self, connection_info, instance_name, mountpoint,
                      hotplug=True):
        """Attach volume to VM instance."""
        # TODO(johngarbutt) move this into _attach_volume_to_vm
        dev_number = volume_utils.get_device_number(mountpoint)

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
        return self._attach_volume(connection_info, vm_ref,
                                   instance_name, dev_number, hotplug)
Example #12
0
 def attach_volume(self,
                   connection_info,
                   instance_name,
                   mountpoint,
                   hotplug=True):
     """Attach volume to VM instance."""
     vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
     return self._attach_volume(connection_info, vm_ref, instance_name,
                                mountpoint, hotplug)
Example #13
0
    def test_exception_raised(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup("session", "somename").AndReturn(None)

        mock.ReplayAll()
        self.assertRaises(exception.InstanceNotFound, lambda: vm_utils.vm_ref_or_raise("session", "somename"))
        mock.VerifyAll()
Example #14
0
    def test_return_value(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn("vmref")

        mock.ReplayAll()
        self.assertEquals("vmref", vm_utils.vm_ref_or_raise("session", "somename"))
        mock.VerifyAll()
Example #15
0
    def test_return_value(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn('vmref')

        mock.ReplayAll()
        self.assertEquals(
            'vmref', vm_utils.vm_ref_or_raise('session', 'somename'))
        mock.VerifyAll()
Example #16
0
    def test_return_value(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn('vmref')

        mock.ReplayAll()
        self.assertEquals(
            'vmref', vm_utils.vm_ref_or_raise('session', 'somename'))
        mock.VerifyAll()
Example #17
0
    def test_exception_raised(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn(None)

        mock.ReplayAll()
        self.assertRaises(
            exception.InstanceNotFound,
            lambda: vm_utils.vm_ref_or_raise('session', 'somename'))
        mock.VerifyAll()
Example #18
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # Detach VBD from VM
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
        device_number = volume_utils.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            raise Exception(_("Unable to locate volume %s") % mountpoint)
Example #19
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # Detach VBD from VM
        LOG.debug(
            _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
        device_number = volume_utils.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to locate volume %s') % mountpoint)
Example #20
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # NOTE: No Resource Pool concept so far
        LOG.debug(
            _("Attach_volume: %(connection_info)s, %(instance_name)s,"
              " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        if 'name_label' not in connection_data:
            label = 'tempSR-%s' % connection_data['volume_id']
        else:
            label = connection_data['name_label']
            del connection_data['name_label']

        if 'name_description' not in connection_data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = connection_data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in connection_data:
            sr_params = volume_utils.parse_volume_info(connection_data)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = connection_data['sr_uuid']
            for k in connection_data['introduce_sr_keys']:
                sr_params[k] = connection_data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise volume_utils.StorageError(
                _('Unable to introduce Storage Repository'))
Example #21
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # NOTE: No Resource Pool concept so far
        LOG.debug(_("Attach_volume: %(connection_info)s, %(instance_name)s,"
                " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        if 'name_label' not in connection_data:
            label = 'tempSR-%s' % connection_data['volume_id']
        else:
            label = connection_data['name_label']
            del connection_data['name_label']

        if 'name_description' not in connection_data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = connection_data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in connection_data:
            sr_params = volume_utils.parse_volume_info(connection_data)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = connection_data['sr_uuid']
            for k in connection_data['introduce_sr_keys']:
                sr_params[k] = connection_data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise volume_utils.StorageError(
                                _('Unable to introduce Storage Repository'))
Example #22
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s")
                % locals())

        device_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        vbd_ref = vm_utils.find_vbd_by_number(
                self._session, vm_ref, device_number)

        # Unplug VBD if we're NOT shutdown
        unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref)
        self._detach_vbd(vbd_ref, unplug=unplug)

        LOG.info(_('Mountpoint %(mountpoint)s detached from instance'
                   ' %(instance_name)s') % locals())
Example #23
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s"),
                  {'instance_name': instance_name, 'mountpoint': mountpoint})

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
        vbd_ref = self._find_vbd(vm_ref, mountpoint)
        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warn(_('Skipping detach because VBD for %s was not found'),
                     instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(_('Mountpoint %(mountpoint)s detached from instance'
                       ' %(instance_name)s'),
                     {'instance_name': instance_name,
                      'mountpoint': mountpoint})
Example #24
0
    def attach_volume(self, connection_info, instance_name, mountpoint, hotplug=True):
        """Attach volume storage to VM instance."""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # NOTE: No Resource Pool concept so far
        LOG.debug(_("Attach_volume: %(connection_info)s, %(instance_name)s," " %(mountpoint)s") % locals())

        driver_type = connection_info["driver_volume_type"]
        if driver_type not in ["iscsi", "xensm"]:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info["data"]
        dev_number = volume_utils.get_device_number(mountpoint)

        self._connect_volume(connection_data, dev_number, instance_name, vm_ref, hotplug=hotplug)

        LOG.info(_("Mountpoint %(mountpoint)s attached to" " instance %(instance_name)s") % locals())
Example #25
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())

        device_number = volume_utils.get_device_number(mountpoint)
        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        try:
            vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number)
        except volume_utils.StorageError:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warn(_("Skipping detach because VBD for %(instance_name)s was" " not found") % locals())
            return

        # Unplug VBD if we're NOT shutdown
        unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref)
        self._detach_vbd(vbd_ref, unplug=unplug)

        LOG.info(_("Mountpoint %(mountpoint)s detached from instance" " %(instance_name)s") % locals())
Example #26
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # NOTE: No Resource Pool concept so far
        LOG.debug(_("Attach_volume: %(connection_info)s, %(instance_name)s,"
                " %(mountpoint)s") % locals())

        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        self.connect_volume(
            connection_data, dev_number, instance_name, vm_ref)

        LOG.info(_('Mountpoint %(mountpoint)s attached to'
                ' instance %(instance_name)s') % locals())
Example #27
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug(
            "Detach_volume: %(instance_name)s, %(mountpoint)s",
            {"instance_name": instance_name, "mountpoint": mountpoint},
        )

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        device_number = volume_utils.get_device_number(mountpoint)
        vbd_ref = volume_utils.find_vbd_by_number(self._session, vm_ref, device_number)

        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warn(_("Skipping detach because VBD for %s was not found"), instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(
                _("Mountpoint %(mountpoint)s detached from instance" " %(instance_name)s"),
                {"instance_name": instance_name, "mountpoint": mountpoint},
            )
Example #28
0
 def attach_volume(self, connection_info, instance_name, mountpoint,
                   hotplug=True):
     """Attach volume to VM instance."""
     vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)
     return self._attach_volume(connection_info, vm_ref,
                                instance_name, mountpoint, hotplug)