PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/VirtualMachine/NetworkInterface/Usage.php

https://github.com/Spencerx/OnApp-PHP-Wrapper-External
PHP | 218 lines | 135 code | 18 blank | 65 comment | 17 complexity | 5906d36aad933fd298ab6e9ebe882c2e MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * VM Backups
  5. *
  6. * @category API wrapper
  7. * @package OnApp
  8. * @subpackage VirtualMachine_NetworkInterface
  9. * @author Yuriy Yakubskiy
  10. * @copyright (c) 2011 OnApp
  11. * @link http://www.onapp.com/
  12. * @see OnApp
  13. */
  14. /**
  15. * VM Network Interface Usage
  16. *
  17. * This class represents the VM Network Interface Usage.
  18. *
  19. * The OnApp_VirtualMachine_NetworkInterface_Usage class uses the following basic methods:
  20. * {@link load}, {@link getList}.
  21. *
  22. * For full fields reference and curl request details visit: ( http://help.onapp.com/manual.php?m=2 )
  23. */
  24. class OnApp_VirtualMachine_NetworkInterface_Usage extends OnApp {
  25. /**
  26. * root tag used in the API request
  27. *
  28. * @var string
  29. */
  30. var $_tagRoot = 'net_hourly_stat';
  31. /**
  32. * alias processing the object data
  33. *
  34. * @var string
  35. */
  36. var $_resource = 'usage';
  37. public function __construct() {
  38. parent::__construct();
  39. $this->className = __CLASS__;
  40. }
  41. /**
  42. * API Fields description
  43. *
  44. * @param string|float $version OnApp API version
  45. * @param string $className current class' name
  46. *
  47. * @return array
  48. */
  49. public function initFields( $version = null, $className = '' ) {
  50. switch( $version ) {
  51. case '2.0':
  52. case '2.1':
  53. case '2.2':
  54. case '2.3':
  55. $this->fields = array(
  56. 'id' => array(
  57. ONAPP_FIELD_MAP => '_id',
  58. ONAPP_FIELD_TYPE => 'integer',
  59. ONAPP_FIELD_READ_ONLY => true
  60. ),
  61. 'created_at' => array(
  62. ONAPP_FIELD_MAP => '_created_at',
  63. ONAPP_FIELD_TYPE => 'datetime',
  64. ONAPP_FIELD_READ_ONLY => true,
  65. ),
  66. 'updated_at' => array(
  67. ONAPP_FIELD_MAP => '_updated_at',
  68. ONAPP_FIELD_TYPE => 'datetime',
  69. ONAPP_FIELD_READ_ONLY => true,
  70. ),
  71. 'data_received' => array(
  72. ONAPP_FIELD_MAP => '_data_received',
  73. ONAPP_FIELD_TYPE => 'integer',
  74. ONAPP_FIELD_READ_ONLY => true,
  75. ),
  76. 'data_sent' => array(
  77. ONAPP_FIELD_MAP => '_data_sent',
  78. ONAPP_FIELD_TYPE => 'integer',
  79. ONAPP_FIELD_READ_ONLY => true,
  80. ),
  81. 'user_id' => array(
  82. ONAPP_FIELD_MAP => '_user_id',
  83. ONAPP_FIELD_TYPE => 'integer',
  84. ONAPP_FIELD_READ_ONLY => true,
  85. ),
  86. 'network_interface_id' => array(
  87. ONAPP_FIELD_MAP => '_network_interface_id',
  88. ONAPP_FIELD_TYPE => 'integer',
  89. ONAPP_FIELD_READ_ONLY => true,
  90. ),
  91. 'virtual_machine_id' => array(
  92. ONAPP_FIELD_MAP => '_virtual_machine_id',
  93. ONAPP_FIELD_TYPE => 'integer',
  94. ONAPP_FIELD_READ_ONLY => true,
  95. )
  96. );
  97. break;
  98. case 3.0:
  99. case 3.1:
  100. case 3.2:
  101. $this->fields = $this->initFields( 2.3 );
  102. break;
  103. }
  104. parent::initFields( $version, __CLASS__ );
  105. return $this->fields;
  106. }
  107. /**
  108. * Returns the URL Alias of the API Class that inherits the OnApp class
  109. *
  110. * @param string $action action name
  111. *
  112. * @return string API resource
  113. * @access public
  114. */
  115. function getResource( $action = ONAPP_GETRESOURCE_DEFAULT ) {
  116. $show_log_msg = true;
  117. switch( $action ) {
  118. case ONAPP_GETRESOURCE_DEFAULT:
  119. /**
  120. * ROUTE :
  121. * @name virtual_machine_backups
  122. * @method GET
  123. * @alias /virtual_machines/:virtual_machine_id/backups(.:format)
  124. * @format {:controller=>"backups", :action=>"index"}
  125. */
  126. if( is_null( $this->_virtual_machine_id ) && is_null( $this->_obj->_virtual_machine_id ) ) {
  127. $this->logger->error(
  128. 'getResource( ' . $action . ' ): argument _virtual_machine_id not set.',
  129. __FILE__,
  130. __LINE__
  131. );
  132. }
  133. else {
  134. if( is_null( $this->_virtual_machine_id ) ) {
  135. $this->_virtual_machine_id = $this->_obj->_virtual_machine_id;
  136. }
  137. }
  138. if( is_null( $this->_network_interface_id ) && is_null( $this->_obj->_network_interface_id ) ) {
  139. $this->logger->error(
  140. 'getResource( ' . $action . ' ): argument _network_interface_id not set.',
  141. __FILE__,
  142. __LINE__
  143. );
  144. }
  145. else {
  146. if( is_null( $this->_network_interface_id ) ) {
  147. $this->_network_interface_id = $this->_obj->_network_interface_id;
  148. }
  149. }
  150. $resource = 'virtual_machines/' . $this->_virtual_machine_id . '/network_interfaces/' . $this->_network_interface_id . '/' . $this->_resource;
  151. break;
  152. default:
  153. $resource = parent::getResource( $action );
  154. break;
  155. }
  156. if( $show_log_msg ) {
  157. $this->logger->debug( 'getResource( ' . $action . ' ): return ' . $resource );
  158. }
  159. return $resource;
  160. }
  161. /**
  162. * Sends an API request to get the Objects. After requesting,
  163. * unserializes the received response into the array of Objects
  164. *
  165. * @param integer $virtual_machine_id Virtual Machine id
  166. * @param integer $network_interface_id Network Interface id
  167. *
  168. * @return mixed an array of Object instances on success. Otherwise false
  169. * @access public
  170. */
  171. function getList( $virtual_machine_id = null, $network_interface_id = null, $url_args = '' ) {
  172. if( is_null( $virtual_machine_id ) && ! is_null( $this->_virtual_machine_id ) ) {
  173. $virtual_machine_id = $this->_virtual_machine_id;
  174. }
  175. if( ! is_null( $virtual_machine_id ) ) {
  176. $this->_virtual_machine_id = $virtual_machine_id;
  177. }
  178. else {
  179. $this->logger->error(
  180. 'getList: argument _virtual_machine_id not set.',
  181. __FILE__,
  182. __LINE__
  183. );
  184. }
  185. if( is_null( $network_interface_id ) && ! is_null( $this->_network_interface_id ) ) {
  186. $network_interface_id = $this->_network_interface_id;
  187. }
  188. if( ! is_null( $network_interface_id ) ) {
  189. $this->_network_interface_id = $network_interface_id;
  190. }
  191. else {
  192. $this->logger->error(
  193. 'getList: argument _network_interface_id not set.',
  194. __FILE__,
  195. __LINE__
  196. );
  197. }
  198. return parent::getList( null, $url_args );
  199. }
  200. }