Skip to content

Commit 66ee164

Browse files
committed
Networking L3: Mapping external fixed IPs
1 parent 526745f commit 66ee164

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

src/Networking/v2/Extensions/Layer3/Models/FixedIp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class FixedIp extends AbstractResource
1313
public $ip;
1414

1515
protected $aliases = [
16-
'subnet_id' => 'subnetId',
16+
'subnet_id' => 'subnetId',
17+
'ip_address' => 'ip',
1718
];
1819
}

src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@ public function retrieve()
7474
$response = $this->executeWithState($this->api->getFloatingIp());
7575
$this->populateFromResponse($response);
7676
}
77+
78+
public function associatePort(string $portId)
79+
{
80+
$this->execute($this->api->putFloatingIp(), ['id' => $this->id, 'portId' => $portId]);
81+
}
7782
}

src/Networking/v2/Extensions/Layer3/Models/GatewayInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GatewayInfo extends AbstractResource
1313
/** @var string */
1414
public $enableSnat;
1515

16-
/** @var []FixedIp */
16+
/** @var FixedIp[] */
1717
public $fixedIps;
1818

1919
protected $aliases = [
@@ -27,7 +27,7 @@ class GatewayInfo extends AbstractResource
2727
protected function getAliases(): array
2828
{
2929
return parent::getAliases() + [
30-
'fixed_ips' => new Alias('fixedIps', FixedIp::class, true),
30+
'external_fixed_ips' => new Alias('fixedIps', FixedIp::class, true),
3131
];
3232
}
3333
}

tests/unit/Networking/v2/Extensions/Layer3/Fixtures/Router.resp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,44 @@ Content-Type: application/json
33

44
{
55
"router": {
6-
"status": "ACTIVE",
6+
"admin_state_up": true,
7+
"availability_zone_hints": [],
8+
"availability_zones": [
9+
"nova"
10+
],
11+
"created_at": "2018-03-19T19:17:04Z",
12+
"description": "",
13+
"distributed": false,
714
"external_gateway_info": {
8-
"network_id": "85d76829-6415-48ff-9c63-5c5ca8c61ac6",
915
"enable_snat": true,
1016
"external_fixed_ips": [
1117
{
12-
"subnet_id": "255.255.255.0",
13-
"ip": "192.168.10.2"
18+
"ip_address": "172.24.4.6",
19+
"subnet_id": "b930d7f6-ceb7-40a0-8b81-a425dd994ccf"
20+
},
21+
{
22+
"ip_address": "2001:db8::9",
23+
"subnet_id": "0c56df5d-ace5-46c8-8f4c-45fa4e334d18"
1424
}
15-
]
25+
],
26+
"network_id": "ae34051f-aa6c-4c75-abf5-50dc9ac99ef3"
1627
},
28+
"flavor_id": "f7b14d9a-b0dc-4fbe-bb14-a0f4970a69e0",
29+
"ha": false,
30+
"id": "f8a44de0-fc8e-45df-93c7-f79bf3b01c95",
1731
"name": "router1",
18-
"admin_state_up": true,
19-
"tenant_id": "d6554fe62e2f41efbb6e026fad5c1542",
20-
"routes": [],
21-
"id": "a07eea83-7710-4860-931b-5fe220fae533"
32+
"revision_number": 1,
33+
"routes": [
34+
{
35+
"destination": "179.24.1.0/24",
36+
"nexthop": "172.24.3.99"
37+
}
38+
],
39+
"status": "ACTIVE",
40+
"updated_at": "2018-03-19T19:17:22Z",
41+
"project_id": "0bd18306d801447bb457a46252d82d13",
42+
"tenant_id": "0bd18306d801447bb457a46252d82d13",
43+
"service_type_id": null,
44+
"tags": ["tag1,tag2"]
2245
}
23-
}
46+
}

tests/unit/Networking/v2/Extensions/Layer3/Models/RouterTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public function test_it_retrieves()
6969
$this->setupMock('GET', 'v2.0/routers/id', null, [], 'Router');
7070

7171
$this->router->retrieve();
72+
73+
$this->assertEquals('f8a44de0-fc8e-45df-93c7-f79bf3b01c95', $this->router->id);
74+
$this->assertCount(2, $this->router->externalGatewayInfo->fixedIps);
7275
}
7376

7477
public function test_it_adds_interface()

0 commit comments

Comments
 (0)