HPE OneView
1754372 Members
3370 Online
108813 Solutions
New Discussion

OneView REST API add server to rack

 
BradV
Esteemed Contributor

OneView REST API add server to rack

I'm trying to determine if racks will have any benefit to our OneView appliances.  I can create the rack object.  Now I want to add the equipment in each rack.  That would go under the array rackMounts, but I'm not sure how to identify each server, switch, PDU, etc.  The servers at least are already added to OneView.  Can anyone explain a little more how to add a server?  For example a DL380 G10 at U position 1,

{"rackMounts":["location":"CenterFront","topUSlot":2,"uHeight":2]}

how to identify/link to the server?

5 REPLIES 5
Vinky_99
Esteemed Contributor

Re: OneView REST API add server to rack

@BradV 

You may try following the below steps:

  1. Get the URI of the server resource: First, you need to obtain the URI of the server resource that you want to add to the rack. You can retrieve this information by making a GET request to the servers collection resource or by using the search API.

  2. Create a new rack mount resource: You can add a new rack mount resource to the rackMounts array of the rack resource by making a POST request to the rack resource's rackMounts subcollection. The request body should contain the necessary properties, such as the location of the device in the rack (for example, CenterFront), the top USlot (for example, 2), and the U height (for example, 2).

  3. Associate the server with the rack mount resource: Once you have created the rack mount resource, you can associate the server with the rack mount resource by updating the server's associatedResource property with the URI of the rack mount resource. You can update this property by making a PATCH request to the server resource, with the new associatedResource value in the request body.

For example, to add a DL380 G10 server at U position 1 in the CenterFront location of a rack, you can use the following API calls:

  1. Get the URI of the server resource: GET /rest/server-hardware?filter="model='DL380 G10'"   -----This API call retrieves the URI of the server resource with the specified model.

  2. Create a new rack mount resource:      

    POST /rest/racks/{rackId}/rack-mounts

    Request body:
    {
    "location": "CenterFront",
    "topUSlot": 1,
    "uHeight": 2
    }

    This API call creates a new rack mount resource with the specified location, top USlot, and U height.
  3. Associate the server with the rack mount resource:

    PATCH /rest/server-hardware/{serverId}

    Request body:
    {
    "associatedResource": "/rest/racks/{rackId}/rack-mounts/{rackMountId}"
    }


    This API call updates the associatedResource property of the server resource with the URI of the newly created rack mount resource.

    Note that you need to replace the {rackId}, {serverId}, and {rackMountId} placeholders in the API calls with the actual IDs of the corresponding resources.

See if this helps you! 

 

Also a NOTE: Am not an expert, I may go wrong. Take a back-up of the data, before you perform any steps. You can give a try on your own risk. 

These are my opinions so use it at your own risk.
Kashyap02
HPE Pro

Re: OneView REST API add server to rack

Hi, Try the suggestions given by Vinky_99 . If fails, request you to log a case with HPE so that we can test the same in the lab. 

I am a HPE Employee.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]

Accept or Kudo

bradawk1
Trusted Contributor

Re: OneView REST API add server to rack

thanks.  I'll work on that.

bradawk1
Trusted Contributor

Re: OneView REST API add server to rack

Unfortunately,

POST /rest/racks/{rackId}/rack-mounts

did not work.  Get http_404 error.  I also did not find that in the REST API reference anywhere.  Good idea though. 

What I tried, but did not work (the rack info was already added):

RNAME="RACK1"
RURI=$(curl --insecure --silent --header "X-API-Version: ${currentVersion}" --header "auth: ${sessionID}" --request GET ${OneView}/rest/racks | jq -r '.members[] | select(.name == "'${RNAME}'") | .uri' | cut -d/ -f4)
RDATA=$((curl --insecure --silent --header "X-API-Version: ${currentVersion}" --header "auth: ${sessionID}" --request GET ${OneView}/rest/racks/${RURI} | jq -c '.')
# Add a mount location:
RDATA=$(echo ${RDATA} | jq -r '.rackMounts[.rackMounts| length] |= . + {"location":"CenterBack","topUSlot":17,"uHeight":2}')
# The updated RDATA looks good.
curl --insecure --silent --header "X-API-Version: ${currentVersion}" --header "auth: ${sessionID}"  \
--header "content-type: application/json" --data "${RDATA}" --request PUT ${OneView}/rest/racks/${RURI} | jq -r '.'

I get back:

Please contact your authorized support representative and provide them with a support dump.  ERM100

bradawk1
Trusted Contributor

Re: OneView REST API add server to rack

I thought maybe there was a problem with modifying a rack once it was added.  So, I attempted to add a rack with all of its mount positions defined:

RACK='rack3'
DATA='{"name":"'${RACK}'","depth":1660,"height":2295,"width":600,"model":48U Rack","partNumber":"Q7G92A","uHeight":48}'
# Add in server locations.  Have 4 DL385s:
for U in {2..8..2}; do
   DATA=$(echo ${DATA} | jq -r '.rackMounts[.rackMounts| length] |= . + {"location":"CenterBack","topUSlot":'${U}',"uHeight":2}')
done
# Add in the first group of XL225n's
for U in {10..20..2}; do
   DATA=$(echo ${DATA} | jq -r '.rackMounts[.rackMounts| length] |= . + {"location":"CenterBack","topUSlot":'${U}',"uHeight":2}')
done
# Add in second group of XL225n's
for U in {28..48..2}; do
   DATA=$(echo ${DATA} | jq -r '.rackMounts[.rackMounts| length] |= . + {"location":"CenterBack","topUSlot":'${U}',"uHeight":2}')
done
# Now, add in the rack:
curl --insecure --silent \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --header "content-type: application/json" \
     --data ${DATA} \
     --request POST ${OneView}/rest/racks | jq -r '.'

but that still gives back the ERM100 error message.

It also raises the question of how to specify the positions of the four servers contained in a single XL225n?  The only allowed values for the location field, are: CenterBack, CenterFron, Left, and Right.  Maybe need to add: TopRight, TopLeft, BottomRight, and BottomLeft?