HPE OneView
cancel
Showing results for 
Search instead for 
Did you mean: 

Delete server hard via REST API?

 
SOLVED
Go to solution
Highlighted
Respected Contributor

Delete server hard via REST API?

I'm trying to figure out how to remove a server from OpenView through the REST API.  I see POST https://{appl}/rest/server-hardware for adding a server, but don't see anything specific to deleting a server.  Does anyone know the correct call for that?

7 REPLIES 7
Highlighted
HPE Pro
Solution

Re: Delete server hard via REST API?

You would use DELETE /rest/server-hardware/{UUID}. This is documented in our REST API documentation. You could also use our language bindings or scripting SDK's like PowerShell or Python, which include options or examples to remove resources like server hardware.

I am an HPE employee

Accept or Kudo

Highlighted
Respected Contributor

Re: Delete server hard via REST API?

Hi Chris,

I am logged into our OpenView and pulled up the REST API reference.  Looking at the Server Hardware page, I see GET, PUT, PATCH, and POST, but there is no DELETE documented.  My systems are all Linux.  So, using curl and the REST API, not powershell.  I'll do a GET /rest/server-hardware to get a current listing.  Then, I'll try the DELETE /rest/server-hardware/{UUID} and see how that works?  Might need an engineering change request to update the documentation.  :)

Regards,

Brad

Highlighted
Respected Contributor

Re: Delete server hard via REST API?

Can report that this worked:

UUID=3738638-3330-5536-4F38-323836433D33
DELURI=$(curl --insecure \
     --header "auth: ${sessionID}" \
     --header "X-API-Version: ${currentVersion}" \
     --request DELETE ${OneView}/rest/server-hardware/${UUID} | jq -r ".uri")
curl --insecure \
     --header "auth: ${sessionID}" \
     --header "X-API-Version: ${currentVersion}" \
     --request GET ${OneView}${DELURI} | jq -r '.'

Thanks Chris.  Please make sure they update the REST API reference!  :)

Regards,

Brad V

Highlighted
Respected Contributor

Re: Delete server hard via REST API?

HI Chris,

I just checked in the vs 1200 API reference and I still can't find this documented.  Also, the deletion command is working, but I'm not getting any return.  No deletion task uri or anything.

Highlighted
HPE Pro

Re: Delete server hard via REST API?

The task URI will be in the HTTP headers of the responce.  As I have stated in other threads, you need to look at the HTTP response code from the cURL call.  If it is HTTP 202, then you need to look for the Location HTTP header, which will contain the task URI.


I am an HPE employee

Accept or Kudo

Highlighted
HPE Pro

Re: Delete server hard via REST API?

Also, as for the REST API reference documentation, I am looking into it.


I am an HPE employee

Accept or Kudo

Highlighted
Respected Contributor

Re: Delete server hard via REST API?

Sorry, was floating in the Caribbean. 

I think I got it worked out.  To delete: 

# To delete a server
UUID=3738638-3330-5536-4F38-323836433D33
declare -a RESPONS
RESPONS=($(curl --insecure \
     --header "auth: ${sessionID}" \
     --header "X-API-Version: ${currentVersion}" \
     --include \
     --request DELETE ${OneView}/rest/server-hardware/${UUID} | grep -E '^HTTP|^Location'))
if [[ ${RESPONS[1]} -eq 202 ]]; then
   # Accepted
   DELURI=${RESPONS[4]}
   # Check the deletion task status:
   curl --insecure \
        --header "auth: ${sessionID}" \
        --header "X-API-Version: ${currentVersion}" \
        --request GET ${OneView}${DELURI} | jq -r '.'
else
   echo rejected
fi
unset RESPONS

To add:

# To add a server:
SERVER="my-hostname-ilo.my.org"
declare -a RESPONS
RESPONS=($(curl --insecure \
      --"content-type: application/json" \
      --header "auth: ${sessionID}" \
      --header "X-API-Version: ${currentVersion}" \
      --include \
      --data "{ \"hostname\": \"${SERVER}\", \"username\": \"Administrator\", \"password\": \"${PASSW}\", \"force\": false, \"licensingIntent\": \"OneView\", \"configurationState\": \"Managed\", \"initialScopeUris\": []}' \
      --request POST ${OneView}/rest/server-hardware | grep -E '^HTTP|^Location'))
if [[ ${RESPONS[1]} -eq 202 ]]; then
   # Accepted
   ADDURI=${RESPONS[4]}
   # Check the addition task status:
   curl --insecure \
        --header "auth: ${sessionID}" \
        --header "X-API-Version: ${currentVersion}" \
        --request GET ${OneView}${ADDURI} | jq -r '.'
else
   echo rejected
fi
unset RESPONS

This seems to be working.  Thanks!