Skip to content

Conversation

@shwstppr
Copy link
Contributor

PR #161 introduced postrequest config but there was no way to update that config other than updating the config file. This PR fixes the behaviour. Also adds a log to highlight what HTTP method is used.

Tested changing config;

⇒  make run                                                                                                                                                                                         
▶  Running gofmt…
▶  Building executable… 7510f73
▶  Done!
./bin/cmk
Apache CloudStack 🐵 CloudMonkey 6.5.0-rc
Report issues: https://github.com/apache/cloudstack-cloudmonkey/issues

(421-test) 🐱 > set profile postrequesttest
Loaded in-built API cache. Failed to read API cache, please run 'sync'.
Loaded server profile: postrequesttest
Url:         http://localhost:8080/client/api
Username:    admin
Domain:      /
API Key:     
Total APIs:  880

(postrequesttest) 🐱 > set url http://10.0.32.197:8080/client/api
Loaded in-built API cache. Failed to read API cache, please run 'sync'.
(postrequesttest) 🐱 > set debug true
[debug] UpdateConfig key:debug value:true update:true
[debug] Trying to read API cache from:/home/shwstppr/.cmk/profiles/postrequesttest.cache
Loaded in-built API cache. Failed to read API cache, please run 'sync'.
(postrequesttest) 🐱 > list zones filter=id,name
[debug] ExecLine line:list zones filter=id,name
[debug] ExecCmd args: list, zones, filter=id,name
[debug] Login POST URL:http://10.0.32.197:8080/client/apimap[command:[login] domain:[/] password:[password] response:[json] username:[admin]]
[debug] Login POST response status code:200
[debug] Login response body:{"loginresponse":{"username":"admin","userid":"9357510b-7e61-11f0-ba77-1e00c8000158","domainid":"430d0c02-7e61-11f0-ba77-1e00c8000158","timeout":1800,"account":"admin","firstname":"admin","lastname":"cloud","type":"1","timezone":"UTC","timezoneoffset":"0.0","registered":"false","sessionkey":"vBI44baeXU3Wpik2PLxZwRqcCsA","is2faenabled":"false","is2faverified":"true","issuerfor2fa":"CloudStack","managementserverid":"061c8be8-8efa-44f6-ade6-3c5502ce5b22"}}
[debug] Login sessionkey:vBI44baeXU3Wpik2PLxZwRqcCsA
[debug] Checking if 2FA is enabled and verified for the user map[account:admin domainid:430d0c02-7e61-11f0-ba77-1e00c8000158 firstname:admin is2faenabled:false is2faverified:true issuerfor2fa:CloudStack lastname:cloud managementserverid:061c8be8-8efa-44f6-ade6-3c5502ce5b22 registered:false sessionkey:vBI44baeXU3Wpik2PLxZwRqcCsA timeout:1800 timezone:UTC timezoneoffset:0.0 type:1 userid:9357510b-7e61-11f0-ba77-1e00c8000158 username:admin]
[debug] 2FA is not enabled for the user, skipping 2FA validation
[debug] NewAPIRequest API request URL:http://10.0.32.197:8080/client/api?command=listZones&expires=2025-08-26T09%3A25%3A04Z&filter=id%2Cname&response=json&sessionkey=vBI44baeXU3Wpik2PLxZwRqcCsA&signatureversion=3
[debug] Using HTTP POST for the request: http://10.0.32.197:8080/client/api
[debug] NewAPIRequest response status code:200
[debug] NewAPIRequest response body:{"listzonesresponse":{"count":1,"zone":[{"id":"ea7e88b7-0798-4ea7-adf3-253cf8b3d229","name":"ref-trl-9283-k-Mr8-abhishek-kumar","dns1":"10.0.32.1","dns2":"8.8.8.8","internaldns1":"10.0.32.1","internaldns2":"8.8.4.4","guestcidraddress":"10.1.1.0/24","networktype":"Advanced","securitygroupsenabled":false,"gputotal":0,"gpuused":0,"allocationstate":"Enabled","zonetoken":"891489eb-6f53-3e39-84d6-e97116312e88","dhcpprovider":"VirtualRouter","localstorageenabled":false,"tags":[],"allowuserspecifyvrmtu":false,"routerprivateinterfacemaxmtu":1500,"routerpublicinterfacemaxmtu":1500,"type":"Core","isnsxenabled":false,"ismultiarch":false,"asnrange":"","routedmodeenabled":true,"hasannotations":false}]}}
{
  "count": 1,
  "zone": [
    {
      "id": "ea7e88b7-0798-4ea7-adf3-253cf8b3d229",
      "name": "ref-trl-9283-k-Mr8-abhishek-kumar"
    }
  ]
}
(postrequesttest) 🐱 > set postrequest false
[debug] ExecLine line:set postrequest false
[debug] ExecCmd args: set, postrequest, false
[debug] Set command received:postrequest values:false
[debug] UpdateConfig key:postrequest value:false update:true
[debug] Trying to read API cache from:/home/shwstppr/.cmk/profiles/postrequesttest.cache
Loaded in-built API cache. Failed to read API cache, please run 'sync'.
(postrequesttest) 🐱 > list zones filter=id,name
[debug] ExecLine line:list zones filter=id,name
[debug] ExecCmd args: list, zones, filter=id,name
[debug] Login POST URL:http://10.0.32.197:8080/client/apimap[command:[login] domain:[/] password:[password] response:[json] username:[admin]]
[debug] Login POST response status code:200
[debug] Login response body:{"loginresponse":{"username":"admin","userid":"9357510b-7e61-11f0-ba77-1e00c8000158","domainid":"430d0c02-7e61-11f0-ba77-1e00c8000158","timeout":1800,"account":"admin","firstname":"admin","lastname":"cloud","type":"1","timezone":"UTC","timezoneoffset":"0.0","registered":"false","sessionkey":"8wnjcYpx7qzkjvlxLaDeHaZ7iLI","is2faenabled":"false","is2faverified":"true","issuerfor2fa":"CloudStack","managementserverid":"061c8be8-8efa-44f6-ade6-3c5502ce5b22"}}
[debug] Login sessionkey:8wnjcYpx7qzkjvlxLaDeHaZ7iLI
[debug] Checking if 2FA is enabled and verified for the user map[account:admin domainid:430d0c02-7e61-11f0-ba77-1e00c8000158 firstname:admin is2faenabled:false is2faverified:true issuerfor2fa:CloudStack lastname:cloud managementserverid:061c8be8-8efa-44f6-ade6-3c5502ce5b22 registered:false sessionkey:8wnjcYpx7qzkjvlxLaDeHaZ7iLI timeout:1800 timezone:UTC timezoneoffset:0.0 type:1 userid:9357510b-7e61-11f0-ba77-1e00c8000158 username:admin]
[debug] 2FA is not enabled for the user, skipping 2FA validation
[debug] NewAPIRequest API request URL:http://10.0.32.197:8080/client/api?command=listZones&expires=2025-08-26T09%3A25%3A40Z&filter=id%2Cname&response=json&sessionkey=8wnjcYpx7qzkjvlxLaDeHaZ7iLI&signatureversion=3
[debug] Using HTTP GET for the request: http://10.0.32.197:8080/client/api?command=listZones&expires=2025-08-26T09%3A25%3A40Z&filter=id%2Cname&response=json&sessionkey=8wnjcYpx7qzkjvlxLaDeHaZ7iLI&signatureversion=3
[debug] NewAPIRequest response status code:200
[debug] NewAPIRequest response body:{"listzonesresponse":{"count":1,"zone":[{"id":"ea7e88b7-0798-4ea7-adf3-253cf8b3d229","name":"ref-trl-9283-k-Mr8-abhishek-kumar","dns1":"10.0.32.1","dns2":"8.8.8.8","internaldns1":"10.0.32.1","internaldns2":"8.8.4.4","guestcidraddress":"10.1.1.0/24","networktype":"Advanced","securitygroupsenabled":false,"gputotal":0,"gpuused":0,"allocationstate":"Enabled","zonetoken":"891489eb-6f53-3e39-84d6-e97116312e88","dhcpprovider":"VirtualRouter","localstorageenabled":false,"tags":[],"allowuserspecifyvrmtu":false,"routerprivateinterfacemaxmtu":1500,"routerpublicinterfacemaxmtu":1500,"type":"Core","isnsxenabled":false,"ismultiarch":false,"asnrange":"","routedmodeenabled":true,"hasannotations":false}]}}
{
  "count": 1,
  "zone": [
    {
      "id": "ea7e88b7-0798-4ea7-adf3-253cf8b3d229",
      "name": "ref-trl-9283-k-Mr8-abhishek-kumar"
    }
  ]
}
(postrequesttest) 🐱 > set postrequest true
[debug] ExecLine line:set postrequest true
[debug] ExecCmd args: set, postrequest, true
[debug] Set command received:postrequest values:true
[debug] UpdateConfig key:postrequest value:true update:true
[debug] Trying to read API cache from:/home/shwstppr/.cmk/profiles/postrequesttest.cache
Loaded in-built API cache. Failed to read API cache, please run 'sync'.
(postrequesttest) 🐱 > list zones filter=id,name
[debug] ExecLine line:list zones filter=id,name
[debug] ExecCmd args: list, zones, filter=id,name
[debug] Login POST URL:http://10.0.32.197:8080/client/apimap[command:[login] domain:[/] password:[password] response:[json] username:[admin]]
[debug] Login POST response status code:200
[debug] Login response body:{"loginresponse":{"username":"admin","userid":"9357510b-7e61-11f0-ba77-1e00c8000158","domainid":"430d0c02-7e61-11f0-ba77-1e00c8000158","timeout":1800,"account":"admin","firstname":"admin","lastname":"cloud","type":"1","timezone":"UTC","timezoneoffset":"0.0","registered":"false","sessionkey":"RdGJhjn9r4MymvjBOTRio4hRqpg","is2faenabled":"false","is2faverified":"true","issuerfor2fa":"CloudStack","managementserverid":"061c8be8-8efa-44f6-ade6-3c5502ce5b22"}}
[debug] Login sessionkey:RdGJhjn9r4MymvjBOTRio4hRqpg
[debug] Checking if 2FA is enabled and verified for the user map[account:admin domainid:430d0c02-7e61-11f0-ba77-1e00c8000158 firstname:admin is2faenabled:false is2faverified:true issuerfor2fa:CloudStack lastname:cloud managementserverid:061c8be8-8efa-44f6-ade6-3c5502ce5b22 registered:false sessionkey:RdGJhjn9r4MymvjBOTRio4hRqpg timeout:1800 timezone:UTC timezoneoffset:0.0 type:1 userid:9357510b-7e61-11f0-ba77-1e00c8000158 username:admin]
[debug] 2FA is not enabled for the user, skipping 2FA validation
[debug] NewAPIRequest API request URL:http://10.0.32.197:8080/client/api?command=listZones&expires=2025-08-26T09%3A26%3A03Z&filter=id%2Cname&response=json&sessionkey=RdGJhjn9r4MymvjBOTRio4hRqpg&signatureversion=3
[debug] Using HTTP POST for the request: http://10.0.32.197:8080/client/api
[debug] NewAPIRequest response status code:200
[debug] NewAPIRequest response body:{"listzonesresponse":{"count":1,"zone":[{"id":"ea7e88b7-0798-4ea7-adf3-253cf8b3d229","name":"ref-trl-9283-k-Mr8-abhishek-kumar","dns1":"10.0.32.1","dns2":"8.8.8.8","internaldns1":"10.0.32.1","internaldns2":"8.8.4.4","guestcidraddress":"10.1.1.0/24","networktype":"Advanced","securitygroupsenabled":false,"gputotal":0,"gpuused":0,"allocationstate":"Enabled","zonetoken":"891489eb-6f53-3e39-84d6-e97116312e88","dhcpprovider":"VirtualRouter","localstorageenabled":false,"tags":[],"allowuserspecifyvrmtu":false,"routerprivateinterfacemaxmtu":1500,"routerpublicinterfacemaxmtu":1500,"type":"Core","isnsxenabled":false,"ismultiarch":false,"asnrange":"","routedmodeenabled":true,"hasannotations":false}]}}
{
  "count": 1,
  "zone": [
    {
      "id": "ea7e88b7-0798-4ea7-adf3-253cf8b3d229",
      "name": "ref-trl-9283-k-Mr8-abhishek-kumar"
    }
  ]
}
(postrequesttest) 🐱 > exit
[debug] ExecLine line:exit
[debug] ExecCmd args: exit

