On 01/31/2012 04:46 PM, Wayne Sun wrote:
* only accpet stream object as parameter in __init__
* remove newStream() from each function
stream object should be pass in as parameter, not create new at
each function.
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 | 84 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 58 insertions(+), 26 deletions(-)
diff --git a/lib/streamAPI.py b/lib/streamAPI.py
index bc7d217..a1b2d0d 100644
--- a/lib/streamAPI.py
+++ b/lib/streamAPI.py
@@ -38,76 +38,108 @@ append_path(result.group(0))
import exception
class StreamAPI(object):
- def __init__(self, connection):
- self.conn = connection
+ def __init__(self, stream):
+ self.stream_obj = stream
Need a 'stream' instance to initialize
class StreamAPI? how to do this?
users must to do 'stream = con.newStream(0)' then StreamAPI(stream),
right? maybe, we may do this like this:
class StreamAPI(object):
def __init__(self, connection, flag = 0):
self.conn = connection
self.stream_obj = newStream(flag)
Alex
- 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 connect(self):
try:
- stream_obj = newStream(flag)
- return stream_obj.connect()
+ return self.stream_obj.connect()
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 finish(self):
try:
- stream_obj = newStream(flag)
- return stream_obj.finish()
+ 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 recv(self, flag = 0, data, nbytes):
+ def recv(self, nbytes):
try:
- stream_obj = newStream(flag)
- return stream_obj.recv(data, nbytes)
+ 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 send(self, flag = 0, data, nbytes):
+ def send(self, data):
try:
- stream_obj = newStream(flag)
- return stream_obj.send(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 eventAddCallback(self, flag = 0, cb, opaque):
+ def eventAddCallback(self, cb, opaque):
try:
- stream_obj = newStream(flag)
- return stream_obj.eventAddCallback(cb, opaque)
+ 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 eventRemoveCallback(self, flag = 0):
+ def eventRemoveCallback(self):
try:
- stream_obj = newStream(flag)
- return stream_obj.eventRemoveCallback()
+ 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 eventUpdateCallback(self, flag = 0, events)
+ def eventUpdateCallback(self, events):
try:
- stream_obj = newStream(flag)
- return stream_obj.eventUpdateCallback(events)
+ 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 screenshot(self, domain, screen, flags = 0):
+ try:
+ 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()