Skip to content

Conversation

shwstppr
Copy link
Contributor

@shwstppr shwstppr commented Jul 31, 2025

Fixes #117
Fixes #152

Currently, filtering is not working when the response object is not returning an array. This PR makes changes to allow filtering when response object is an array or a map.

For async apis, filter arg is passed to the query request allowing filtering to work with the final response.

Output with changes,

⇒  make run                                                                                                                                                                                         main|✚2 
▶  Running gofmt…
▶  Building executable… a6552ee
▶  Done!
./bin/cmk
Apache CloudStack 🐵 CloudMonkey 6.4.0
Report issues: https://github.com/apache/cloudstack-cloudmonkey/issues

(lab) 🐱 > deploy virtualmachine zoneid=1bf9db92-f21a-411b-a089-58ce51754581 serviceofferingid=0348031d-aa66-419d-bb4b-b023b3017c0c templateid=8fe9df86-6de0-11f0-bdac-9843fa67404e (CentOS 5.6 (64-bit) no GUI (Simulator)) filter=id
{
  "virtualmachine": [
    {
      "id": "d0f4daa2-7adc-4cdf-a65c-ec128d8374be"
    }
  ]
}
(lab) 🐱 > update virtualmachine id=2902e6d3-b261-4de1-a0cf-2fe6e324ea88 display=abc filter=name,id
{
  "virtualmachine": [
    {
      "id": "2902e6d3-b261-4de1-a0cf-2fe6e324ea88",
      "name": "VM-2902e6d3-b261-4de1-a0cf-2fe6e324ea88"
    }
  ]
}
(lab) 🐱 > list virtualmachines id=2902e6d3-b261-4de1-a0cf-2fe6e324ea88 filter=id,name
{
  "count": 1,
  "virtualmachine": [
    {
      "id": "2902e6d3-b261-4de1-a0cf-2fe6e324ea88",
      "name": "VM-2902e6d3-b261-4de1-a0cf-2fe6e324ea88"
    }
  ]
}

For output,

⇒  make run                                                                                                                                                     allow-filter-nonlistapis| 
▶  Running gofmt…
/home/shwstppr/lab/shapeblue/cloudstack-cloudmonkey/cmd/network.go
▶  Building executable… a6ee865
▶  Done!
./bin/cmk
Apache CloudStack 🐵 CloudMonkey 6.4.0
Report issues: https://github.com/apache/cloudstack-cloudmonkey/issues

(lab) 🐱 > set output table
(lab) 🐱 > 
(lab) 🐱 > deploy virtualmachine zoneid=1bf9db92-f21a-411b-a089-58ce51754581 serviceofferingid=0348031d-aa66-419d-bb4b-b023b3017c0c templateid=8fe9df86-6de0-11f0-bdac-9843fa67404e (CentOS 5.6 (64-bit) no GUI (Simulator)) filter=id,name
virtualmachine:
+--------------------------------------+-----------------------------------------+
|                  ID                  |                  NAME                   |
+--------------------------------------+-----------------------------------------+
| f33388d1-358e-4fb3-92a8-90f00b30e4f8 | VM-f33388d1-358e-4fb3-92a8-90f00b30e4f8 |
+--------------------------------------+-----------------------------------------+

Currently, filtering is not working when the response object is not
returning an array. This PR makes changes to allow filtering when
response object is an array or a map.

For async apis, filter arg is passed to the query request allowing
filtering to work with the final response.

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@shwstppr shwstppr changed the title output: allow filtering for non-list apis output: allow filtering and honour output format for non-list apis Jul 31, 2025
@DaanHoogland
Copy link
Contributor

tested destroy

(randy) 🐱 > destroy virtualmachine id=110f2c65-1c27-4131-aa78-28da865f8c60 filter=name,zoneid,cpunumber,hostname
{
  "virtualmachine": [
    {
      "cpunumber": 1,
      "name": "VM-110f2c65-1c27-4131-aa78-28da865f8c60",
      "zoneid": "8710c111-ff6f-4246-96bc-0f56be3be16f"
    }
  ]
}
(randy) 🐱 > set output table
(randy) 🐱 > destroy virtualmachine id=543b2904-e931-4325-959e-70174973389e  filter=name,zoneid,cpunumber,hostname
virtualmachine:
+-----------------------------------------+--------------------------------------+-----------+----------+
|                  NAME                   |                ZONEID                | CPUNUMBER | HOSTNAME |
+-----------------------------------------+--------------------------------------+-----------+----------+
| VM-543b2904-e931-4325-959e-70174973389e | 8710c111-ff6f-4246-96bc-0f56be3be16f |         1 |          |
+-----------------------------------------+--------------------------------------+-----------+----------+

