[pve-devel] [PATCH 7/7] qmpclient-qga : mux_input : parse qga result
Alexandre Derumier
aderumier at odiso.com
Sun Mar 17 16:09:07 CET 2013
result sample:
first json is guest-sync result, second json is command result
{ "return": 123456}\n{"return": {}}
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QMPClient.pm | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/PVE/QMPClient.pm b/PVE/QMPClient.pm
index 193e53f..d2d4a73 100755
--- a/PVE/QMPClient.pm
+++ b/PVE/QMPClient.pm
@@ -281,7 +281,11 @@ sub queue_execute {
sub mux_input {
my ($self, $mux, $fh, $input) = @_;
- return if $$input !~ m/}\r\n$/;
+ if($self->{qga}){
+ return if $$input !~ m/}\n(.+)}\n$/;
+ }else{
+ return if $$input !~ m/}\r\n$/;
+ }
my $raw = $$input;
@@ -297,6 +301,32 @@ sub mux_input {
eval {
my @jsons = split("\n", $raw);
+ if($self->{qga}){
+
+ die "response is not complete" if @jsons != 2 ;
+
+ my $obj = from_json($jsons[0]);
+ my $cmdid = $obj->{return};
+ die "received responsed without command id\n" if !$cmdid;
+
+ my $curcmd = $self->{current}->{$vmid};
+ die "unable to lookup current command for VM $vmid\n" if !$curcmd;
+
+ delete $self->{current}->{$vmid};
+
+ if ($curcmd->{id} ne $cmdid) {
+ die "got wrong command id '$cmdid' (expected $curcmd->{id})\n";
+ }
+
+ $obj = from_json($jsons[1]);
+
+ if (my $callback = $curcmd->{callback}) {
+ &$callback($vmid, $obj);
+ }
+
+ return;
+ }
+
foreach my $json (@jsons) {
my $obj = from_json($json);
next if defined($obj->{QMP}); # skip monitor greeting
--
1.7.10.4
More information about the pve-devel
mailing list