PR apache#161 introduced `postrequest` config but there was no way to update that config other than updating the config file.
This PR fixes the behaviour. Also adds a log to highlight what HTTP
method is used.

Signed-off-by: Abhishek Kumar <[email protected]>
@shwstppr shwstppr added this to the 6.5.0 milestone Aug 26, 2025
@github-actions
Copy link

✅ Build complete for PR #190.

🔗 Download the cmk binaries (expires on September 05, 2025)

Copy link
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

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

clgtm

Copy link

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

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

LGTM

  1. Enabled the global setting "enforce.post.requests.and.timestamps” to true

  2. On the cmk

(admin) 🐱 > set postrequest false 

(admin) 🐱 > create volume name=test5 diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210  zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] ExecLine line:create volume name=test5 diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210  zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] ExecCmd args: create, volume, name=test5, diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210, zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] NewAPIRequest API request URL:http://10.0.35.15:8080/client/api?apiKey=LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q&command=createVolume&diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210&expires=2025-08-26T10%3A03%3A51Z&name=test5&response=json&signatureversion=3&zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034&signature=XQ5zgA1Z%2F33lGP4es1L%2FJZwsXeM%3D
[debug] Using HTTP GET for the request: http://10.0.35.15:8080/client/api?apiKey=LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q&command=createVolume&diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210&expires=2025-08-26T10%3A03%3A51Z&name=test5&response=json&signatureversion=3&zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034&signature=XQ5zgA1Z%2F33lGP4es1L%2FJZwsXeM%3D
[debug] NewAPIRequest response status code:400
[debug] NewAPIRequest response body:{"createvolumeresponse":{"uuidList":[],"errorcode":400,"cserrorcode":9999,"errortext":"State changing command createVolume needs to be sent using POST request"}}
🙈 Error: (HTTP 400, error code 9999) State changing command createVolume needs to be sent using POST request
  1. On cmk change the parameter to true
