- Community Home
- >
- Software
- >
- HPE OneView
- >
- REST API getting list of current hardware
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-01-2019 04:26 AM - edited 07-01-2019 06:32 AM
07-01-2019 04:26 AM - edited 07-01-2019 06:32 AM
I'm working towards creating server profile templates. In order to do that, I need to get a current listing of all hardware types. That call is only pulling back 32 and not all. I am using:
# First, get a list of all hardware:
HARDW=hardw
curl --insecure \
--header "auth: ${sessionID}" \
--header "X-API-Version: ${currentVersion}" \
--output ${HARDW} \
--request GET ${OneView}/rest/server-hardware?start=0&count=-1
I thought by adding count=-1 that was supposed to return all? (I am using API version 1000). Anyone have a clue what I am doing wrong?
FYI, I changed the count from -1, to 20, 200, 1000 and it always just returns 32 servers.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-01-2019 07:41 AM
07-01-2019 07:41 AM
Re: REST API getting list of current hardware
What you are getting is a paginated return. We limit the number of objects on the return, so that it does not overwhelm the appliance. So, you need to look at the nextPageUri value if it is not null or empty. If it has a value, make a looping call until it is, storing each array of members into a new local copy of all members.
Just to reiterate a prior statement of mine, our scripting tool kits would handle a lot of this for you automatically.
I am an HPE employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-01-2019 11:35 AM
07-01-2019 11:35 AM
Re: REST API getting list of current hardware
Hi Chris,
OK. Thanks. That helped. I can now get them all with:
# First, get a list of all hardware:
HARDW=hardw
curl --insecure \
--header "auth: ${sessionID}" \
--header "X-API-Version: ${currentVersion}" \
--output ${HARDW} \
--request GET ${OneView}/rest/server-hardware?start=0&count=-1
# That only pulls down the first 32. To get the rest, do:
i=1
NEXT=$(/bin/sed -e 's|^.*nextPageUri":"\(/rest/server-hardware.*\):,"prevPageUri.*|\1|' ${HARDW})
while [[ ${NEXT != *"null"* ]]; do
curl --insecure \
--header "auth: ${sessionID}" \
--header "X-API-Version: ${currentVersion}" \
--output ${HARDW}${i} \
--request GET ${OneView}${NEXT}
NEXT=$(/bin/sed -e 's|^.*nextPageUri":"\(/rest/server-hardware.*\):,"prevPageUri.*|\1|' ${HARDW}${i})
if [[ ${#NEXT} -gt 50 ]]; then
NEXT$(/bin/sed -e 's|^.*nextPageUri":\(.*\),"prevPageUri.*|\1|' ${HARDW}${i})
fi
((i++))
done
I just need to then concatenate to a single file.
I am trying to make openview-python work, but not having a lot of luck yet.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
07-03-2019 09:41 AM - edited 07-03-2019 09:44 AM
07-03-2019 09:41 AM - edited 07-03-2019 09:44 AM
SolutionCouldn't come up with a clean method to concatenate programatically, but did it just be looking at how many hardware output files there were. This will get them into a json formatted file.
# Follow instructions in: OneView-API_Get_Session_Credentials.txt
#
# To get a list of the current hardware, run:
# Create a variable pointing to a file to hold the hardware output:
HARDW=hardw
# Get the list of current server hardware:
curl --insecure \
--header "auth: ${sessionID}" \
--header "X-API-Version: ${currentVersion}" \
--output ${HARDW} \
--request GET ${OneView}/rest/server-hardware?start=0&count=-1
#
# That only pulls down 32 devices. Need to look for nextPageUri:
i=1
NEXT=$(/bin/sed -e 's|^.*nextPageUri":"\(/rest/server-hardware.*\)","prevPageUri.*|\1|' ${HARDW})
while [[ ${NEXT} != *"null"* ]]; do
curl --insecure \
--header "auth: ${sessionID}" \
--header "X-API-Version: ${currentVersion}" \
--output ${HARDW}${i} \
--request GET ${OneView}${NEXT}
NEXT=$(/bin/sed -e 's|^.*nextPageUri":"\(/rest/server-hardware.*\)","prevPageUri.*|\1|' ${HARDW}${i})
if [[ ${#NEXT} -gt 50 ]]; then
NEXT=$(/bin/sed -e 's|^.*nextPageUri":\(.*\)","prevPageUri.*|\1|' ${HARDW}${i})
fi
((i++))
done
cat ${HARDW} ${HARDW}1 ${HARDW}2 ${HARDW}3 ${HARDW}4 ${HARDW}5 > hardw-all-raw
cat hardw-all-raw | jq -r '.' > hardw-all
Once you have the full hardware list, can then get a listing of the different hardware types with:
# To get a list of server hardware type uri's:
RAW_DATA=$(grep -E 'serverHardwareTypeUri|model' hardw-all | sed -e 's|^\s\(.*\)$|\1' | sed -e '{$!{ N;s|","model|}}' | sed -e 's|": "|":"|g' | tr ' ' '_' |
sort -u)
i=0
declare -A HWR
for f in $(echo ${RAW_DATA}); do
echo "f = ${f}"
HWR[${i},0]=$(echo ${f} | cut -d ':' -f2 | cut -d ',' -f1)
HWR[${i},1]=$(echo ${f} | cut -d ':' -f3 | tr '_' ' ')
((i++))
done
Hopefully that will help someone else.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-09-2020 02:49 AM
01-09-2020 02:49 AM
Re: REST API getting list of current hardware
Updated my procedure a little to programmaticaly concatenate the different intermediate files:
# Need to know the number of iterations and build a command to concatentate all into a single file:
echo ${i}
j=0
while [[ $[j} -lt ${i} ]]; do
echo ${j}
if [[ ${j} -eq 0 ]]; then
CMD="cat ${HARDW}"
else
CMD="${CMD} ${HARDW}${j}"
fi
((j++))
done
echo ${CMD}
$(echo ${CMD}) > hardw-all-raw
# Now process into a readable json format:
cat hardw-all-raw | jq -r '.' > hardw-all
# Clean up
/bin/rm hardw hardw? hardw-all-raw
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP