<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: REST API getting list of current hardware in HPE OneView</title>
    <link>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053514#M4347</link>
    <description>&lt;P&gt;Couldn't come up with a clean method to concatenate programatically, but did it just be looking at how many hardware output files there were.&amp;nbsp; This will get them into a json formatted file.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&amp;amp;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 &amp;gt; hardw-all-raw
cat hardw-all-raw | jq -r '.' &amp;gt; hardw-all&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you have the full hardware list, can then get a listing of the different hardware types with:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&lt;/LI-CODE&gt;&lt;P&gt;Hopefully that will help someone else.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2019 16:44:36 GMT</pubDate>
    <dc:creator>BradV</dc:creator>
    <dc:date>2019-07-03T16:44:36Z</dc:date>
    <item>
      <title>REST API getting list of current hardware</title>
      <link>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053139#M4332</link>
      <description>&lt;P&gt;I'm working towards creating server profile templates.&amp;nbsp; In order to do that, I need to get a current listing of all hardware types.&amp;nbsp; That call is only pulling back 32 and not all.&amp;nbsp; I am using:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&amp;amp;count=-1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought by adding count=-1 that was supposed to return all?&amp;nbsp; (I am using API version 1000).&amp;nbsp; Anyone have a clue what I am doing wrong?&lt;/P&gt;&lt;P&gt;FYI, I changed the count from -1, to 20, 200, 1000 and it always just returns 32 servers.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:32:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053139#M4332</guid>
      <dc:creator>BradV</dc:creator>
      <dc:date>2019-07-01T13:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: REST API getting list of current hardware</title>
      <link>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053173#M4333</link>
      <description>&lt;P&gt;What you are getting is a paginated return.&amp;nbsp; We limit the number of objects on the return, so that it does not overwhelm the appliance.&amp;nbsp; So, you need to look at the &lt;FONT face="courier new,courier"&gt;nextPageUri&lt;/FONT&gt; value if it is not null or empty.&amp;nbsp; If it has a value, make a looping call until it is, storing each array of &lt;FONT face="courier new,courier"&gt;members&lt;/FONT&gt; into a new local copy of all members.&lt;/P&gt;&lt;P&gt;Just to reiterate a prior statement of mine, our scripting tool kits would handle a lot of this for you automatically.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 14:41:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053173#M4333</guid>
      <dc:creator>ChrisLynch</dc:creator>
      <dc:date>2019-07-01T14:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: REST API getting list of current hardware</title>
      <link>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053200#M4334</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;OK.&amp;nbsp; Thanks.&amp;nbsp; That helped.&amp;nbsp; I can now get them all with:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&amp;amp;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&lt;/LI-CODE&gt;&lt;P&gt;I just need to then concatenate to a single file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to make openview-python work, but not having a lot of luck yet.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:35:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053200#M4334</guid>
      <dc:creator>BradV</dc:creator>
      <dc:date>2019-07-01T18:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: REST API getting list of current hardware</title>
      <link>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053514#M4347</link>
      <description>&lt;P&gt;Couldn't come up with a clean method to concatenate programatically, but did it just be looking at how many hardware output files there were.&amp;nbsp; This will get them into a json formatted file.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&amp;amp;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 &amp;gt; hardw-all-raw
cat hardw-all-raw | jq -r '.' &amp;gt; hardw-all&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you have the full hardware list, can then get a listing of the different hardware types with:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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&lt;/LI-CODE&gt;&lt;P&gt;Hopefully that will help someone else.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 16:44:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7053514#M4347</guid>
      <dc:creator>BradV</dc:creator>
      <dc:date>2019-07-03T16:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: REST API getting list of current hardware</title>
      <link>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7075216#M4858</link>
      <description>&lt;P&gt;Updated my procedure a little to programmaticaly concatenate the different intermediate files:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 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}) &amp;gt; hardw-all-raw
# Now process into a readable json format:
cat hardw-all-raw | jq -r '.' &amp;gt; hardw-all
# Clean up
/bin/rm hardw hardw? hardw-all-raw&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Jan 2020 10:49:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-oneview/rest-api-getting-list-of-current-hardware/m-p/7075216#M4858</guid>
      <dc:creator>BradV</dc:creator>
      <dc:date>2020-01-09T10:49:50Z</dc:date>
    </item>
  </channel>
</rss>

