Skip to content

Commit 30bc992

Browse files
author
Jamie Hannaford
committed
Merge pull request rackspace#603 from kaecyra/improve-list-ports-docs
Add more verbose annotation to `listPorts` to clarify filtering options
2 parents abe8163 + 7821d55 commit 30bc992

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

doc/services/networking/ports.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ You can list all the ports to which you have access as shown in the following ex
8686
8787
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/Networking/list-ports.php>`_
8888

89+
The port list query may be filtered by numerous optional parameters as per the `API documentation <http://developer.openstack.org/api-ref-networking-v2.html#listPorts>`_
90+
91+
.. code-block:: php
92+
93+
$ports = $networkingService->listPorts([
94+
'status' => 'ACTIVE',
95+
'device_id' => '9ae135f4-b6e0-4dad-9e91-3c223e385824'
96+
]);
97+
98+
foreach ($ports as $port) {
99+
/** @var $port OpenCloud\Networking\Resource\Port **/
100+
}
101+
102+
`Get the executable PHP script for this example <https://raw.githubusercontent.com/rackspace/php-opencloud/master/samples/Networking/list-ports-filtered.php>`_
103+
89104

90105
Get a port
91106
----------
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
require dirname(__DIR__) . '/../vendor/autoload.php';
19+
20+
use OpenCloud\Rackspace;
21+
22+
// 1. Instantiate a Rackspace client. You can replace {authUrl} with
23+
// Rackspace::US_IDENTITY_ENDPOINT or similar
24+
$client = new Rackspace('{authUrl}', array(
25+
'username' => '{username}',
26+
'apiKey' => '{apiKey}',
27+
));
28+
29+
// 2. Obtain a Networking service object from the client.
30+
$networkingService = $client->networkingService(null, '{region}');
31+
32+
// 3. List ACTIVE ports for given device ID
33+
$ports = $networkingService->listPorts([
34+
'status' => 'ACTIVE',
35+
'device_id' => '{deviceId}'
36+
]);
37+
foreach ($ports as $port) {
38+
/** @var $port OpenCloud\Networking\Resource\Port **/
39+
}

0 commit comments

Comments
 (0)