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()
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()
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()
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()
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)
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())
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())
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)
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 })
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)
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()
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()
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()
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()
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)
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)
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'))
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'))
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())
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})
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())
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())
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())
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}, )