Skip to content

Commit 0b95f51

Browse files
committed
Merge pull request #432 from rackspace/working
Merging working -> master in preparation for minor release
2 parents bc90480 + 39d6400 commit 0b95f51

File tree

9 files changed

+130
-20
lines changed

9 files changed

+130
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You must install this library through Composer:
2828
curl -sS https://getcomposer.org/installer | php
2929

3030
# Require php-opencloud as a dependency
31-
php composer.phar require rackspace/php-opencloud:dev-master
31+
php composer.phar require rackspace/php-opencloud
3232
```
3333

3434
Once you have installed the library, you will need to load Composer's autoloader (which registers all the required

lib/OpenCloud/Compute/Resource/Server.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,4 +738,44 @@ protected function updateJson($params = array())
738738
{
739739
return (object) array('server' => (object) $params);
740740
}
741+
742+
/**
743+
* Suspend a server
744+
*
745+
* A suspend request suspend an instance, its VM state is stored on disk, all memory is written
746+
* to disk, and the virtual machine is stopped. Suspending an instance is similar to placing a
747+
* device in hibernation; memory and vCPUs become available to create other instances.
748+
*
749+
* @api
750+
* @return \Guzzle\Http\Message\Response
751+
*/
752+
public function suspend()
753+
{
754+
// The suspend action is only available when the os-admin-actions extension is installed.
755+
$this->checkExtension('os-admin-actions');
756+
757+
$object = (object) array('suspend' => 'none');
758+
759+
return $this->action($object);
760+
}
761+
762+
/**
763+
* Resume a server
764+
*
765+
* A resume request resumes a suspended instance, its VM state was stored on disk, all memory was written
766+
* to disk, and the virtual machine was stopped. Resuming a suspended instance is similar to resuming a
767+
* device from hibernation.
768+
*
769+
* @api
770+
* @return \Guzzle\Http\Message\Response
771+
*/
772+
public function resume()
773+
{
774+
// The resume action is only available when the os-admin-actions extension is installed.
775+
$this->checkExtension('os-admin-actions');
776+
777+
$object = (object) array('resume' => 'none');
778+
779+
return $this->action($object);
780+
}
741781
}

lib/OpenCloud/LoadBalancer/Service.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,14 @@ public function loadBalancer($id = null)
4444
* Return a paginated collection of load balancers
4545
*
4646
* @param bool $detail If TRUE, all details are returned; otherwise, a
47-
* minimal set (ID, name) is retrieved
47+
* minimal set (ID, name) is retrieved [DEPRECATED]
4848
* @param array $filter Optional query params used for search
4949
* @return \OpenCloud\Common\Collection\PaginatedIterator
5050
*/
5151
public function loadBalancerList($detail = true, array $filter = array())
5252
{
5353
$url = $this->getUrl();
5454
$url->addPath(Resource\LoadBalancer::resourceName());
55-
if ($detail) {
56-
$url->addPath('detail');
57-
}
5855
$url->setQuery($filter);
5956

6057
return $this->resourceList('LoadBalancer', $url);

lib/OpenCloud/Orchestration/Resource/ResourceType.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,13 @@ class ResourceType extends ReadOnlyResource
3333

3434
protected $resourceType;
3535
protected $attributes;
36-
protected $_properties; // Named so because the Base class has a $properties member.
36+
protected $resourceTypeProperties; // Named so because the Base class has a $properties member.
3737

3838
protected $aliases = array(
39-
'resource_type' => 'resourceType'
39+
'resource_type' => 'resourceType',
40+
'properties' => 'resourceTypeProperties'
4041
);
4142

42-
/**
43-
* Required to prevent the Base class from attempting to populate $this->properties.
44-
*/
45-
protected function setProperties($properties)
46-
{
47-
$this->_properties = $properties;
48-
}
49-
50-
public function getProperties()
51-
{
52-
return $this->_properties;
53-
}
54-
5543
/**
5644
* Returns the template representation for this resource type.
5745
*

lib/OpenCloud/Orchestration/Resource/Stack.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Stack extends PersistentResource
3131
protected static $json_name = 'stack';
3232

3333
protected $id;
34+
protected $parentStack; // Named so because the Base class has a $parent member.
3435
protected $disableRollback;
3536
protected $description;
3637
protected $parameters;
@@ -49,6 +50,7 @@ class Stack extends PersistentResource
4950
protected $links;
5051

5152
protected $aliases = array(
53+
'parent' => 'parentStack',
5254
'disable_rollback' => 'disableRollback',
5355
'stack_name' => 'name',
5456
'stack_status' => 'status',
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
//
19+
// Pre-requisites:
20+
// * Prior to running this script, you must setup the following environment variables:
21+
// * OS_AUTH_URL: Your Rackspace Cloud Authentication URL,
22+
// * OS_USERNAME: Your Rackspace Cloud Account Username,
23+
// * RAX_API_KEY: Your Rackspace Cloud Account API KEY, and
24+
// * OS_REGION_NAME: The Rackspace Cloud region you want to use
25+
//
26+
27+
require __DIR__ . '/../../vendor/autoload.php';
28+
use OpenCloud\Rackspace;
29+
30+
// 1. Instantiate an Rackspace client.
31+
$client = new Rackspace(getenv('OS_AUTH_URL'), array(
32+
'username' => getenv('OS_USERNAME'),
33+
'apiKey' => getenv('RAX_API_KEY')
34+
));
35+
36+
// 2. Obtain an LoadBalancer service object from the client.
37+
$region = getenv('OS_REGION_NAME');
38+
$loadBalancerService = $client->loadBalancerService(null, $region);
39+
40+
// 3. Get load balancers.
41+
$loadBalancers = $loadBalancerService->loadBalancerList();
42+
foreach ($loadBalancers as $loadBalancer) {
43+
/** @var $loadBalancer OpenCloud\LoadBalancer\Resource\LoadBalancer **/
44+
var_dump($loadBalancer);
45+
}

tests/OpenCloud/Smoke/Unit/Compute.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ public function main()
165165
return false;
166166
}
167167

168+
sleep(3);
169+
170+
// Suspend
171+
$this->step('Suspend the server');
172+
$server->suspend()
173+
$server->waitFor('ACTIVE', 120, $this->getWaiterCallback());
174+
175+
if ($server->status() == 'ERROR') {
176+
$this->stepInfo("Server suspension failed with ERROR\n");
177+
return false;
178+
}
179+
180+
sleep(3);
181+
182+
// Resume
183+
$this->step('Resume the server');
184+
$server->resume()
185+
$server->waitFor('ACTIVE', 120, $this->getWaiterCallback());
186+
187+
if ($server->status() == 'ERROR') {
188+
$this->stepInfo("Server resuming failed with ERROR\n");
189+
return false;
190+
}
191+
168192
sleep(3);
169193

170194
// Attach volume

tests/OpenCloud/Smoke/Unit/Orchestration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function main()
126126
$this->stepInfo('%-25s | %s', 'Metadata key', 'Metadata value');
127127
foreach ($metadata as $key => $value) {
128128
$this->stepInfo('%-25s | %s', $key, $value);
129+
}
129130

130131
$this->step('List stack events');
131132
$events = $stack->listEvents();
@@ -197,6 +198,7 @@ public function main()
197198
$this->stepInfo('Abandon stack data: %s ', $abandonedStackData);
198199

199200
$this->step('Adopt stack');
201+
sleep(10); // For abandoned stack to get deleted.
200202
$stack = $this->getService()->adoptStack(array(
201203
'name' => 'simple-lamp-setup-from-template-url',
202204
'templateUrl' => 'https://raw.githubusercontent.com/rackspace-orchestration-templates/lamp/master/lamp.yaml',

tests/OpenCloud/Tests/Compute/Resource/ServerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ public function test_Rebuild3()
116116
$this->assertNotNull($resp->getStatusCode());
117117
}
118118

119+
public function test_Suspend()
120+
{
121+
$resp = $this->server->suspend();
122+
$this->assertNotNull($resp->getStatusCode());
123+
}
124+
125+
public function test_Resume()
126+
{
127+
$resp = $this->server->resume();
128+
$this->assertNotNull($resp->getStatusCode());
129+
}
130+
119131
public function test_Delete()
120132
{
121133
$resp = $this->server->delete();

0 commit comments

Comments
 (0)