HPCloud-PHP
1.2.0
PHP bindings for HPCloud and OpenStack services.
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Pages
Flavor.php
Go to the documentation of this file.
1
<?php
2
/* ============================================================================
3
(c) Copyright 2013 Hewlett-Packard Development Company, L.P.
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights to
7
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
8
the Software, and to permit persons to whom the Software is furnished to do so,
9
subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in all
12
copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
SOFTWARE.
21
============================================================================ */
22
/**
23
* @file
24
* This file contains the Database Flavor class.
25
*/
26
27
namespace
HPCloud\Services\DBaaS
;
28
29
use \HPCloud\Transport;
30
use \HPCloud\Exception;
31
32
/**
33
* Class for working with Database Flavors.
34
*/
35
class
Flavor
extends
Operations
{
36
37
protected
$token
;
38
protected
$projectId
;
39
protected
$url
;
40
protected
$client
;
41
42
public
function
__construct
(
$token
,
$projectId
,
$endpoint
) {
43
$this->token =
$token
;
44
$this->
projectId
=
$projectId
;
45
$this->
url
=
$endpoint
;
46
$this->client =
Transport::instance
();
47
}
48
49
/**
50
* Retrieve a list of available instance flavors.
51
*
52
* @retval array
53
* @return array
54
* An array of \HPCloud\Service\DBaaS\Flavor objects listing the available
55
* flavors.
56
*/
57
public
function
listFlavors
() {
58
$url
= $this->
url
.
'/flavors'
;
59
$res = $this->client->doRequest(
$url
,
'GET'
, $this->
headers
());
60
$json = json_decode($res->content(), TRUE);
61
62
$list = array();
63
foreach
($json[
'flavors'
] as $instance) {
64
$list[] = FlavorDetails::newFromArray($instance);
65
}
66
67
return
$list;
68
}
69
70
/**
71
* Get a FlavorDetails object by its name.
72
*
73
* @param string $name
74
* The name of the flavor.
75
*
76
* @retval HPCloud::Services::DBaaS::FlavorDetails
77
* @return \HPCloud\Services\DBaaS\FlavorDetails
78
* A flavor details object for the flavor.
79
*/
80
public
function
getFlavorByName
(
$name
) {
81
$flavors = $this->
listFlavors
();
82
foreach
($flavors as $k => $v) {
83
if
($v->name() ==
$name
) {
84
return
$v;
85
}
86
}
87
88
// If we got here there was either no flavor with that name or a problem
89
// getting the flavors. Throw an exception.
90
throw
new
Exception
(
"DBaaS Flavor {$name} not available."
);
91
}
92
}
src
HPCloud
Services
DBaaS
Flavor.php
Generated on Fri Jan 11 2013 09:17:48 for HPCloud-PHP by
1.8.1.2