'Detach a volume from an instance.'

@check_instance_lock
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.PAUSED, vm_states.STOPPED, vm_states.RESIZED, vm_states.SOFT_DELETED, vm_states.SHELVED, vm_states.SHELVED_OFFLOADED])
def detach_volume(self, context, instance, volume):

    if (instance.vm_state == vm_states.SHELVED_OFFLOADED):
        self._detach_volume_shelved_offloaded(context, instance, volume)
    else:
        self._detach_volume(context, instance, volume)
