API Documentation RunningExamples server.get possible os images PHP

Aus EUserv Wiki

(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
 
Zeile 3: Zeile 3:
   <nowiki>
   <nowiki>
<?php
<?php
 +
//includes the class library
//includes the class library
include_once("lib/xmlrpc.inc");
include_once("lib/xmlrpc.inc");
$xmlrpc_internalencoding = 'UTF-8';
$xmlrpc_internalencoding = 'UTF-8';
 +
$host="api.test.euserv.net";
$host="api.test.euserv.net";
$port=443;
$port=443;
Zeile 12: Zeile 14:
$api_path="/";
$api_path="/";
$srv_id=1337;
$srv_id=1337;
 +
//defines the function
//defines the function
function server_get_possible_os_images($host,$port,$username,$password,$api_path,$srv_id)
function server_get_possible_os_images($host,$port,$username,$password,$api_path,$srv_id)
{
{
-
//creates the serverurl
+
 
-
$serverurl = 'https://'.$host.':'.$port.'/'.$api_path;
+
  //creates the serverurl
-
//----------creates the message which will be send to the server----------
+
  $serverurl = 'https://'.$host.':'.$port.'/'.$api_path;
-
//creates the request for the XML-RPC Server
+
 
-
$request = new xmlrpcmsg('server.get_possible_os_images');
+
  //----------creates the message which will be send to the server----------
-
//adds parameters to the request
+
 
-
$request->addParam
+
  //creates the request for the XML-RPC Server
-
(
+
  $request = new xmlrpcmsg('server.get_possible_os_images');
-
//creates a value of type struct which contains an array with the username and password
+
  //adds parameters to the request
-
new xmlrpcval
+
  $request->addParam
-
(
+
    (
-
array
+
   
-
(
+
    //creates a value of type struct which contains an array with the username and password
-
//creates a value of type string which contains the "$username"
+
    new xmlrpcval
-
'login' => new xmlrpcval($username, 'string'),
+
      (
-
//creates a value of type string which contains the "$password"
+
      array
-
'password' => new xmlrpcval($password, 'string'),
+
 
-
//creates a value of type string which contains the "$srv_id"
+
      (
-
'srv_id' => new xmlrpcval($srv_id, 'int'),
+
        //creates a value of type string which contains the "$username"
-
)
+
        'login' => new xmlrpcval($username, 'string'),
-
,'struct'
+
       
-
)
+
        //creates a value of type string which contains the "$password"
-
);
+
        'password' => new xmlrpcval($password, 'string'),
-
//----------creates the XML-RPC client which represents a client of a XML-RPC server----------
+
     
-
//creates the client
+
        //creates a value of type string which contains the "$srv_id"
-
$client = new xmlrpc_client($serverurl);
+
        'srv_id' => new xmlrpcval($srv_id, 'int'),
-
//disable SSL Keycheck
+
     
-
$client->setSSLVerifyPeer(0);
+
      )
-
//----------sends the request to the server and gets the response----------
+
      ,'struct'
-
//sends the request via https and writes it into $response. timeout is set to 0
+
      )
-
$response = $client->send($request,0,'https');
+
    );
-
//generates a storable representation of $response and writes it into $result_xml
+
 
-
//echo $response->serialize();
+
  //----------creates the XML-RPC client which represents a client of a XML-RPC server----------
-
//checks the response. if the method "faultCode" returns zero, the response was succesfull
+
 
-
if (0==$response->faultCode())
+
  //creates the client
-
{
+
  $client = new xmlrpc_client($serverurl);
-
//returns the value sent by the server
+
 
-
$value = $response->value();
+
  //disable SSL Keycheck
-
//returns the actual PHP-language value of "value"
+
  $client->setSSLVerifyPeer(0);
-
$result_obj = $value->scalarval();
+
 
-
//destroys "value"
+
  //----------sends the request to the server and gets the response----------
-
unset($value);
+
 
-
}
+
  //sends the request via https and writes it into $response. timeout is set to 0
-
else
+
  $response = $client->send($request,0,'https');
-
{
+
 
-
//returns the faultCode and the faultString
+
  //generates a storable representation of $response and writes it into $result_xml
-
return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString());
+
  //echo $response->serialize();
-
}
+
 
-
//destroys "client"
+
  //checks the response. if the method "faultCode" returns zero, the response was succesfull
-
unset($client);
+
  if (0==$response->faultCode())  
-
//destroys "response"
+
  {
-
unset($response);
+
    //returns the value sent by the server
-
//----------reads the result_obj----------
+
    $value = $response->value();
-
//if result_obj is set then it returns the actual PHP-language value of "result_obj"
+
     
-
if (isset($result_obj['status']))
+
    //returns the actual PHP-language value of "value"
-
{
+
    $result_obj = $value->scalarval();
-
$value['status'] = $result_obj['status']->scalarval();
+
     
-
}
+
    //destroys "value"
-
if (isset($result_obj['os_images_asoc_array']))
+
    unset($value);    
-
{
+
  }
-
//reads the data
+
  else
-
while (list($os_images, $data) = $result_obj['os_images_asoc_array']->structEach())
+
  {
-
{
+
    //returns the faultCode and the faultString
-
//gets the "os_images"
+
    return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString());
-
$data = $data->scalarval();
+
  }
-
//reads the value of each member and writes it into an array
+
   
-
$os_images_asoc_array[$os_images]['os_id'] = $data['os_id']->scalarval();
+
  //destroys "client"
-
$os_images_asoc_array[$os_images]['os_status'] = $data['os_status']->scalarval();
+
  unset($client);
-
$os_images_asoc_array[$os_images]['os_name'] = $data['os_name']->scalarval();
+
   
-
$os_images_asoc_array[$os_images]['os_is_64bit'] = $data['os_is_64bit']->scalarval();
+
  //destroys "response"
-
$os_images_asoc_array[$os_images]['os_raidlevel'] = $data['os_raidlevel']->scalarval();
+
  unset($response);
-
}
+
  //----------reads the result_obj----------
-
//writes the array into the array "value"
+
   
-
$value['os_images_asoc_array'] = $os_images_asoc_array;
+
  //if result_obj is set then it returns the actual PHP-language value of "result_obj"
-
}
+
   
-
return $value;
+
  if (isset($result_obj['status']))
 +
  {
 +
    $value['status'] = $result_obj['status']->scalarval();
 +
  }
 +
 
 +
  if (isset($result_obj['os_images_asoc_array']))
 +
  {
 +
  //reads the data
 +
   
 +
    while (list($os_images, $data) = $result_obj['os_images_asoc_array']->structEach())
 +
    {
 +
      //gets the "os_images"
 +
      $data = $data->scalarval();
 +
   
 +
      //reads the value of each member and writes it into an array
 +
      $os_images_asoc_array[$os_images]['os_id'] = $data['os_id']->scalarval();
 +
      $os_images_asoc_array[$os_images]['os_status'] = $data['os_status']->scalarval();
 +
      $os_images_asoc_array[$os_images]['os_name'] = $data['os_name']->scalarval();
 +
      $os_images_asoc_array[$os_images]['os_is_64bit'] = $data['os_is_64bit']->scalarval();
 +
      $os_images_asoc_array[$os_images]['os_raidlevel'] = $data['os_raidlevel']->scalarval();
 +
   
 +
    }
 +
   
 +
  //writes the array into the array "value"
 +
  $value['os_images_asoc_array'] = $os_images_asoc_array;
 +
  }
 +
  return $value;  
}
}
 +
