Added framework in for DBaaS Flavors.
This commit is contained in:
@@ -29,6 +29,7 @@ namespace HPCloud\Services;
|
||||
|
||||
use \HPCloud\Services\DBaaS\Instance;
|
||||
use \HPCloud\Services\DBaaS\Snapshot;
|
||||
use \HPCloud\Services\DBaaS\Flavor;
|
||||
|
||||
/**
|
||||
* Database As A Service.
|
||||
@@ -135,6 +136,10 @@ class DBaaS {
|
||||
return new Snapshot($this->token, $this->projectId, $this->url);
|
||||
}
|
||||
|
||||
public function flavor() {
|
||||
return new Flavor($this->token, $this->projectId, $this->url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the project ID for this session.
|
||||
*
|
||||
|
||||
68
src/HPCloud/Services/DBaaS/Flavor.php
Normal file
68
src/HPCloud/Services/DBaaS/Flavor.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/* ============================================================================
|
||||
(c) Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
============================================================================ */
|
||||
/**
|
||||
* @file
|
||||
* This file contains the Database Flavor class.
|
||||
*/
|
||||
|
||||
namespace HPCloud\Services\DBaaS;
|
||||
|
||||
use \HPCloud\Transport;
|
||||
|
||||
/**
|
||||
* Class for working with Database Flavors.
|
||||
*/
|
||||
class Flavor extends Operations {
|
||||
|
||||
protected $token;
|
||||
protected $projectId;
|
||||
protected $url;
|
||||
protected $client;
|
||||
|
||||
public function __construct($token, $projectId, $endpoint) {
|
||||
$this->token = $token;
|
||||
$this->projectId = $projectId;
|
||||
$this->url = $endpoint;
|
||||
$this->client = Transport::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of available instance flavors.
|
||||
*
|
||||
* @retval array
|
||||
* @return array
|
||||
* An array of \HPCloud\Service\DBaaS\Flavor objects listing the available
|
||||
* flavors.
|
||||
*/
|
||||
public function listFlavors() {
|
||||
$url = $this->url . '/flavors';
|
||||
$res = $this->client->doRequest($url, 'GET', $this->headers());
|
||||
$json = json_decode($res->content(), TRUE);
|
||||
|
||||
$list = array();
|
||||
foreach ($json['flavors'] as $instance) {
|
||||
$list[] = FlavorDetails::newFromArray($instance);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
124
src/HPCloud/Services/DBaaS/FlavorDetails.php
Normal file
124
src/HPCloud/Services/DBaaS/FlavorDetails.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/* ============================================================================
|
||||
(c) Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
============================================================================ */
|
||||
/**
|
||||
* @file
|
||||
* This file contains the Database FlavorDetails class.
|
||||
*/
|
||||
|
||||
namespace HPCloud\Services\DBaaS;
|
||||
|
||||
/**
|
||||
* Class for working with Database Flavors Details.
|
||||
*/
|
||||
class FlavorDetails {
|
||||
|
||||
protected $name;
|
||||
protected $id;
|
||||
protected $url;
|
||||
protected $links;
|
||||
protected $ram;
|
||||
protected $vcpu;
|
||||
|
||||
public static function newFromArray(array $array) {
|
||||
|
||||
$o = new FlavorDetails($array['name'], $array['id']);
|
||||
$o->links = $array['links'];
|
||||
$o->ram = $array['ram'];
|
||||
$o->vcpu = $array['vcpu'];
|
||||
|
||||
if (isset($array['links'][0]) && $array['links'][0]['rel'] == 'self') {
|
||||
$o->url = $array['links'][0]['href'];
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
public function __construct($name, $id) {
|
||||
$this->name = $name;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of a flavor (e.g., small).
|
||||
*
|
||||
* @return string
|
||||
* The name of a flavor.
|
||||
*/
|
||||
public function name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of a flavor.
|
||||
*
|
||||
* @return int
|
||||
* The id of a flavor.
|
||||
*/
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the links for a flavor.
|
||||
*
|
||||
* @retval array
|
||||
* @return array
|
||||
* Get an array of links for the flavor.
|
||||
*/
|
||||
public function links() {
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the callback url for the flavor.
|
||||
*
|
||||
* @retval string
|
||||
* @return string
|
||||
* The callback url for the flavor. This is in the form
|
||||
* [DaaSBaseURI]/{tenant_id}/flavors/{flavorId}
|
||||
*/
|
||||
public function url() {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of ram available to this flavor.
|
||||
*
|
||||
* @retval int
|
||||
* @return int
|
||||
* The amount of ram available to the flavor.
|
||||
*/
|
||||
public function ram() {
|
||||
return $this->ram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of virtual CPUs available to this flavor.
|
||||
*
|
||||
* @retval int
|
||||
* @return int
|
||||
* The number of virtual CPUs available to the flavor.
|
||||
*/
|
||||
public function vcpu() {
|
||||
return $this->vcpu;
|
||||
}
|
||||
}
|
||||
43
test/Tests/DBaaSFlavorTest.php
Normal file
43
test/Tests/DBaaSFlavorTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* ============================================================================
|
||||
(c) Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
============================================================================ */
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Unit tests for HPCloud::DBaaS::Flavor.
|
||||
*/
|
||||
namespace HPCloud\Tests\Services\DBaaS;
|
||||
|
||||
require_once __DIR__ . '/DBaaSTestCase.php';
|
||||
|
||||
use \HPCloud\Services\DBaaS;
|
||||
use \HPCloud\Services\DBaaS\Flavor;
|
||||
|
||||
/**
|
||||
* @group dbaas
|
||||
*/
|
||||
class DBaaSInstanceTest extends DBaaSTestCase {
|
||||
public function testListFlavors() {
|
||||
$flavors = $this->dbaas()->flavor()->listFlavors();
|
||||
|
||||
$this->assertNotEmpty($flavors);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,12 @@ class DBaaSInstanceTest extends DBaaSTestCase {
|
||||
$this->assertInstanceOf('\HPCloud\Services\DBaaS\Instance', $inst);
|
||||
}
|
||||
|
||||
public function testListFlavors() {
|
||||
$flavors = $this->dbaas()->flavor()->listFlavors();
|
||||
|
||||
$this->assertNotEmpty($flavors);
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
// Make sure there aren't old fixtures hanging around from a
|
||||
// failed run.
|
||||
|
||||
Reference in New Issue
Block a user