summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2012-11-21 21:43:12 +1100
committerMichael Still <michael.still@canonical.com>2012-11-23 07:09:53 +1100
commitfc4f4bd09a0ef3a65514c5dc733c7b2fd6ac7ead (patch)
tree2bded36ce01d5b8a94724f46b113d5f9260e8c4c /nova/utils.py
parent2d6abe49c35ab5c6200164455631a259eefe7457 (diff)
Truncate large console logs in libvirt.
Resolves bug 1081436 where they were returning a 5.5gb console log to the user. Change-Id: I0d98c83e801f8936d35789b5e8f8283f49483c4e
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 464629d95..c94cd2c3e 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -1180,3 +1180,24 @@ def mkfs(fs, path, label=None):
args.extend([label_opt, label])
args.append(path)
execute(*args)
+
+
+def last_bytes(file_like_object, num):
+ """Return num bytes from the end of the file, and remaining byte count.
+
+ :param file_like_object: The file to read
+ :param num: The number of bytes to return
+
+ :returns (data, remaining)
+ """
+
+ try:
+ file_like_object.seek(-num, os.SEEK_END)
+ except IOError, e:
+ if e.errno == 22:
+ file_like_object.seek(0, os.SEEK_SET)
+ else:
+ raise
+
+ remaining = file_like_object.tell()
+ return (file_like_object.read(), remaining)