]> git.proxmox.com Git - qemu-server.git/commitdiff
qmpclient-qga : mux_input : parse qga result
authorAlexandre Derumier <aderumier@odiso.com>
Sun, 17 Mar 2013 15:09:07 +0000 (16:09 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 1 Dec 2014 08:50:12 +0000 (09:50 +0100)
result sample:

first json is guest-sync result, second json is command result

{ "return": 123456}\n{"return": {}}

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
PVE/QMPClient.pm

index 3401ce3e889b5426e6a4ad16c9b9193e274cd184..51f7c185d6f5821d8c6d8bc1ef12a143518f82f9 100755 (executable)
@@ -292,9 +292,15 @@ sub mux_close {
 sub mux_input {
     my ($self, $mux, $fh, $input) = @_;
 
-    return if $$input !~ s/^(.*})\r\n(.*)$/$2/so;
-
-    my $raw = $1;
+    my $raw;
+
+    if($self->{qga}){
+       return if $$input !~ s/^([^\n]+}\n[^\n]+})\n(.*)$/$2/so;
+       $raw = $1;
+    }else{
+       return if $$input !~ s/^([^\n]+})\r?\n(.*)$/$2/so;
+       $raw = $1;
+    }
 
     my $vmid = $self->{fhs_lookup}->{$fh};
     if (!$vmid) {
@@ -305,6 +311,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