PHP Wrapper

This wrapper enables you to make API calls from PHP applications. You can address the API directly by composing HTTP requests and processing responses using any tool you like, but the PHP wrapper abstracts this process to simplify integration in PHP environments. Please note that other integration modules now require the wrapper.

Latest version:

To start using a PHP wrapper, you need to include the following code into your application.  

Example
# Require Wrapper AutoLoad Class:

 <code>
      require_once '{Path to the Wrapper}/OnAppInit.php';
 </code>


# Get OnApp Instance:

 <code>
       $onapp = new OnApp_Factory('{IP Address / Hostname}', '{Username}', '{Password}');
 </code>


# Get OnApp_VirtualMachine Instance:

 <code>
       $vm_obj = $onapp->factory('VirtualMachine', {debug mode boolean, not required} );
 </code>


# Get the list of VMs:

 <code>
       $vms       = $vm_obj->getList();
 </code>


# Get a particular VM:

 <code>
       $vm       = $vm_obj->load({VM ID});
 </code>


# Create a VM:

 <code>
       $vm_obj->_label                 = '{VM Label}';
       $vm_obj->_memory                 = {VM RAM };
       $vm_obj->_cpu_shares             = {VM CPU priority};
       $vm_obj->_hostname             = '{Hostname}';
       $vm_obj->_cpus                 = {number of VM CPUs};
       $vm_obj->_primary_disk_size     = {VM Disk Space};
       $vm_obj->_swap_disk_size         = {VM Swap Size};
       $vm_obj->_template_id         = {VM Template ID};
       $vm_obj->_allowed_hot_migrate = {VM Hot Migrate Boolean Value};
       $vm_obj->save();
 </code>


# Edit a VM:

 <code>
       $vm_obj->_id = {VM ID};
       $vm_obj->_{Field You Want To Edit} = {New Value};

       $vm_obj->save();
 </code>


# Getting the debug log (depending the on debug mode):

 <code>
       print_r( $vm_obj );
 </code>

The first line of code that is require_once '{Path to the Wrapper}/OnAppInit.php' is a call to the OnAppInit.php file that automatically loads all the essential classes and dependencies. The next call allows to connect to a destination OnApp server instance via the OnApp_Factory class where:

  • {IP Address / Hostname} is a complete URL with a protocol, for example, https://onapp.instance.com

  • {Username} / {Password} are the credentials that you use to connect to the destination instance

After you are connected, you can call the available OnApp methods from your PHP application. For the full list of methods with the usage examples, see GitHub