Proper XML CALL

Hi guys,

We are trying to create a VM template with one.template.allocate API call:

> curl -H "Content-Type: text/xml" -X POST \
>   -d "<?xml version='1.0'?>
>       <methodCall>
>         <methodName>one.template.allocate</methodName>
>         <params>
>           <param>
>             <value><string>oneadmin:oneadmin</string></value>
>           </param>
>           <param>
>             <value><string><NAME>abc</NAME></string></value>
>           </param>
>         </params>
>       </methodCall>" http://vip_ip:2633/RPC2

But get an error:

Call XML not a proper XML-RPC call. The child of a <value> element is neither <array> nor <struct>, but has 1 child elements of its own.

Please help in advice!

Hi Leonid,

Following XML-RPC API doc you should encapsulate the values in <TEMPLATE> ... </TEMPLATE> . And the XML-RPC spec update Updated 1/21/99 DW says:

What characters are allowed in strings? Non-printable characters? Null characters? Can a “string” be used to hold an arbitrary chunk of binary data?

Any characters are allowed in a string except < and &, which are encoded as &lt; and &amp;. A string can be used to encode binary data.

This is the academic approach to the solution. The practical one that I usually use is to run mitmproxy and run the shell tools with endpoint the proxied port

#run in one terminal
mitmproxy --mode reverse:http://127.0.0.1:2633 -p 2634
#and in a second terminal call onetemplate...
cat >template.xml <<EOF
<TEMPLATE>
  <NAME>test</NAME>
</TEMPLATE>
EOF
onetemplate create template.xml --endpoint http://127.0.0.1:2634/RPC2
ID: 20

After getting familiar with the interface of mitmproxy You could monitor the actual XML-RPC2 API request, which is as follow:

<?xml version="1.0" ?>
<methodCall>
  <methodName>one.template.allocate</methodName>
  <params>
    <param>
    <value>
      <string>oneadmin:oneadmin</string>
    </value>
    </param>
    <param>
    <value>
      <string>
        &lt;TEMPLATE&gt;
          &lt;NAME&gt;test4&lt;/NAME&gt;
        &lt;/TEMPLATE&gt;
      </string>
    </value>
    </param>
  </params>
</methodCall>

Hope this helps. :wink:

Best Regards,
Anton Todorov

1 Like

Hi Anton,

Thank you very much !!
That is exactly what we need.