(admin) 🐱 > set postrequest true


[debug] ExecLine line:set postrequest true
[debug] ExecCmd args: set, postrequest, true
[debug] Set command received:postrequest values:true
[debug] UpdateConfig key:postrequest value:true update:true
[debug] Trying to read API cache from:/Users/kiranchavala/.cmk/profiles/admin.cache
(admin) 🐱 > create volume name=test5 diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210  zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] ExecLine line:create volume name=test5 diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210  zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] ExecCmd args: create, volume, name=test5, diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210, zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] NewAPIRequest API request URL:http://10.0.35.15:8080/client/api?apiKey=LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q&command=createVolume&diskofferingid=2c8a9190-3099-4598-95b1-19560bd40210&expires=2025-08-26T10%3A05%3A48Z&name=test5&response=json&signatureversion=3&zoneid=5ae50b9f-6280-4c4b-9551-ee48da867034
[debug] Using HTTP POST for the request: http://10.0.35.15:8080/client/api
[debug] NewAPIRequest response status code:200
[debug] NewAPIRequest response body:{"createvolumeresponse":{"id":"942f7f51-c410-4036-bbde-2ff80812f285","jobid":"3a94e2da-28af-46e3-a0c4-6316ae405f6b"}}
⣯ 😹 polling for async API result[debug] NewAPIRequest API request URL:http://10.0.35.15:8080/client/api?apiKey=LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q&command=queryAsyncJobResult&expires=2025-08-26T10%3A05%3A51Z&jobid=3a94e2da-28af-46e3-a0c4-6316ae405f6b&response=json&signatureversion=3
[debug] Using HTTP POST for the request: http://10.0.35.15:8080/client/api
⡿ 😻 polling for async API result[debug] NewAPIRequest response status code:200
[debug] NewAPIRequest response body:{"queryasyncjobresultresponse":{"accountid":"41afc720-7731-11f0-9a5b-1e00900003a2","account":"admin","domainid":"f8f8593c-7730-11f0-9a5b-1e00900003a2","domainpath":"ROOT","userid":"41b07ac1-7731-11f0-9a5b-1e00900003a2","cmd":"org.apache.cloudstack.api.command.admin.volume.CreateVolumeCmdByAdmin","jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"volume":{"id":"942f7f51-c410-4036-bbde-2ff80812f285","name":"test5","zoneid":"5ae50b9f-6280-4c4b-9551-ee48da867034","zonename":"ref-trl-9219-k-Mol8-kiran-chavala","type":"DATADISK","provisioningtype":"thin","size":5368709120,"created":"2025-08-26T09:50:49+0000","state":"Allocated","account":"admin","domainid":"f8f8593c-7730-11f0-9a5b-1e00900003a2","domain":"ROOT","domainpath":"/","storagetype":"shared","hypervisor":"None","diskofferingid":"2c8a9190-3099-4598-95b1-19560bd40210","diskofferingname":"Small","diskofferingdisplaytext":"Small Disk, 5 GB","destroyed":false,"isextractable":true,"displayvolume":true,"quiescevm":false,"supportsstoragesnapshot":false,"deleteprotection":false,"tags":[],"hasannotations":false,"jobid":"3a94e2da-28af-46e3-a0c4-6316ae405f6b","jobstatus":0}},"jobinstancetype":"Volume","jobinstanceid":"942f7f51-c410-4036-bbde-2ff80812f285","created":"2025-08-26T09:50:49+0000","completed":"2025-08-26T09:50:49+0000","jobid":"3a94e2da-28af-46e3-a0c4-6316ae405f6b","jobstatus":1}}
{
  "volume": {
    "account": "admin",
    "created": "2025-08-26T09:50:49+0000",
    "deleteprotection": false,
    "destroyed": false,
    "diskofferingdisplaytext": "Small Disk, 5 GB",
    "diskofferingid": "2c8a9190-3099-4598-95b1-19560bd40210",
    "diskofferingname": "Small",
    "displayvolume": true,
    "domain": "ROOT",
    "domainid": "f8f8593c-7730-11f0-9a5b-1e00900003a2",
    "domainpath": "/",
    "hasannotations": false,
    "hypervisor": "None",
    "id": "942f7f51-c410-4036-bbde-2ff80812f285",
    "isextractable": true,
    "jobid": "3a94e2da-28af-46e3-a0c4-6316ae405f6b",
    "jobstatus": 0,
    "name": "test5",
    "provisioningtype": "thin",
    "quiescevm": false,
    "size": 5368709120,
    "state": "Allocated",
    "storagetype": "shared",
    "supportsstoragesnapshot": false,
    "tags": [],
    "type": "DATADISK",
    "zoneid": "5ae50b9f-6280-4c4b-9551-ee48da867034",
    "zonename": "ref-trl-9219-k-Mol8-kiran-chavala"
  }
}

@shwstppr shwstppr merged commit ccb6470 into apache:main Aug 26, 2025
6 checks passed
@shwstppr shwstppr deleted the fix-postrequest-config branch August 26, 2025 10:01
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.

3 participants