//calls the function
//calls the function
$result = server_get_possible_os_images($host,$port,$username,$password,$api_path,$srv_id);
$result = server_get_possible_os_images($host,$port,$username,$password,$api_path,$srv_id);
 +
if(0==$result['faultCode'])
if(0==$result['faultCode'])
{
{
-
echo "Status: ".$result['status']."<br><br>";
+
  echo "Status: ".$result['status']."<br><br>";
-
//writes the array "os_images_asoc_array" into "daten"
+
 
-
$daten = $result["os_images_asoc_array"];
+
  //writes the array "os_images_asoc_array" into "daten"
-
//gets the array_keys(members) of "daten"
+
  $daten = $result["os_images_asoc_array"];
-
$datenkeys = array_keys($daten);
+
 
-
$k=0;
+
  //gets the array_keys(members) of "daten"
-
//counts the arraykeys, the number of arraykeys will be used in the do-while construct
+
  $datenkeys = array_keys($daten);
-
$anzahlkeys = count($datenkeys);
+
  $k=0;
-
do
+
 
-
{
+
  //counts the arraykeys, the number of arraykeys will be used in the do-while construct
-
//outputs the data
+
  $anzahlkeys = count($datenkeys);
-
echo " <u>os_id:</u> ".$daten[$datenkeys[$k]]['os_id'];
+
 
-
echo " <u>os_status:</u> ".$daten[$datenkeys[$k]]['os_status'];
+
  do
-
echo " <u>os_name:</u> ".$daten[$datenkeys[$k]]['os_name'];
+
  {
-
echo " <u>os_is_64bit:</u> ".$daten[$datenkeys[$k]]['os_is_64bit'];
+
    //outputs the data
-
echo " <u>os_raidlevel:</u> ".$daten[$datenkeys[$k]]['os_raidlevel'];
+
    echo " <u>os_id:</u> ".$daten[$datenkeys[$k]]['os_id'];
-
echo "<br>";
+
    echo " <u>os_status:</u> ".$daten[$datenkeys[$k]]['os_status'];
-
$k=$k+1;
+
    echo " <u>os_name:</u> ".$daten[$datenkeys[$k]]['os_name'];
-
}
+
    echo " <u>os_is_64bit:</u> ".$daten[$datenkeys[$k]]['os_is_64bit'];
-
while($k<$anzahlkeys);
+
    echo " <u>os_raidlevel:</u> ".$daten[$datenkeys[$k]]['os_raidlevel'];
 +
    echo "<br>";
 +
    $k=$k+1;
 +
 
 +
  }
 +
  while($k<$anzahlkeys);
}
}
else
else
{
{
-
echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString'];
+
  echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString'];
}
}
?>
?>
   </nowiki>
   </nowiki>

