Initial, simple, unit-tested implementation of QMPClient.

This follows the README given earlier, at least in principle, but
doesn't implement the entirety of QMP, by any stretch of the
imagination.

Notable by their absence are error responses, argument validation
(for incoming and outgoing messsages of all types), and any visibility
into qmp_capabilities.

Also missing are integration tests.
This commit is contained in:
Nick Thomas
2011-11-13 18:36:51 +00:00
parent 7777e5cacb
commit 51175ddf56
13 changed files with 833 additions and 1 deletions

35
lib/qmp_client.rb Normal file
View File

@@ -0,0 +1,35 @@
require 'socket'
require 'qmp_client/api'
require 'qmp_client/connectors'
require 'qmp_client/messages'
# This library provides an interface to QEMU's QMP server, allowing you to
# manage and query running virtual machines.
#
# @author Nick Thomas <nick@lupine.me.uk>
module QMPClient
def self.connect_unix(filename, &blk)
sock = UNIXSocket.connect(filename)
connect_socket(sock, &blk)
ensure
sock.close if sock && !sock.closed?
end
def self.connect_tcp(host, port, local_host=nil, local_port=nil, &blk)
sock = TCPSocket.connect(host, port, local_host, local_port)
connect_socket(sock, &blk)
ensure
sock.close if sock && !sock.closed?
end
def self.connect_socket(read_socket, write_socket = nil, &blk)
conn = Connectors::Socket.new(QMPClient::Messages, QMPClient::Messages)
conn.run(read_socket, write_socket) do |rq, wq|
API.run(rq, wq, &blk)
end
end
end