4 Replies Latest reply: Apr 14, 2016 8:12 AM by Jeffrey Adams RSS

    Rest API Get Snapshot Collection: Cannot index into a null array.

    Jeffrey Adams Wayfarer

      Hi All.

       

      I have a powershell script using the REST API to refresh dev/qa environments.

      The refresh has been working great for some time.  All of the sudden today I had 2 machines fail with  Cannot index into a null array.

      Here is the snippet of code:

       

      $prod_array = @();

      $ProdVolume_array = @();

      $topsnapshot_array = @();

      $uri = "https://" + $ArrayIP + "snapshot_collections/detail"

      $snaplist = Invoke-RestMethod -Uri $uri -Method get -Header $header

      $prod_array += $snaplist.data 

      $ProdVolume_array = $prod_array | select snapshots_list, name, creation_time |where-object name -like $ProdVolumeCollection* | sort-object -Property creation_time -descending

      $topsnapshot_array = $ProdVolume_array[0].snapshots_list


      $snaplist does have information in it.  when I look at $prod_array and $ProdVolume_array I see nothing.  I don't understand why.

       

      Thanks,

      Jeff

        • Re: Rest API Get Snapshot Collection: Cannot index into a null array.
          Julian Cates Adventurer

          Hey Jeff,

           

          Are you certain that $snaplist contains valid data?  Depending on what value $ArrayIP has, I see a potential error. If it's simply the IP/hostname of the array as I expect it might be, then I suggest that you change this line:

           

          $uri = "https://" + $ArrayIP + "snapshot_collections/detail"


          to instead be


          $uri = "https://" + $ArrayIP + ":5392/v1/snapshot_collections/detail"

           

          Otherwise, when you invoke the API in the following line, you are likely to get an error. The only other thing that jumps out is that I don't know what $ProdVolumeCollection looks like here. If it's invalid, then $ProdVolume_array would wind up being empty.

           

          Cheers,

           

          Julian

            • Re: Rest API Get Snapshot Collection: Cannot index into a null array.
              Raja Shekar Chelur Adventurer

              Not sure about the snapshot_collections failure, but the snapshots object failed with this error:

               

              Invoke-RestMethod : The remote server returned an error: (400) Bad Request.


              snapshots objectset does not support listing all objects. The complete response for this error would be some thing like this:


              {

                 "messages":[

                    {

                       "code":"SM_http_bad_request",

                       "text":"The request could not be understood by the server."

                    },

                    {

                       "code":"SM_missing_arg",

                       "arguments":{

                          "arg":"vol_id"

                       },

                       "text":"Missing the argument 'vol_id' in the request."

                    }

                 ]

              }


              You will have to provide the id of a particular volume to list the snapshots. For e.g. you can use a query URL like this:


              https://<array-ip>:5392/v1/snapshots/detail?vol_id=0611f49156c08fdc81000000000000000000000007

            • Re: Rest API Get Snapshot Collection: Cannot index into a null array.
              Jeffrey Adams Wayfarer

              I may have found the problem:

               

              changing

               

              $ProdVolume_array = $prod_array | select snapshots_list, name, creation_time |where-object name -like $ProdVolumeCollection* | sort-object -Property creation_time -descending


              to:

               

              $ProdVolume_array = $prod_array | select * |where-object volcoll_name -eq $ProdVolumeCollection | sort-object -Property creation_time -descending


              In some local testing this appears to take care of the issue, but I need to validate.


              I'm still not sure why it all of the sudden failed.