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

REST API creating new profile from profile template

 
SOLVED
Go to solution
Highlighted
Respected Contributor

REST API creating new profile from profile template

I'm not getting any output when trying to create a new server profile from a profile template.  This is the process I am using: 

# Create a new profile from a server profile template:
UUID='28fa126e-bd5b-43fe-9b3c-1710554f8dcc'
NEW_PROF=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/server-profile-templates/${UUID}/new-profile)
#
# Need to modify the returned object.
SRV=my-servername
SRVURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/server-hardware?filter=%22%27serverName%27%20-%20%27${SRV}%27%22 | jq -r '.members[] | .uri')
SRVNAM=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/server-hardware?filter=%22%27serverName%27%20-%20%27${SRV}%27%22 | jq -r '.members[] | .serverName')
echo "Creating a server profile for, ${SRVNAM}, at uri: ${SRVURI}"
#
# Add in the uri:
NEW_PROF1=$(echo ${NEW_PROF} | jq -r '.serverHardwareUri="'${SRVURI}'"')
NEW_PROF=$(echo ${NEW_PROF1} | jq -r '.name="'${SRVNAM}'"')
echo "The new profile will be: $(echo ${NEW_PROF} | jq -r '.')"
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${NEW_PROF}" \
     --request GET ${OneView}/rest/server-profiles

The echo just before trying to create looks good.  No error messages from jq.  So, I think the json is OK.  OneView is complaining about anything - just no output and no profile created.  Any ideas what I am doing wrong?

1 REPLY 1
Highlighted
Respected Contributor
Solution

Re: REST API creating new profile from profile template

Chris's response to another post prompted me to add "--include" to my curl call.  I first modified the supplied data to be on one line by changing this line:

NEW_PROF=$(echo ${NEW_PROF1} | jq -r '.name="'${SRVNAM}'"' | jq -c '.')

Note piping it to jq -c.  Then I added a '--include' to my curl command:

curl --insecure \
     --include \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${NEW_PROF}" \
     --request GET ${OneView}/rest/server-profiles

 and got back: 

HTTP/1.1 100 Continue

HTTP/1.1 200 Accepted
Date: Wed, 21 Aug 2019  15:40:33 GMT
Server: Apache
Location: /rest/tasks/0E325C85-7E5E-4112-939E-2F21215D0B6728
Content-Length: 0
cache-control: no-cache

The Location line with the rest task uri is the important one.