'Attach an existing volume to an existing 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 attach_volume(self, context, instance, volume_id, device=None, disk_bus=None, device_type=None, tag=None):

    if (device and (not block_device.match_device(device))):
        raise exception.InvalidDevicePath(path=device)
    is_shelved_offloaded = (instance.vm_state == vm_states.SHELVED_OFFLOADED)
    if is_shelved_offloaded:
        if tag:
            raise exception.VolumeTaggedAttachToShelvedNotSupported()
        return self._attach_volume_shelved_offloaded(context, instance, volume_id, device, disk_bus, device_type)
    return self._attach_volume(context, instance, volume_id, device, disk_bus, device_type, tag=tag)
