Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deployVirtualMachine build unexpected query string for parameter iptonetworklist #32

Open
danielcosta opened this issue Jun 10, 2021 · 0 comments

Comments

@danielcosta
Copy link

Hello there, I got the very same problem reported on issue #1 but here I'll try to explain how to reproduce the case.

On deployVirtualMachine command the API accepts an array for parameter iptonetworklist, which is formatted this way if you create a VM directly from CloudStack UI: &iptonetworklist[0].networkid=b6170452-820c-4a5b-bb76-6a22a0266c0d&iptonetworklist[0].ip=10.1.1.100&iptonetworklist[0].mac=DC-FE-49-00-66-0D. The key [0] on this array can be incremented when you associate more than one network to the new VM.

The point is that the method protected function buildQueryString(array $params) on PCextreme\Cloudstack\Client is not able to build the query string array like expected by CloudStack API on this command, giving Notice: Undefined index: key if we try to send the array data with something like this:

  "iptonetworklist" => array:1 [
    0 => array:3 [
      "mac" => "54-77-2F-BA-67-74"
      "networkid" => "b6170452-820c-4a5b-bb76-6a22a0266c0d"
      "ip" => "10.1.1.50"
    ]
  ]

Otherwise, if we try to send the array as expected by the method, like the example bellow:

  "iptonetworklist" => array:3 [
    0 => array:2 [
      "key" => "mac"
      "value" => "54-77-2F-BA-67-74"
    ]
    1 => array:2 [
      "key" => "networkid"
      "value" => "b6170452-820c-4a5b-bb76-6a22a0266c0d"
    ]
    2 => array:2 [
      "key" => "ip"
      "value" => "10.1.1.50"
    ]
  ]

We get the query string as this: &iptonetworklist[0].key=mac&iptonetworklist[0].value=54-77-2F-BA-67-74&iptonetworklist[1].key=networkid&iptonetworklist[1].value=b6170452-820c-4a5b-bb76-6a22a0266c0d&iptonetworklist[2].key=ip&iptonetworklist[2].value=10.1.1.50

This way the method will not give the notice, but CloudStack API will treat each key on the array as a different entry in the map, returning this error:

ClientException {#3412
  #response: array:1 [
    "deployvirtualmachineresponse" => array:4 [
      "uuidList" => []
      "errorcode" => 431
      "cserrorcode" => 4350
      "errortext" => "Unable to translate and find entity with networkId: null"
    ]
  ]
  #message: "Unable to translate and find entity with networkId: null"
  #code: 431
  #file: "/var/www/html/vendor/pcextreme/cloudstack/src/Client.php"
  #line: 405

I'm not sure if this is the only endpoint treating array on request this way, but the way buildQueryString() method parses input and build query string is not working for the command deployVirtualMachine.

If you could confirm if there are other commands receiving and parsing arrays for requests I could eventually send a PR to fix this, but I'm afraid we fix for this command and break for others.

Please let me know if I can help sending other evidences of the case.

For the reference, I'm using CloudStack 4.15.0.0 here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant