'Reboot VM instance.'

def reboot(self, instance, reboot_type, bad_volumes_callback=None):

    vm_ref = self._get_vm_opaque_ref(instance, check_rescue=True)
    try:
        if (reboot_type == 'HARD'):
            self._session.call_xenapi('VM.hard_reboot', vm_ref)
        else:
            self._session.call_xenapi('VM.clean_reboot', vm_ref)
    except self._session.XenAPI.Failure as exc:
        details = exc.details
        if ((details[0] == 'VM_BAD_POWER_STATE') and (details[(-1)] == 'halted')):
            LOG.info('Starting    halted    instance    found    during    reboot', instance=instance)
            self._start(instance, vm_ref=vm_ref, bad_volumes_callback=bad_volumes_callback)
            return
        elif (details[0] == 'SR_BACKEND_FAILURE_46'):
            LOG.warning('Reboot    failed    due    to    bad    volumes,    detaching    bad    volumes    and    starting    halted    instance', instance=instance)
            self._start(instance, vm_ref=vm_ref, bad_volumes_callback=bad_volumes_callback)
            return
        else:
            raise
