Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/OpenCloud/Compute/Resource/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

use Guzzle\Http\Url;
use OpenCloud\Common\Exceptions;
use OpenCloud\Common\PersistentObject;
use OpenCloud\Common\Resource\PersistentResource;
use OpenCloud\Compute\Constants\Network as NetworkConst;
use OpenCloud\Compute\Service;
use OpenCloud\Networking\Resource\NetworkInterface;

/**
* The Network class represents a single virtual network
*/
class Network extends PersistentObject
class Network extends PersistentResource implements NetworkInterface
{
public $id;
public $label;
Expand Down Expand Up @@ -154,4 +155,9 @@ public function getResourcePath()
return self::$openStackResourcePath;
}
}

public function getId()
{
return $this->id;
}
}
11 changes: 6 additions & 5 deletions lib/OpenCloud/Compute/Resource/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OpenCloud\Common\Resource\NovaResource;
use OpenCloud\DNS\Resource\HasPtrRecordsInterface;
use OpenCloud\Image\Resource\ImageInterface;
use OpenCloud\Networking\Resource\NetworkInterface;
use OpenCloud\Volume\Resource\Volume;
use OpenCloud\Common\Exceptions;
use OpenCloud\Common\Http\Message\Formatter;
Expand Down Expand Up @@ -681,22 +682,22 @@ protected function createJson()
$server->networks = array();

foreach ($this->networks as $network) {
if (!$network instanceof Network) {
if (!$network instanceof NetworkInterface) {
throw new Exceptions\InvalidParameterError(sprintf(
'When creating a server, the "networks" key must be an ' .
'array of OpenCloud\Compute\Network objects with valid ' .
'IDs; variable passed in was a [%s]',
'array of objects which implement OpenCloud\Networking\Resource\NetworkInterface;' .
'variable passed in was a [%s]',
gettype($network)
));
}
if (empty($network->id)) {
if (!($networkId = $network->getId())) {
$this->getLogger()->warning('When creating a server, the '
. 'network objects passed in must have an ID'
);
continue;
}
// Stock networks array
$server->networks[] = (object) array('uuid' => $network->id);
$server->networks[] = (object) array('uuid' => $networkId);
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/OpenCloud/Networking/Resource/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @package OpenCloud\Networking\Resource
*/
class Network extends PersistentResource
class Network extends PersistentResource implements NetworkInterface
{
protected static $url_resource = 'networks';
protected static $json_name = 'network';
Expand Down Expand Up @@ -71,4 +71,9 @@ public function createJson()
{
return parent::createJson();
}

public function getId()
{
return $this->id;
}
}
31 changes: 31 additions & 0 deletions lib/OpenCloud/Networking/Resource/NetworkInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace OpenCloud\Networking\Resource;

/**
* Interface for a Network
*
* @package OpenCloud\Networking\Resource
*/
interface NetworkInterface
{
/**
* @return string
*/
public function getId();
}
1 change: 1 addition & 0 deletions tests/OpenCloud/Tests/Compute/Resource/NetworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function test__construct()
{
$this->assertEquals(NetworkConst::RAX_PUBLIC, $this->network->id);
$this->assertInstanceOf('OpenCloud\Compute\Resource\Network', $this->network);
$this->assertInstanceOf('OpenCloud\Networking\Resource\NetworkInterface', $this->network);
}

public function test_Create()
Expand Down
7 changes: 6 additions & 1 deletion tests/OpenCloud/Tests/Compute/Resource/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,18 @@ public function test_Image_Schedule()

public function test_Create_With_Networks()
{
$neutronService = $this->client->networkingService(null, 'IAD');
$neutronNetwork = $neutronService->network();
$neutronNetwork->setId('12345');

$this->service->server()->create(array(
'name' => 'personality test 1',
'image' => $this->service->imageList()->first(),
'flavor' => $this->service->flavorList()->first(),
'networks' => array(
$this->service->network(Network::RAX_PUBLIC),
$this->service->network()
$this->service->network(),
$neutronNetwork,
)
));
}
Expand Down