vCloud Private Hosting: Using the vCloud SDK for PHP: Part 1

vCloud Private Hosting: Using the vCloud SDK for PHP: Part 1

If you are looking to set up your own vCloud Private Hosting and are looking to use the vCloud SDK with a language you are familiar with such as PHP, this post should help shed some light on the process. At Cloudhelix we make use of the vCloud SDK for various automation and reporting tasks. The good news is that customers can use it with their own vCD login in the same way.

Why would you want to do that? There are various reasons:

  • You may wish to write your own PHP applications for deploying vApps on demand.
  • You may wish to keep on top of your resource usage in line with your company’s reporting policies.
  • You may wish to add custom metadata entries to your vApps or virtual machines – we regularly poll the vCloud private hosting environment to record these, so if you would like your internal PO number for a virtual machine to show up on your bill (for example) we could arrange to look for the metadata value and add this automatically.

Future blog posts will go into particular configuration requirements in more depth – first, let’s quickly get things up and running to test with, using XAMPP on a CentOS 6.5 virtual machine.

NB: the versions below are correct at the time of writing, however feel free to check for updates and amend accordingly, if some time has passed.

  • XAMPP: https://www.apachefriends.org/download.html
  • PEAR: http://pear.php.net/

As always, while we are proceeding with simple settings for the sake of this demo, please review and choose settings in line with your organisation’s policies.

First, download and install XAMPP:

 
   
wget http://downloads.sourceforge.net/project/xampp/XAMPP%20Linux/1.8.3/xampp-linux-x64-1.8.3-4-installer.run
chmod +x xampp-linux-x64-1.8.3-4-installer.run
./xampp-linux-x64-1.8.3-4-installer.run

As shown, there is a simple setup wizard:

  • Run /opt/lampp/lampp security to set passwords.
  • If you want to test any webpages from outside the local LAN, edit theLocationMatch section of /opt/lampp/etc/extra/httpd-xampp.conf (or comment it out).
  • Start the service

 
   
ln -s /opt/lampp/lampp /etc/init.d/lampp
chkconfig lampp on
service lampp stop
service lampp startapache

The following are required by the vCloud SDK:

  • HTTP_Request2
  • Net_URL2

These can be added as follows:

 
   
wget http://download.pear.php.net/package/HTTP_Request2-2.2.1.tgz; wget http://download.pear.php.net/package/Net_URL2-2.0.5.tgz
tar -xzf HTTP*.tgz;tar -xzf Net*.tgz
mv HTTP_Request2-2.2.1/HTTP/Request2* /opt/lampp/lib/php/HTTP
mv Net_URL2-2.0.5/Net/URL2.php /opt/lampp/lib/php/Net

Ensure that your path is correct: export PATH=$PATH:/opt/lampp/bin/ – the PATH entry in ~/.bash_profile can be also be amended for future use.

Now, onto the reason we have done all this – download the vCloud SDK. The main page is here – the Download button should take you to a My VMware login page.

Once you have uploaded the file to your server:

 
   
tar -xzf vcloudPHP-*.tar.gz
mv vcloudPHP-5.5.0/library/VMware/ /opt/lampp/lib/php

You should now be ready to go! In this example, I am using the script inventory.php that is provided as a sample with the SDK download – because I am using a demo customer login, I have edited it and commented out the call to the provider resources function, which would require a system administrator login.

 
   
cd vcloudPHP-5.5.0/samples/
php inventory.php -s https://vcloud.cloudhelix.net -u cloudhelix-demo@cloudhelix-demo -p  -v 5.5

As shown in the warning, certificate validation should be used in a production environment as a best practice – this has not been included for the purposes of this demo.

However, as a basic test it has been successful – we have retrieved a list of the four vApps in this demo customer Org – a couple used for demonstrating the performance gains with flash-accelerated storage, the Cloudhelix half of the failover demo previously detailed here, and finally the server we have built for the purposes of this SDK demo.

Future posts in this series will cover more configuration examples – check back again soon!


你可能感兴趣的:(php,云端,vCloud)