Aktuelle Version vom 07:29, 6. Sep. 2012

back to API Documentation

server.get_possible_os_images

 
<?php

//includes the class library
include_once("lib/xmlrpc.inc");
$xmlrpc_internalencoding = 'UTF-8';

$host="api.test.euserv.net";
$port=443;
$username="<API_USER>";
$password="<API_USER_PASSWORD>";
$api_path="/";
$srv_id=1337;

//defines the function
function server_get_possible_os_images($host,$port,$username,$password,$api_path,$srv_id)
{

  //creates the serverurl
  $serverurl = 'https://'.$host.':'.$port.'/'.$api_path;

  //----------creates the message which will be send to the server----------

  //creates the request for the XML-RPC Server
  $request = new xmlrpcmsg('server.get_possible_os_images');
  //adds parameters to the request
  $request->addParam
    (
    
    //creates a value of type struct which contains an array with the username and password
    new xmlrpcval
      (
      array

      (
        //creates a value of type string which contains the "$username"
        'login' => new xmlrpcval($username, 'string'),
        
        //creates a value of type string which contains the "$password"
        'password' => new xmlrpcval($password, 'string'),
      
        //creates a value of type string which contains the "$srv_id"
        'srv_id' => new xmlrpcval($srv_id, 'int'),
      
      )
      ,'struct'
      )
    );

  //----------creates the XML-RPC client which represents a client of a XML-RPC server----------

  //creates the client
  $client = new xmlrpc_client($serverurl);
  
  //disable SSL Keycheck
  $client->setSSLVerifyPeer(0);
  
  //----------sends the request to the server and gets the response----------

  //sends the request via https and writes it into $response. timeout is set to 0
  $response = $client->send($request,0,'https');
  
  //generates a storable representation of $response and writes it into $result_xml
  //echo $response->serialize();
  
  //checks the response. if the method "faultCode" returns zero, the response was succesfull
  if (0==$response->faultCode()) 
  {
    //returns the value sent by the server
    $value = $response->value();
      
    //returns the actual PHP-language value of "value"
    $result_obj = $value->scalarval();
      
    //destroys "value"
    unset($value);      
  }
  else
  {
    //returns the faultCode and the faultString
    return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString());
  }
    
  //destroys "client"
  unset($client);
    
  //destroys "response"
  unset($response);  
  //----------reads the result_obj----------
    
  //if result_obj is set then it returns the actual PHP-language value of "result_obj"
    
  if (isset($result_obj['status']))
  {
    $value['status'] = $result_obj['status']->scalarval();
  }

  if (isset($result_obj['os_images_asoc_array']))
  {  
  //reads the data
    
    while (list($os_images, $data) = $result_obj['os_images_asoc_array']->structEach())
    {
      //gets the "os_images"
      $data = $data->scalarval();
    
      //reads the value of each member and writes it into an array
      $os_images_asoc_array[$os_images]['os_id'] = $data['os_id']->scalarval();
      $os_images_asoc_array[$os_images]['os_status'] = $data['os_status']->scalarval();
      $os_images_asoc_array[$os_images]['os_name'] = $data['os_name']->scalarval();
      $os_images_asoc_array[$os_images]['os_is_64bit'] = $data['os_is_64bit']->scalarval();
      $os_images_asoc_array[$os_images]['os_raidlevel'] = $data['os_raidlevel']->scalarval();
    
    }
    
  //writes the array into the array "value"
  $value['os_images_asoc_array'] = $os_images_asoc_array;
  }  
  return $value;    
}

//calls the function
$result = server_get_possible_os_images($host,$port,$username,$password,$api_path,$srv_id);

if(0==$result['faultCode'])
{
  echo "Status: ".$result['status']."<br><br>";

  //writes the array "os_images_asoc_array" into "daten"
  $daten = $result["os_images_asoc_array"];

  //gets the array_keys(members) of "daten"
  $datenkeys = array_keys($daten);
  $k=0;
  
  //counts the arraykeys, the number of arraykeys will be used in the do-while construct
  $anzahlkeys = count($datenkeys);

  do
  {
    //outputs the data
    echo " <u>os_id:</u> ".$daten[$datenkeys[$k]]['os_id'];
    echo " <u>os_status:</u> ".$daten[$datenkeys[$k]]['os_status'];
    echo " <u>os_name:</u> ".$daten[$datenkeys[$k]]['os_name'];
    echo " <u>os_is_64bit:</u> ".$daten[$datenkeys[$k]]['os_is_64bit'];
    echo " <u>os_raidlevel:</u> ".$daten[$datenkeys[$k]]['os_raidlevel'];
    echo "<br>";
    $k=$k+1;

  }
  while($k<$anzahlkeys);
}
else
{
  echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString'];
}
?>