forked from virtuozzo/OnApp-PHP-Wrapper-External
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics.php
141 lines (129 loc) · 4.12 KB
/
Statistics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Billing Statistics
*
* @category API wrapper
* @package OnApp
* @subpackage
* @author
* @copyright © 2016 OnApp
* @link http://www.onapp.com/
* @see OnApp
*/
/**
* Billing Statistics
*
* The OnApp_Statistic uses the following basic methods:
* {@link getList}.
*
* For full fields reference and curl request details visit: ( http://help.onapp.com/manual.php?m=2 )
*/
class OnApp_Statistics extends OnApp {
/**
* root tag used in the API request
*
* @var string
*/
var $_tagRoot = 'stats';
/**
* alias processing the object data
*
* @var string
*/
var $_resource = 'billing/dashboard_statistics';
/**
* 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 5.0:
$this->fields = array(
'cpus' => array(
ONAPP_FIELD_MAP => '_cpus',
ONAPP_FIELD_TYPE => 'array',
),
'memory' => array(
ONAPP_FIELD_MAP => '_memory',
ONAPP_FIELD_TYPE => 'array',
),
'disk_size' => array(
ONAPP_FIELD_MAP => '_disk_size',
ONAPP_FIELD_TYPE => 'array',
),
'iops' => array(
ONAPP_FIELD_MAP => '_iops',
ONAPP_FIELD_TYPE => 'array',
),
'bandwidth' => array(
ONAPP_FIELD_MAP => '_bandwidth',
ONAPP_FIELD_TYPE => 'array',
),
'smart_servers' => array(
ONAPP_FIELD_MAP => '_smart_servers',
ONAPP_FIELD_TYPE => 'array',
),
'baremetal_servers' => array(
ONAPP_FIELD_MAP => '_baremetal_servers',
ONAPP_FIELD_TYPE => 'array',
),
'virtual_servers' => array(
ONAPP_FIELD_MAP => '_virtual_servers',
ONAPP_FIELD_TYPE => 'array',
),
);
break;
case 5.1:
$this->fields = $this->initFields( 5.0 );
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 ) {
switch ( $action ) {
default:
$resource = parent::getResource( $action );
break;
}
return $resource;
}
/**
* Sends an API request to get the Objects. After requesting,
* unserializes the received response into the array of Objects
*
* @param integer $cdn_resource_id CDN Resource id
*
* @return mixed an array of Object instances on success. Otherwise false
* @access public
*/
public function getStatistics( $stats_for = null, $startdate = null, $enddate = null ) {
$params = array();
if ( ! is_null( $stats_for ) ) {
$params['stats_for'] = array();
$params['stats_for'][] = $stats_for;
}
if ( ! is_null( $startdate ) ) {
$params['period[startdate]'] = $startdate;
}
if ( ! is_null( $enddate ) ) {
$params['period[enddate]'] = $enddate;
}
return $this->sendGet( ONAPP_GETRESOURCE, null, $params );
}
function getList( $params = null, $url_args = null ) {
return $this->getStatistics();
}
}