* accpet connection object and stream flag as parameter in __init__
remove connect function for connction is given in as parameter.
* remove newStream() from each function
create new stream object in __init__.
function also need flags parameter.
* Add 5 new functions
screenshot(self, domain, screen, flags = 0)
download(self, vol, offset, length, flags = 0)
upload(self, vol, offset, length, flags = 0)
recvAll(self, handler, opaque)
sendAll(self, handler, opaque)
for recvAll and sendAll, handler is a user defined function which
write/read data to/from file.
---
lib/streamAPI.py | 75 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 50 insertions(+), 25 deletions(-)
diff --git a/lib/streamAPI.py b/lib/streamAPI.py
index bc7d217..4da57ca 100644
--- a/lib/streamAPI.py
+++ b/lib/streamAPI.py
@@ -38,76 +38,101 @@ append_path(result.group(0))
import exception
class StreamAPI(object):
- def __init__(self, connection):
+ def __init__(self, connection, flag = 0):
self.conn = connection
+ self.stream_obj = self.conn.newStream(flag)
- def abort(self, flag = 0):
+ def abort(self):
try:
- stream_obj = newStream(flag)
- return stream_obj.abort()
+ return self.stream_obj.abort()
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def connect(self, flag = 0):
+ def finish(self):
try:
- stream_obj = newStream(flag)
- return stream_obj.connect()
+ return self.stream_obj.finish()
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def finish(self, flag = 0):
+ def recv(self, nbytes):
try:
- stream_obj = newStream(flag)
- return stream_obj.finish()
+ return self.stream_obj.recv(nbytes)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def recv(self, flag = 0, data, nbytes):
+ def send(self, data):
try:
- stream_obj = newStream(flag)
- return stream_obj.recv(data, nbytes)
+ return self.stream_obj.send(data)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def send(self, flag = 0, data, nbytes):
+ def eventAddCallback(self, cb, opaque):
try:
- stream_obj = newStream(flag)
- return stream_obj.send(data, nbytes)
+ return self.stream_obj.eventAddCallback(cb, opaque)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def eventAddCallback(self, flag = 0, cb, opaque):
+ def eventRemoveCallback(self):
try:
- stream_obj = newStream(flag)
- return stream_obj.eventAddCallback(cb, opaque)
+ return self.stream_obj.eventRemoveCallback()
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def eventRemoveCallback(self, flag = 0):
+ def eventUpdateCallback(self, events):
try:
- stream_obj = newStream(flag)
- return stream_obj.eventRemoveCallback()
+ return self.stream_obj.eventUpdateCallback(events)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
- def eventUpdateCallback(self, flag = 0, events)
+ def screenshot(self, domain, screen, flags = 0):
try:
- stream_obj = newStream(flag)
- return stream_obj.eventUpdateCallback(events)
+ return self.stream_obj.screenshot(domain, screen, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def download(self, vol, offset, length, flags = 0):
+ try:
+ return self.stream_obj.download(vol, offset, length, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def upload(self, vol, offset, length, flags = 0):
+ try:
+ return self.stream_obj.upload(vol, offset, length, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def recvAll(self, handler, opaque):
+ try:
+ return self.stream_obj.recvAll(handler, opaque)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def sendAll(self, handler, opaque):
+ try:
+ return self.stream_obj.sendAll(handler, opaque)
except libvirt.libvirtError, e:
message = e.get_error_message()
code = e.get_error_code()
--
1.7.1