Get HPE 3PAR/Primera Details

				
					// 3PAR System Details https://[3PAR IP]:8080/api/v1/system
// 3PAR cpg Details https://[3PAR IP]:8080/api/v1/cpgs
// 3PAR Hosts Details https://[3PAR IP]:8080/api/v1/hosts
// 3PAR Hostsets Details https://[3PAR IP]:8080/api/v1/hostsets
// 3PAR Volumes Details https://[3PAR IP]:8080/api/v1/volumes

public function get_StoreServ_Array_Details($IPv4Addr, $Username, $Password)
    {
      $comment = '';
      $contact = '';
      // Before you get any data from 3PAR you need to get a session key.
      $Session_Key = get_session_key($IPv4Addr, $Username, $Password);
      $API_Dir = "system";
      $SS_Array_Rest = new StoreServeRest;
      $SS_Response = Get_StoreServe_Details($IPv4Addr, $Session_Key, $API_Dir);
      $content = '';

      foreach($SS_Response as $key => $value)
      {
        if(is_array($value))
        {
            $value = 'ARRAY!';
        }

        if ($key == "name") {
            $name = $value;
        } elseif ($key == "systemVersion") {
            $systemVersion = $value;
        } elseif ($key == "patches") {
            $patches = $value;
        } elseif ($key == "IPv4Addr") {
            $IPv4Addr = $value;
        } elseif ($key == "model") {
            $model = $value;
        } elseif ($key == "serialNumber") {
            $serialNumber = $value;
        } elseif ($key == "totalNodes") {
            $totalNodes = $value;
        } elseif ($key == "masterNode") {
            $masterNode = $value;
        } elseif ($key == "onlineNodes") {
            $onlineNodes = $value;
        } elseif ($key == "clusterNodes") {
            $clusterNodes = $value;
        } elseif ($key == "chunkletSizeMiB") {
            $chunkletSizeMiB = $value;
        } elseif ($key == "totalCapacityMiB") {
            $totalCapacityMiB = $value;
            $totalCapacityGiB = $totalCapacityMiB / 1024;
            $totalCapacityTiB = $totalCapacityGiB / 1024;
        } elseif ($key == "allocatedCapacityMiB") {
            $allocatedCapacityMiB = $value;
            $allocatedCapacityGiB = $allocatedCapacityMiB / 1024;
            $allocatedCapacityTiB = $allocatedCapacityGiB / 1024;
        } elseif ($key == "freeCapacityMiB") {
            $freeCapacityMiB = $value;
            $freeCapacityGiB = $freeCapacityMiB / 1024;
            $freeCapacityTiB = $freeCapacityGiB / 1024;
        } elseif ($key == "failedCapacityMiB") {
            $failedCapacityMiB = $value;
        } elseif ($key == "contact") {
            $contact = $value;
        } elseif ($key == "comment") {
            $comment = $value;
        } elseif ($key == "timeZone") {
            $timeZone = $value;
        } elseif ($key == "licenseInfo") {
            $licenseInfo = $value;
        } elseif ($key == "parameters") {
            $parameters = $value;
        }
    }
}

function Get_StoreServe_Details($IPv4Addr, $Session_Key, $API_Dir)
{
     $contentType = "application/json -H";
     $wsapi_url = 'https://' . $IPv4Addr . ':8080/api/v1/' . $API_Dir;

     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $wsapi_url);

     curl_setopt($ch, CURLOPT_HTTPHEADER, Array('GET /api/v1/volumes HTTP/1.1')); // -H
     curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Accept: ' . $contentType));
     curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Accept-Language: en'));
     curl_setopt($ch, CURLOPT_HTTPHEADER, Array('X-HP3PAR-WSAPI-SessionKey: ' . $Session_Key));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //FALSE outputs the responce to the page - TRUE outputs responce to as string
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary
     curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

     $response = curl_exec($ch);
     $response = json_decode($response,true);

     return $response;
}


// Before you get any data from 3PAR you need to get a session key.

public static function get_session_key($ipaddr,$uname, $pword) {
    $data = '{"user":"'. $uname. '","password":"'. $pword . '"}';
    $contentType = "application/json";
    $wsapi_url = 'https://' . $ipaddr . ':8080/api/v1/credentials';
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$wsapi_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array('GET /api/v1/credentials HTTP/1.1 -H')); // -H
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Accept: ' . $contentType)); // -H
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //FALSE outputs the responce to the page - TRUE outputs responce to as string
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary
    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    $response = curl_exec($ch);

    curl_close($ch);

    $response = json_decode($response,true);

    foreach ($response as $key => $value) {
       return $value;
   }
}