[libvirt] [PATCH] virsh: Pretty the output of qemu-agent-command

Osier Yang jyang at redhat.com
Tue May 14 17:05:59 UTC 2013


On 15/05/13 00:27, Daniel P. Berrange wrote:
> On Tue, May 14, 2013 at 11:36:01PM +0800, Osier Yang wrote:
>> This adds a new option "--pretty" for qemu-agent-command, to
>> pretty-format the returned JSON string.
>> ---
>>   tools/virsh-domain.c | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
>> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>> index 546b182..bb94ac1 100644
>> --- a/tools/virsh-domain.c
>> +++ b/tools/virsh-domain.c
>> @@ -7605,6 +7605,10 @@ static const vshCmdOptDef opts_qemu_agent_command[] = {
>>        .type = VSH_OT_BOOL,
>>        .help = N_("execute command without timeout")
>>       },
>> +    {.name = "pretty",
>> +     .type = VSH_OT_BOOL,
>> +     .help = N_("pretty-print the output")
>> +    },
>>       {.name = "cmd",
>>        .type = VSH_OT_ARGV,
>>        .flags = VSH_OFLAG_REQ,
>> @@ -7626,6 +7630,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
>>       const vshCmdOpt *opt = NULL;
>>       virBuffer buf = VIR_BUFFER_INITIALIZER;
>>       bool pad = false;
>> +    virJSONValuePtr pretty = NULL;
>>   
>>       dom = vshCommandOptDomain(ctl, cmd, NULL);
>>       if (dom == NULL)
>> @@ -7670,6 +7675,17 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
>>       }
>>       result = virDomainQemuAgentCommand(dom, guest_agent_cmd, timeout, flags);
>>   
>> +    if (vshCommandOptBool(cmd, "pretty")) {
>> +        char *tmp;
>> +        pretty = virJSONValueFromString(result);
>> +        if (pretty && (tmp = virJSONValueToString(pretty, true))) {
>> +            VIR_FREE(result);
>> +            result = tmp;
>> +        } else {
>> +            vshResetLibvirtError();
>> +        }
>> +    }
>> +
>>       vshPrint(ctl, "%s\n", result);
>>   
>>       ret = true;
> ACK

Thanks, pushed.

Osier




More information about the libvir-list mailing list