/VirtualMachine/NetworkInterface/Usage.php
PHP | 218 lines | 135 code | 18 blank | 65 comment | 17 complexity | 5906d36aad933fd298ab6e9ebe882c2e MD5 | raw file
- <?php
- /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
- /**
- * VM Backups
- *
- * @category API wrapper
- * @package OnApp
- * @subpackage VirtualMachine_NetworkInterface
- * @author Yuriy Yakubskiy
- * @copyright (c) 2011 OnApp
- * @link http://www.onapp.com/
- * @see OnApp
- */
- /**
- * VM Network Interface Usage
- *
- * This class represents the VM Network Interface Usage.
- *
- * The OnApp_VirtualMachine_NetworkInterface_Usage class uses the following basic methods:
- * {@link load}, {@link getList}.
- *
- * For full fields reference and curl request details visit: ( http://help.onapp.com/manual.php?m=2 )
- */
- class OnApp_VirtualMachine_NetworkInterface_Usage extends OnApp {
- /**
- * root tag used in the API request
- *
- * @var string
- */
- var $_tagRoot = 'net_hourly_stat';
- /**
- * alias processing the object data
- *
- * @var string
- */
- var $_resource = 'usage';
- public function __construct() {
- parent::__construct();
- $this->className = __CLASS__;
- }
- /**
- * API Fields description
- *
- * @param string|float $version OnApp API version
- * @param string $className current class' name
- *
- * @return array
- */
- public function initFields( $version = null, $className = '' ) {
- switch( $version ) {
- case '2.0':
- case '2.1':
- case '2.2':
- case '2.3':
- $this->fields = array(
- 'id' => array(
- ONAPP_FIELD_MAP => '_id',
- ONAPP_FIELD_TYPE => 'integer',
- ONAPP_FIELD_READ_ONLY => true
- ),
- 'created_at' => array(
- ONAPP_FIELD_MAP => '_created_at',
- ONAPP_FIELD_TYPE => 'datetime',
- ONAPP_FIELD_READ_ONLY => true,
- ),
- 'updated_at' => array(
- ONAPP_FIELD_MAP => '_updated_at',
- ONAPP_FIELD_TYPE => 'datetime',
- ONAPP_FIELD_READ_ONLY => true,
- ),
- 'data_received' => array(
- ONAPP_FIELD_MAP => '_data_received',
- ONAPP_FIELD_TYPE => 'integer',
- ONAPP_FIELD_READ_ONLY => true,
- ),
- 'data_sent' => array(
- ONAPP_FIELD_MAP => '_data_sent',
- ONAPP_FIELD_TYPE => 'integer',
- ONAPP_FIELD_READ_ONLY => true,
- ),
- 'user_id' => array(
- ONAPP_FIELD_MAP => '_user_id',
- ONAPP_FIELD_TYPE => 'integer',
- ONAPP_FIELD_READ_ONLY => true,
- ),
- 'network_interface_id' => array(
- ONAPP_FIELD_MAP => '_network_interface_id',
- ONAPP_FIELD_TYPE => 'integer',
- ONAPP_FIELD_READ_ONLY => true,
- ),
- 'virtual_machine_id' => array(
- ONAPP_FIELD_MAP => '_virtual_machine_id',
- ONAPP_FIELD_TYPE => 'integer',
- ONAPP_FIELD_READ_ONLY => true,
- )
- );
- break;
- case 3.0:
- case 3.1:
- case 3.2:
- $this->fields = $this->initFields( 2.3 );
- break;
- }
- parent::initFields( $version, __CLASS__ );
- return $this->fields;
- }
- /**
- * Returns the URL Alias of the API Class that inherits the OnApp class
- *
- * @param string $action action name
- *
- * @return string API resource
- * @access public
- */
- function getResource( $action = ONAPP_GETRESOURCE_DEFAULT ) {
- $show_log_msg = true;
- switch( $action ) {
- case ONAPP_GETRESOURCE_DEFAULT:
- /**
- * ROUTE :
- * @name virtual_machine_backups
- * @method GET
- * @alias /virtual_machines/:virtual_machine_id/backups(.:format)
- * @format {:controller=>"backups", :action=>"index"}
- */
- if( is_null( $this->_virtual_machine_id ) && is_null( $this->_obj->_virtual_machine_id ) ) {
- $this->logger->error(
- 'getResource( ' . $action . ' ): argument _virtual_machine_id not set.',
- __FILE__,
- __LINE__
- );
- }
- else {
- if( is_null( $this->_virtual_machine_id ) ) {
- $this->_virtual_machine_id = $this->_obj->_virtual_machine_id;
- }
- }
- if( is_null( $this->_network_interface_id ) && is_null( $this->_obj->_network_interface_id ) ) {
- $this->logger->error(
- 'getResource( ' . $action . ' ): argument _network_interface_id not set.',
- __FILE__,
- __LINE__
- );
- }
- else {
- if( is_null( $this->_network_interface_id ) ) {
- $this->_network_interface_id = $this->_obj->_network_interface_id;
- }
- }
- $resource = 'virtual_machines/' . $this->_virtual_machine_id . '/network_interfaces/' . $this->_network_interface_id . '/' . $this->_resource;
- break;
- default:
- $resource = parent::getResource( $action );
- break;
- }
- if( $show_log_msg ) {
- $this->logger->debug( 'getResource( ' . $action . ' ): return ' . $resource );
- }
- return $resource;
- }
- /**
- * Sends an API request to get the Objects. After requesting,
- * unserializes the received response into the array of Objects
- *
- * @param integer $virtual_machine_id Virtual Machine id
- * @param integer $network_interface_id Network Interface id
- *
- * @return mixed an array of Object instances on success. Otherwise false
- * @access public
- */
- function getList( $virtual_machine_id = null, $network_interface_id = null, $url_args = '' ) {
- if( is_null( $virtual_machine_id ) && ! is_null( $this->_virtual_machine_id ) ) {
- $virtual_machine_id = $this->_virtual_machine_id;
- }
- if( ! is_null( $virtual_machine_id ) ) {
- $this->_virtual_machine_id = $virtual_machine_id;
- }
- else {
- $this->logger->error(
- 'getList: argument _virtual_machine_id not set.',
- __FILE__,
- __LINE__
- );
- }
- if( is_null( $network_interface_id ) && ! is_null( $this->_network_interface_id ) ) {
- $network_interface_id = $this->_network_interface_id;
- }
- if( ! is_null( $network_interface_id ) ) {
- $this->_network_interface_id = $network_interface_id;
- }
- else {
- $this->logger->error(
- 'getList: argument _network_interface_id not set.',
- __FILE__,
- __LINE__
- );
- }
- return parent::getList( null, $url_args );
- }
- }