'Acquire console information for an instance.
If the console is enabled, the console will be re-enabled
before returning.
:param instance: nova instance
:return: a dictionary with below values
{ \'node\': ironic node
\'console_info\': node console info }
:raise ConsoleNotAvailable: if console is unavailable
for the instance'

def _get_node_console_with_reset(self, instance):

    node = self._validate_instance_and_node(instance)
    node_uuid = node.uuid
    def _get_console():
        'Request    ironicclient    to    acquire    node    console.'
        try:
            return self.ironicclient.call('node.get_console', node_uuid)
        except (exception.NovaException, ironic.exc.InternalServerError, ironic.exc.BadRequest) as e:
            LOG.error('Failed    to    acquire    console    information    for    instance    %(inst)s:    %(reason)s', {'inst': instance.uuid, 'reason': e})
            raise exception.ConsoleNotAvailable()
    def _wait_state(state):
        'Wait    for    the    expected    console    mode    to    be    set    on    node.'
        console = _get_console()
        if (console['console_enabled'] == state):
            raise loopingcall.LoopingCallDone(retvalue=console)
        _log_ironic_polling('set    console    mode', node, instance)
        return False
    def _enable_console(mode):
        'Request    ironicclient    to    enable/disable    node    console.'
        try:
            self.ironicclient.call('node.set_console_mode', node_uuid, mode)
        except (exception.NovaException, ironic.exc.InternalServerError, ironic.exc.BadRequest) as e:
            LOG.error('Failed    to    set    console    mode    to    "%(mode)s"    for    instance    %(inst)s:    %(reason)s', {'mode': mode, 'inst': instance.uuid, 'reason': e})
            raise exception.ConsoleNotAvailable()
        try:
            timer = loopingcall.BackOffLoopingCall(_wait_state, state=mode)
            return timer.start(starting_interval=_CONSOLE_STATE_CHECKING_INTERVAL, timeout=CONF.ironic.serial_console_state_timeout, jitter=0.5).wait()
        except loopingcall.LoopingCallTimeOut:
            LOG.error('Timeout    while    waiting    for    console    mode    to    be    set    to    "%(mode)s"    on    node    %(node)s', {'mode': mode, 'node': node_uuid})
            raise exception.ConsoleNotAvailable()
    console = _get_console()
    if console['console_enabled']:
        try:
            _enable_console(False)
            console = _enable_console(True)
        except exception.ConsoleNotAvailable:
            console = _enable_console(True)
    if console['console_enabled']:
        return {'node': node, 'console_info': console['console_info']}
    else:
        LOG.debug('Console    is    disabled    for    instance    %s', instance.uuid)
        raise exception.ConsoleNotAvailable()
