php icontrol icr
1 TopicPHP and iControl REST
Problem this snippet solves: PHP and iControl REST interfaces Here are a couple of ways to use PHP and iControlREST (iCR). iCR is lighter-weight than iControl SOAP but is only supported on >= v11.5. When using these, check that the PHP implementation supports cURL using phpinfo() or check your php.ini file for 'extension=php_curl.dll' or the relevant name. I have included two ways to do this - via functions and via a PHP class. In practise the class is the simplest way to do this but the function seems to be the more efficient way of doing it. (Tested by retrieving ~700 Virtual Servers from a remote BIG-IP). Using the attached files you can save them and modify as required. Change the IP address 172.24.9.129 to be relevant to your setup. Note that the iCR class uses the default username/password admin/admin. Feel free to PM me if you have any specific requirements or issues. How to use this snippet: Example Class Usage: include("iCR_class.php"); $r = new iCR ("172.24.9.129"); echo "<html><body><pre>"; echo "<h2>Non-existent Virtual Server</h2><pre>"; print_r($r->get("/ltm/virtual/iCR_Test_VS")); echo $r->code; $vs = array('name'=>"iCR_Test_VS",'destination'=>'192.168.1.1:80','mask'=>'255.255.255.255','ipProtocol'=>'tcp'); echo "</pre><h2>Created Virtual Server</h2><pre>"; print_r($r->create("/ltm/virtual",$vs)); echo "</pre><h2>Edited Virtual Server</h2><pre>"; $description = array('description' => 'This is a modified Virtual Server'); # Use the PATCH method to update ( the true as the third variable ) print_r($r->modify("/ltm/virtual/iCR_Test_VS",$description,true)); echo "Modify HTTP Return Code: $r->code\n"; echo "</pre><h2>Deleted Virtual Server</h2><pre>"; print_r($r->delete("/ltm/virtual/iCR_Test_VS")); echo "Delete HTTP Return Code: $r->code\n"; print_r($r->get("/ltm/virtual/iCR_Test_VS")); echo "</pre></body></html>"; `</pre> Example Function Usage: include("iCR.php"); $hostname = "172.24.9.129"; $username = "admin"; $password = "admin"; $BIGIP_URL_BASE = "https://$hostname/mgmt/tm"; $url = $BIGIP_URL_BASE."/ltm/virtual"; $handle = curl_init(); echo "<html><body><h2><pre>"; echo "</pre><h2>Non-existent Virtual Server</h2><pre>"; print_r(iCR($handle,$username,$password,"GET",$url."/iCR_Test_VS")); // Create a Virtual Server echo "</pre><h2>Created Virtual Server</h2><pre>"; $vs = array('name'=>"iCR_Test_VS",'destination'=>'192.168.1.1:80','mask'=>'255.255.255.255','ipProtocol'=>'tcp'); print_r(iCR($handle,$username,$password,'POST',$url,$vs)); // Edit the Virtual Server echo "</pre><h2>Edited Virtual Server</h2><pre>"; $description = array('description' => 'This is a modified Virtual Server'); print_r(iCR($handle,$username,$password,'PUT',$url."/iCR_Test_VS",$description)); // Delete the Virtual Server echo "</pre><h2>Deleted Virtual Server</h2><pre>"; print_r(iCR($handle,$username,$password,"DELETE",$url."/iCR_Test_VS")); echo "</pre><h2>Post-delete Virtual Server</h2><pre>"; print_r(iCR($handle,$username,$password,"GET",$url."/iCR_Test_VS")); echo "</pre></body></html>";692Views0likes8Comments