Skip to content

Commit a2f6e87

Browse files
author
Jamie Hannaford
authored
Merge pull request #104 from php-opencloud/ISSUE-103-port-fixed-ips
[rfr] Issue 103 port fixed ips
2 parents af7597a + 85bb2c2 commit a2f6e87

File tree

12 files changed

+163
-9
lines changed

12 files changed

+163
-9
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cache:
99
matrix:
1010
include:
1111
- php: 7.0
12+
- php: 7.1
1213
- php: nightly
1314
allow_failures:
1415
- php: nightly
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => ['id' => '{userId}', 'password' => '{password}'],
9+
'scope' => ['project' => ['id' => '{projectId}']]
10+
]);
11+
12+
$networking = $openstack->networkingV2();
13+
14+
$port = $networking->createPort([
15+
'name' => 'portName',
16+
'networkId' => '{networkId}',
17+
'adminStateUp' => true,
18+
'fixedIps' => [
19+
[
20+
'ipAddress' => '192.168.199.100'
21+
],
22+
[
23+
'ipAddress' => '192.168.199.200'
24+
]
25+
]
26+
]);

samples/networking/v2/subnets/delete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
$networking = $openstack->networkingV2();
2020

21-
$network = $networking->getSubnet('{subnetId}');
21+
$subnet = $networking->getSubnet('{subnetId}');
2222

23-
$network->delete();
23+
$subnet->delete();

src/Networking/v2/Params.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,27 @@ public function macAddr(): array
282282
public function fixedIps(): array
283283
{
284284
return [
285-
'type' => self::STRING_TYPE,
285+
'type' => self::ARRAY_TYPE,
286286
'location' => self::JSON,
287287
'sentAs' => 'fixed_ips',
288-
'description' => 'If you specify only a subnet UUID, OpenStack Networking allocates an available IP from that subnet to the port. If you specify both a subnet UUID and an IP address, OpenStack Networking tries to allocate the address to the port.',
288+
'description' => 'The IP addresses for the port. If you would like to assign multiple IP addresses for the
289+
port, specify multiple entries in this field. Each entry consists of IP address (ipAddress)
290+
and the subnet ID from which the IP address is assigned (subnetId)',
291+
'items' => [
292+
'type' => self::OBJECT_TYPE,
293+
'properties' => [
294+
'ipAddress' => [
295+
'type' => self::STRING_TYPE,
296+
'sentAs' => 'ip_address',
297+
'description' => 'If you specify only an IP address, OpenStack Networking tries to allocate the IP address if the address is a valid IP for any of the subnets on the specified network.'
298+
],
299+
'subnetId' => [
300+
'type' => self::STRING_TYPE,
301+
'sentAs' => 'subnet_id',
302+
'description' => 'Subnet id. If you specify only a subnet ID, OpenStack Networking allocates an available IP from that subnet to the port.'
303+
]
304+
]
305+
]
289306
];
290307
}
291308

tests/integration/Networking/v2/CoreTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ private function deleteSubnet($subnetId)
273273

274274
public function ports()
275275
{
276+
$this->logStep('Test port');
277+
276278
$replacements = ['{newName}' => $this->randomStr()];
277279

278280
/** @var $network \OpenStack\Networking\v2\Models\Network */
@@ -284,7 +286,6 @@ public function ports()
284286
/** @var $port \OpenStack\Networking\v2\Models\Port */
285287
$path = $this->sampleFile($replacements, 'ports/create.php');
286288
require_once $path;
287-
$this->assertInstanceOf(Port::class, $port);
288289

289290
$replacements['{portId}'] = $port->id;
290291
$port->networkId = $network->id;
@@ -316,5 +317,43 @@ public function ports()
316317

317318
$path = $this->sampleFile($replacements, 'networks/delete.php');
318319
require_once $path;
320+
321+
$this->createPortWithFixedIps();
322+
}
323+
324+
private function createPortWithFixedIps()
325+
{
326+
$this->logStep('Test port with fixed IP');
327+
328+
/** @var $network \OpenStack\Networking\v2\Models\Network */
329+
$path = $this->sampleFile(['{networkName}' => $this->randomStr()], 'networks/create.php');
330+
require_once $path;
331+
$this->logStep('Created network {id}', ['{id}' => $network->id]);
332+
333+
334+
/** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
335+
$path = $this->sampleFile(['{subnetName}' => $this->randomStr(), '{networkId}' => $network->id], 'subnets/create.php');
336+
require_once $path;
337+
$this->logStep('Created subnet {id}', ['{id}' => $subnet->id]);
338+
339+
/** @var $port \OpenStack\Networking\v2\Models\Port */
340+
$path = $this->sampleFile(['{networkId}' => $network->id], 'ports/create_with_fixed_ips.php');
341+
require_once $path;
342+
$this->logStep('Created port {id}', ['{id}' => $port->id]);
343+
344+
$path = $this->sampleFile(['{portId}' => $port->id], 'ports/delete.php');
345+
require_once $path;
346+
347+
$this->logStep('Deleted port {id}', ['{id}' => $port->id]);
348+
349+
/** @var $subnet \OpenStack\Networking\v2\Models\Subnet */
350+
$path = $this->sampleFile(['{subnetId}' => $subnet->id], 'subnets/delete.php');
351+
require_once $path;
352+
$this->logStep('Deleted subnet {id}', ['{id}' => $subnet->id]);
353+
354+
/** @var $network \OpenStack\Networking\v2\Models\Network */
355+
$path = $this->sampleFile(['{networkId}' => $network->id], 'networks/delete.php');
356+
require_once $path;
357+
$this->logStep('Deleted network {id}', ['{id}' => $network->id]);
319358
}
320359
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"port":{
6+
"status":"DOWN",
7+
"binding:host_id":"",
8+
"description":"",
9+
"allowed_address_pairs":[
10+
11+
],
12+
"extra_dhcp_opts":[
13+
14+
],
15+
"updated_at":"2017-02-24T07:31:56Z",
16+
"device_owner":"",
17+
"revision_number":5,
18+
"binding:profile":{
19+
20+
},
21+
"fixed_ips":[
22+
{
23+
"subnet_id":"d8e52c33-b301-4feb-9856-a71b71f06c1d",
24+
"ip_address":"192.168.254.20"
25+
}
26+
],
27+
"id":"a87cc70a-3e15-4acf-8205-9b711a3531b8",
28+
"security_groups":[
29+
"38172d7a-233f-49ba-b47c-91a66b92c7b4"
30+
],
31+
"device_id":"",
32+
"name":"",
33+
"admin_state_up":true,
34+
"network_id":"a87cc70a-3e15-4acf-8205-9b711a3531b7",
35+
"tenant_id":"500e0da6e1b54d65a81ba6fe922c65d1",
36+
"binding:vif_details":{
37+
38+
},
39+
"binding:vnic_type":"normal",
40+
"binding:vif_type":"unbound",
41+
"mac_address":"fa:16:3e:34:87:49",
42+
"project_id":"500e0da6e1b54d65a81ba6fe922c65d1",
43+
"created_at":"2017-02-24T07:31:55Z"
44+
}
45+
}

0 commit comments

Comments
 (0)