~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to plugins/xenserver/xenapi/etc/xapi.d/plugins/console

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, James Page, Chuck Short
  • Date: 2013-07-19 09:15:03 UTC
  • mfrom: (1.1.73)
  • Revision ID: package-import@ubuntu.com-20130719091503-3khzpejd61moi5pf
Tags: 1:2013.2~b2-0ubuntu1
[ Adam Gandelman ]
* d/patches/requirements_drop_requests_vers_cap.patch: Remove
  upper version limit  on requests dependency, which was capped upstream
  to fix centos-related gating issues.
* debian/control:
  - Set version requirement python-kombu (>= 2.5.12).
  - Set version requirement python-pyparsing (>= 1.5.6).
  - Add websockify to nova-spiceproxy Depends.
  - Add spice-html5 to nova-spiceproxy Depends (LP: #1197119)
* Add nova-xvpvncproxy upstart (LP: #1197163)

[ James Page ]
* d/control: Update VCS fields for new branch locations. 

[ Chuck Short ]
* New upstream release.
* debian/patches/fix-requirements.patch: Combined several 
  patches into one.
* debian/control: Replace python-quantumclient with python-neutronclient.
* debian/patches/fix-sqlalchemy-0.7.9-usage.patch: Temporary patch to address a FTBFS
  with sqlalchemy 0.7.9.
* debian/patches/avoid-failing-test.patch: Skip failing test on buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
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
 
5
#
 
6
#         http://www.apache.org/licenses/LICENSE-2.0
 
7
#
 
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
 
12
#    under the License.
 
13
 
 
14
"""
 
15
To configure this plugin, you must set the following xenstore key:
 
16
/local/logconsole/@ = "/var/log/xen/guest/console.%d"
 
17
 
 
18
This can be done by running:
 
19
xenstore-write /local/logconsole/@ "/var/log/xen/guest/console.%d"
 
20
 
 
21
WARNING:
 
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>
 
28
"""
 
29
 
 
30
import base64
 
31
import logging
 
32
import os
 
33
import zlib
 
34
 
 
35
import XenAPIPlugin
 
36
 
 
37
import pluginlib_nova
 
38
pluginlib_nova.configure_logging("console")
 
39
 
 
40
CONSOLE_LOG_DIR = '/var/log/xen/guest'
 
41
CONSOLE_LOG_FILE_PATTERN = CONSOLE_LOG_DIR + '/console.%d'
 
42
 
 
43
MAX_CONSOLE_BYTES = 102400
 
44
SEEK_SET = 0
 
45
SEEK_END = 2
 
46
 
 
47
 
 
48
def _last_bytes(file_like_object):
 
49
    try:
 
50
        file_like_object.seek(-MAX_CONSOLE_BYTES, SEEK_END)
 
51
    except IOError, e:
 
52
        if e.errno == 22:
 
53
            file_like_object.seek(0, SEEK_SET)
 
54
        else:
 
55
            raise
 
56
    return file_like_object.read()
 
57
 
 
58
 
 
59
def get_console_log(session, arg_dict):
 
60
    try:
 
61
        raw_dom_id = arg_dict['dom_id']
 
62
    except KeyError:
 
63
        raise pluginlib_nova.PluginError("Missing dom_id")
 
64
    try:
 
65
        dom_id = int(raw_dom_id)
 
66
    except ValueError:
 
67
        raise pluginlib_nova.PluginError("Invalid dom_id")
 
68
 
 
69
    logfile = CONSOLE_LOG_FILE_PATTERN % dom_id
 
70
    try:
 
71
        log_content = pluginlib_nova.with_file(logfile, 'rb', _last_bytes)
 
72
    except IOError, e:
 
73
        msg = "Error reading console: %s" % e
 
74
        logging.debug(msg)
 
75
        raise pluginlib_nova.PluginError(msg)
 
76
    return base64.b64encode(zlib.compress(log_content))
 
77
 
 
78
 
 
79
if __name__ == "__main__":
 
80
    XenAPIPlugin.dispatch({"get_console_log": get_console_log})