Ejemplo n.º 1
0
    def get_console_output(self, userid):
        def append_to_log(log_data, log_path):
            LOG.debug('log_data: %(log_data)r, log_path: %(log_path)r',
                         {'log_data': log_data, 'log_path': log_path})
            with open(log_path, 'a+') as fp:
                fp.write(log_data)

            return log_path

        LOG.info("Begin to capture console log on vm %s", userid)
        log_size = CONF.guest.console_log_size * 1024
        console_log = self._smutclient.get_user_console_output(userid)

        log_path = self._pathutils.get_console_log_path(userid)
        # TODO: need consider shrink log file size
        append_to_log(console_log, log_path)

        log_fp = file(log_path, 'rb')
        try:
            log_data, remaining = zvmutils.last_bytes(log_fp, log_size)
        except Exception as err:
            msg = ("Failed to truncate console log, error: %s" %
                   six.text_type(err))
            LOG.error(msg)
            raise exception.SDKInternalError(msg)

        if remaining > 0:
            LOG.info('Truncated console log returned, %d bytes ignored' %
                     remaining)

        LOG.info("Complete get console output on vm %s", userid)
        return log_data
Ejemplo n.º 2
0
    def get_console_output(self, userid):
        def append_to_log(log_data, log_path):
            LOG.debug('log_data: %(log_data)r, log_path: %(log_path)r',
                         {'log_data': log_data, 'log_path': log_path})
            fp = open(log_path, 'a+')
            fp.write(log_data)
            fp.close()
            return log_path

        log_size = CONF.guest.console_log_size * 1024
        console_log = ""

        try:
            console_log = self._zvmclient.get_user_console_output(userid,
                                                                  log_size)
        except exception.ZVMClientInternalError:
            # Ignore no console log avaiable error
            LOG.info("No new console log avaiable.")

        log_path = self._pathutils.get_console_log_path(CONF.zvm.host, userid)
        # TODO: need consider shrink log file size
        append_to_log(console_log, log_path)

        log_fp = file(log_path, 'rb')
        log_data, remaining = zvmutils.last_bytes(log_fp, log_size)
        if remaining > 0:
            LOG.info('Truncated console log returned, %d bytes ignored' %
                     remaining)
        return log_data