HPE OneView
1837582 Members
2925 Online
110117 Solutions
New Discussion

Power off server

 
SOLVED
Go to solution
BradV
Esteemed Contributor

Power off server

I'm trying to send a REST API call to a server to power it off, but getting back:

 

{"errorCode":"INVALID_JSON_DATA_TYPE","message":"Invalid JSON data type.","details":"The JSON sent in the request contained a unknown type where a different unknown type is required on line 1 near column 15.","messageParameters":[],"recommendedActions":["Correct the content of the JSON and retry the request."],"errorSource":null,"nestedErrors":[],"data":{}}

 

Just realized why I was getting that.  I was using "off" instead of "Off."  So, case is significant.  Might be good to point out in the API reference what the exact allowed values are for powerState?

My working code is:

 

SERVER=my.fqdn
POWER=<On|Off>
ACTV=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "\"serverName = '${SERVER}'\"")
UUID=$(curl --insecure --silent \
      --header "auth: ${sessionID}" \
      --header "X-API-Version: ${currentVersion}" \
      --request GET ${OneView}/rest/server-hardware?filter=${ACTV} | jq -r '.members[] | .uuid')
DATA='{"powerState":"'${POWER}'","powerControl":"MomentaryPress"}'
TASKURI=$(curl --insecure \
       --header "content-type: application/json" \
       --header "X-API-Version: ${currentVersion}" \
       --header "auth: ${sessionID}" \
       --include \
       --data "${DATA}" \
       --request PUT ${OneView}/rest/server-hardware/${UUID}/powerState |  grep '^Location:' | awk '{ print $2})
echo "Can check the power off task at: ${TASKURI}"

 

2 REPLIES 2
BradV
Esteemed Contributor
Solution

Re: Power off server

Just trying to mark as solved.

Sunitha_Mod
Honored Contributor

Re: Power off server

Hello @BradV

Thank you for sharing the info. We hope it'll help other community members.