mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-29 18:34:50 +00:00
qmpclient-qga : mux_input : parse qga result
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>
This commit is contained in:
parent
a45a14fcf7
commit
bcfbc40b39
@ -292,9 +292,15 @@ sub mux_close {
|
|||||||
sub mux_input {
|
sub mux_input {
|
||||||
my ($self, $mux, $fh, $input) = @_;
|
my ($self, $mux, $fh, $input) = @_;
|
||||||
|
|
||||||
return if $$input !~ s/^(.*})\r\n(.*)$/$2/so;
|
my $raw;
|
||||||
|
|
||||||
my $raw = $1;
|
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};
|
my $vmid = $self->{fhs_lookup}->{$fh};
|
||||||
if (!$vmid) {
|
if (!$vmid) {
|
||||||
@ -305,6 +311,32 @@ sub mux_input {
|
|||||||
eval {
|
eval {
|
||||||
my @jsons = split("\n", $raw);
|
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) {
|
foreach my $json (@jsons) {
|
||||||
my $obj = from_json($json);
|
my $obj = from_json($json);
|
||||||
next if defined($obj->{QMP}); # skip monitor greeting
|
next if defined($obj->{QMP}); # skip monitor greeting
|
||||||
|
Loading…
Reference in New Issue
Block a user