2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3
# not use this file except in compliance with the License. You may obtain
4
# a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
# License for the specific language governing permissions and limitations
15
To configure this plugin, you must set the following xenstore key:
16
/local/logconsole/@ = "/var/log/xen/guest/console.%d"
18
This can be done by running:
19
xenstore-write /local/logconsole/@ "/var/log/xen/guest/console.%d"
22
You should ensure appropriate log rotation to ensure
23
guests are not able to consume too much Dom0 disk space,
24
and equally should not be able to stop other guests from logging.
25
Adding and removing the following xenstore key will reopen the log,
26
as will be required after a log rotate:
27
/local/logconsole/<dom_id>
38
pluginlib_nova.configure_logging("console")
40
CONSOLE_LOG_DIR = '/var/log/xen/guest'
41
CONSOLE_LOG_FILE_PATTERN = CONSOLE_LOG_DIR + '/console.%d'
43
MAX_CONSOLE_BYTES = 102400
48
def _last_bytes(file_like_object):
50
file_like_object.seek(-MAX_CONSOLE_BYTES, SEEK_END)
53
file_like_object.seek(0, SEEK_SET)
56
return file_like_object.read()
59
def get_console_log(session, arg_dict):
61
raw_dom_id = arg_dict['dom_id']
63
raise pluginlib_nova.PluginError("Missing dom_id")
65
dom_id = int(raw_dom_id)
67
raise pluginlib_nova.PluginError("Invalid dom_id")
69
logfile = CONSOLE_LOG_FILE_PATTERN % dom_id
71
log_content = pluginlib_nova.with_file(logfile, 'rb', _last_bytes)
73
msg = "Error reading console: %s" % e
75
raise pluginlib_nova.PluginError(msg)
76
return base64.b64encode(zlib.compress(log_content))
79
if __name__ == "__main__":
80
XenAPIPlugin.dispatch({"get_console_log": get_console_log})