Also tried to merge it with #163 but couldn’t get that to work yet. Both look good in isolation.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good, one caveat is merging this with #163. That will require some effort (as I think you predicted @shwstppr )

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@DaanHoogland
Copy link
Contributor

DaanHoogland commented Aug 6, 2025

retested:

(randy) 🐱 > destroy virtualmachine id=6983f65d-002f-4b39-abcd-101a87ed87bd filter=name,account,hostid,zonename,
virtualmachine:
+-----------------------------------------+---------+--------+------------------------+
|                  NAME                   | ACCOUNT | HOSTID |        ZONENAME        |
+-----------------------------------------+---------+--------+------------------------+
| VM-6983f65d-002f-4b39-abcd-101a87ed87bd | admin   |        | pr10149-t13944-kvm-ol8 |
+-----------------------------------------+---------+--------+------------------------+
(randy) 🐱 > destroy virtualmachine id=88410c7e-9dc8-40b5-93ce-1322c6b58272 exclude=id,zoneid,zonename,details,nic,
{
  "virtualmachine": [
    {
      "account": "admin",
      "affinitygroup": [],
      "arch": "x86_64",
      "cpunumber": 1,
      "cpuspeed": 500,
      "created": "2025-08-05T14:14:52+0000",
      "deleteprotection": false,
      "displayname": "VM-88410c7e-9dc8-40b5-93ce-1322c6b58272",
      "displayvm": true,
      "domain": "ROOT",
      "domainid": "ff08771b-6bbd-11f0-80fe-1e00cf0001d6",
      "domainpath": "/",
      "guestosid": "ff2c2d90-6bbd-11f0-80fe-1e00cf0001d6",
      "haenable": false,
      "hasannotations": false,
      "hypervisor": "KVM",
      "instancename": "i-2-10-VM",
      "ipaddress": "10.1.1.36",
      "isdynamicallyscalable": true,
      "jobid": "2b78bf8f-6419-4c86-bac8-bf0c12bebaf1",
      "jobstatus": 0,
      "lastupdated": "2025-08-06T12:08:49+0000",
      "memory": 512,
      "name": "VM-88410c7e-9dc8-40b5-93ce-1322c6b58272",
      "osdisplayname": "Other Linux (64-bit)",
      "ostypeid": "ff2c2d90-6bbd-11f0-80fe-1e00cf0001d6",
      "passwordenabled": true,
      "pooltype": "NetworkFilesystem",
      "receivedbytes": 0,
      "rootdeviceid": 0,
      "rootdevicetype": "ROOT",
      "securitygroup": [],
      "sentbytes": 0,
      "serviceofferingid": "32af3025-54fd-44da-aafe-79ef7cd84dc7",
      "serviceofferingname": "Small Instance",
      "state": "Destroyed",
      "tags": [],
      "templatedisplaytext": "mini",
      "templateformat": "QCOW2",
      "templateid": "0a73e080-7119-44b0-87b6-d70e8c3871a4",
      "templatename": "mini",
      "templatetype": "USER",
      "userid": "4cc477f3-6bbe-11f0-80fe-1e00cf0001d6",
      "username": "admin"
    }
  ]
}

@shwstppr shwstppr closed this Aug 8, 2025
@shwstppr shwstppr reopened this Aug 8, 2025
Copy link

github-actions bot commented Aug 8, 2025

✅ Build complete for PR #164.

🔗 Download the cmk binaries (expires on August 18, 2025)

@shwstppr shwstppr added this to the 6.5.0 milestone Aug 8, 2025
@DaanHoogland
Copy link
Contributor

@shwstppr , any reason not to merge this yet?

@shwstppr
Copy link
Contributor Author

shwstppr commented Aug 8, 2025

@DaanHoogland when I checked last it had the need-testing label so I was not sure if you wanted more testing on it

@DaanHoogland
Copy link
Contributor

right, removed, merging

@DaanHoogland DaanHoogland merged commit 94da963 into apache:main Aug 8, 2025
5 checks passed
shwstppr added a commit to shwstppr/cloudstack-cloudmonkey that referenced this pull request Aug 13, 2025
…pache#164)

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
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

Successfully merging this pull request may close these issues.

Display option not honoured by async API response filter is ignored on e.g. deploy virtual machine
3 participants