Bug #11642
closedFetching host power state using "power_action": "status" fails for VMs
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1211376
Description of problem:
User is unable to fetch a power state of a VM using REST API `"power_action": "status"` ; PUT /api/hosts/:id/power.
Version-Release number of selected component (if applicable):
Upstream foreman 1.7.4-1
Downstream Sat 6.0.8
How reproducible:
-
Steps to Reproduce:
1. Setup a compute resource
2. Create a host on that compute resource
3. Run power state check using the rest api against the virtualized host:
[jkrocil@lysandros ~]$ curl --insecure -X PUT -d '{"power_action": "status"}' -u admin -H "Content-Type:application/json" -H "Accept:application/json" https://my-foreman.domain.com/api/v2/hosts/my-vm.nested.lan/power
Actual results:
{
"error": {"message":"undefined method `status' for #<PowerManager::Virt:0x007f8e196e0268>"}
}
Expected results:
Valid response with power state info.
Additional info:
Running `"power_action": "state"` instead of "status" works.
The issue is here:
https://github.com/theforeman/foreman/blob/develop/app/services/power_manager/virt.rb#L24
"state" and "status" is being removed from the SUPPORTED_ACTIONS.
There are methods being created dynamically for each power state except the 2.
For "state" though, there is a method defined at L18.
For "status", there is nothing.
Thanks to stbenjam for help.