'Get text console output.'

@extensions.expected_errors((404, 409, 501))
@wsgi.action('os-getConsoleOutput')
@validation.schema(console_output.get_console_output)
def get_console_output(self, req, id, body):

    context = req.environ['nova.context']
    context.can(co_policies.BASE_POLICY_NAME)
    instance = common.get_instance(self.compute_api, context, id)
    length = body['os-getConsoleOutput'].get('length')
    try:
        output = self.compute_api.get_console_output(context, instance, length)
    except (exception.InstanceNotFound, exception.ConsoleNotAvailable) as e:
        raise webob.exc.HTTPNotFound(explanation=e.format_message())
    except exception.InstanceNotReady as e:
        raise webob.exc.HTTPConflict(explanation=e.format_message())
    except NotImplementedError:
        common.raise_feature_not_supported()
    remove_re = re.compile('[\x00-\x08\x0b-\x1f]')
    output = remove_re.sub('', output)
    return {'output': output}
