Skip to content

Commit 2cc7ab5

Browse files
extend FloatingIP with description and subnet_id
The OpenStack API for Floating IPs supports: - an optional description of the floating IP - specifying a specific subnet_id upon creation The subnet ID is not returned on GET.
1 parent 842981a commit 2cc7ab5

File tree

10 files changed

+51
-1
lines changed

10 files changed

+51
-1
lines changed

samples/Networking/v2/floatingIPs/create.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
$floatingIp = $networking->createFloatingIp([
1818
"floatingNetworkId" => "{networkId}",
1919
"portId" => "{portId}",
20-
'fixedIpAddress' => '{fixedIpAddress}',
20+
"fixedIpAddress" => "{fixedIpAddress}",
21+
"description" => "{description}",
2122
]);

src/Networking/v2/Extensions/Layer3/Api.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function postFloatingIps(): array
2626
'jsonKey' => 'floatingip',
2727
'params' => [
2828
'tenantId' => $this->params->tenantIdJson(),
29+
'description' => $this->params->descriptionJson(),
2930
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
3031
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
3132
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
@@ -53,6 +54,7 @@ public function putFloatingIp(): array
5354
'jsonKey' => 'floatingip',
5455
'params' => [
5556
'id' => $this->params->idPath(),
57+
'description' => $this->notRequired($this->params->descriptionJson()),
5658
'floatingNetworkId' => $this->notRequired($this->params->floatingNetworkIdJson()),
5759
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
5860
'floatingIpAddress' => $this->params->floatingIpAddressJson(),

src/Networking/v2/Extensions/Layer3/ApiTrait.php

+3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public function postFloatingIps(): array
2020
'jsonKey' => 'floatingip',
2121
'params' => [
2222
'tenantId' => $this->params->tenantIdJson(),
23+
'description' => $this->notRequired($this->params->descriptionJson()),
2324
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
25+
'subnetId' => $this->notRequired($this->params->subnetIdJson()),
2426
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
2527
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
2628
'portId' => $this->params->portIdJson(),
@@ -47,6 +49,7 @@ public function putFloatingIp(): array
4749
'jsonKey' => 'floatingip',
4850
'params' => [
4951
'id' => $this->params->idPath(),
52+
'description' => $this->notRequired($this->params->descriptionJson()),
5053
'floatingNetworkId' => $this->notRequired($this->params->floatingNetworkIdJson()),
5154
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
5255
'floatingIpAddress' => $this->params->floatingIpAddressJson(),

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

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class FloatingIp extends OperatorResource implements Listable, Creatable, Retrie
2121
/** @var string */
2222
public $status;
2323

24+
/** @var string */
25+
public $description;
26+
2427
/** @var string */
2528
public $floatingNetworkId;
2629

@@ -41,6 +44,7 @@ class FloatingIp extends OperatorResource implements Listable, Creatable, Retrie
4144

4245
protected $aliases = [
4346
'floating_network_id' => 'floatingNetworkId',
47+
'subnet_id' => 'subnetId',
4448
'router_id' => 'routerId',
4549
'fixed_ip_address' => 'fixedIpAddress',
4650
'floating_ip_address' => 'floatingIpAddress',

src/Networking/v2/Extensions/Layer3/Params.php

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
*/
1010
class Params extends \OpenStack\Networking\v2\Params
1111
{
12+
public function descriptionJson(): array
13+
{
14+
return [
15+
'type' => self::STRING_TYPE,
16+
'description' => 'The description of the floating IP.',
17+
'sentAs' => 'description',
18+
];
19+
}
20+
1221
public function tenantIdJson(): array
1322
{
1423
return [

src/Networking/v2/Extensions/Layer3/ParamsTrait.php

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
*/
1010
trait ParamsTrait
1111
{
12+
public function descriptionJson(): array
13+
{
14+
return [
15+
'type' => self::STRING_TYPE,
16+
'description' => 'The description of the floating IP.',
17+
'sentAs' => 'description',
18+
];
19+
}
20+
1221
public function floatingNetworkIdJson(): array
1322
{
1423
return [
@@ -37,6 +46,15 @@ public function floatingIpAddressJson(): array
3746
];
3847
}
3948

49+
public function subnetIdJson(): array
50+
{
51+
return [
52+
'type' => self::STRING_TYPE,
53+
'description' => 'The UUID of the subnet of the floating Network associated with the floating IP.',
54+
'sentAs' => 'subnet',
55+
];
56+
}
57+
4058
public function portIdJson(): array
4159
{
4260
return [

tests/sample/Networking/v2/FloatingIpTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ public function testCreate(): FloatingIpData
6363
'name' => $this->randomStr(),
6464
]);
6565
$fixedIp = $this->findSubnetIp($data->port, $data->internalSubnet);
66+
$description = $this->randomStr();
6667

6768
/** @var FloatingIp $floatingIp */
6869
require_once $this->sampleFile('floatingIPs/create.php', [
6970
'{networkId}' => $data->externalNetwork->id,
7071
'{portId}' => $data->port->id,
7172
'{fixedIpAddress}' => $fixedIp,
73+
'{description}' => $description,
7274
]);
7375
$this->assertInstanceOf(FloatingIp::class, $floatingIp);
7476
$this->assertEquals($data->externalNetwork->id, $floatingIp->floatingNetworkId);
7577
$this->assertEquals($data->port->id, $floatingIp->portId);
78+
$this->assertEquals($description, $floatingIp->description);
7679

7780
$data->floatingIp = $floatingIp;
7881

@@ -123,6 +126,7 @@ public function testGet(FloatingIpData $data)
123126
$this->assertInstanceOf(FloatingIp::class, $floatingIp);
124127
$this->assertEquals($data->floatingIp->id, $floatingIp->id);
125128
$this->assertEmpty($floatingIp->portId);
129+
$this->assertEmpty($floatingIp->description);
126130

127131
$floatingIp->retrieve();
128132
$this->assertEquals($data->floatingIp->portId, $floatingIp->portId);

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Content-Type: application/json
88
"fixed_ip_address": "10.0.0.3",
99
"floating_ip_address": "172.24.4.228",
1010
"tenant_id": "4969c491a3c74ee4af974e6d800c62de",
11+
"description": "some-floating-ip",
1112
"status": "ACTIVE",
1213
"port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab",
1314
"id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7"

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

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Content-Type: application/json
1111
"floating_ip_address": "172.24.4.228",
1212
"port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab",
1313
"id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7",
14+
"description": "some-floating-ip",
1415
"status": "ACTIVE"
1516
},
1617
{
@@ -21,6 +22,7 @@ Content-Type: application/json
2122
"floating_ip_address": "172.24.4.227",
2223
"port_id": null,
2324
"id": "61cea855-49cb-4846-997d-801b70c71bdd",
25+
"description": "some-floating-ip",
2426
"status": "DOWN"
2527
}
2628
]

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

+6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ public function test_it_updates()
2727
$expectedJson = ['floatingip' => [
2828
"floating_network_id" => "376da547-b977-4cfe-9cba-275c80debf57",
2929
"port_id" => "ce705c24-c1ef-408a-bda3-7bbd946164ab",
30+
"description" => "some-floating-ip",
3031
]];
3132

3233
$this->mockRequest('PUT', 'v2.0/floatingips/id', new Response(202), $expectedJson, []);
3334

3435
$this->floatingIp->floatingNetworkId = "376da547-b977-4cfe-9cba-275c80debf57";
3536
$this->floatingIp->portId = "ce705c24-c1ef-408a-bda3-7bbd946164ab";
37+
$this->floatingIp->description = "some-floating-ip";
3638
$this->floatingIp->update();
3739
}
3840

@@ -49,6 +51,10 @@ public function test_it_retrieves()
4951

5052
$this->floatingIp->retrieve();
5153

54+
self::assertEquals(
55+
'some-floating-ip',
56+
$this->floatingIp->description
57+
);
5258
self::assertEquals(
5359
'376da547-b977-4cfe-9cba-275c80debf57',
5460
$this->floatingIp->floatingNetworkId

0 commit comments

Comments
 (0)