Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend FloatingIP with description and subnet_id #421

Merged
merged 1 commit into from
Jan 7, 2025
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
3 changes: 2 additions & 1 deletion samples/Networking/v2/floatingIPs/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
$floatingIp = $networking->createFloatingIp([
"floatingNetworkId" => "{networkId}",
"portId" => "{portId}",
'fixedIpAddress' => '{fixedIpAddress}',
"fixedIpAddress" => "{fixedIpAddress}",
"description" => "{description}",
]);
2 changes: 2 additions & 0 deletions src/Networking/v2/Extensions/Layer3/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function postFloatingIps(): array
'jsonKey' => 'floatingip',
'params' => [
'tenantId' => $this->params->tenantIdJson(),
'description' => $this->notRequired($this->params->descriptionJson()),
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
Expand Down Expand Up @@ -53,6 +54,7 @@ public function putFloatingIp(): array
'jsonKey' => 'floatingip',
'params' => [
'id' => $this->params->idPath(),
'description' => $this->notRequired($this->params->descriptionJson()),
'floatingNetworkId' => $this->notRequired($this->params->floatingNetworkIdJson()),
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
Expand Down
3 changes: 3 additions & 0 deletions src/Networking/v2/Extensions/Layer3/ApiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public function postFloatingIps(): array
'jsonKey' => 'floatingip',
'params' => [
'tenantId' => $this->params->tenantIdJson(),
'description' => $this->notRequired($this->params->descriptionJson()),
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
'subnetId' => $this->notRequired($this->params->subnetIdJson()),
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
'portId' => $this->params->portIdJson(),
Expand All @@ -47,6 +49,7 @@ public function putFloatingIp(): array
'jsonKey' => 'floatingip',
'params' => [
'id' => $this->params->idPath(),
'description' => $this->notRequired($this->params->descriptionJson()),
'floatingNetworkId' => $this->notRequired($this->params->floatingNetworkIdJson()),
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
Expand Down
3 changes: 3 additions & 0 deletions src/Networking/v2/Extensions/Layer3/Models/FloatingIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class FloatingIp extends OperatorResource implements Listable, Creatable, Retrie
/** @var string */
public $status;

/** @var string */
public $description;

/** @var string */
public $floatingNetworkId;

Expand Down
9 changes: 9 additions & 0 deletions src/Networking/v2/Extensions/Layer3/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/
class Params extends \OpenStack\Networking\v2\Params
{
public function descriptionJson(): array
{
return [
'type' => self::STRING_TYPE,
'description' => 'The description of the floating IP.',
'sentAs' => 'description',
];
}

public function tenantIdJson(): array
{
return [
Expand Down
18 changes: 18 additions & 0 deletions src/Networking/v2/Extensions/Layer3/ParamsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/
trait ParamsTrait
{
public function descriptionJson(): array
{
return [
'type' => self::STRING_TYPE,
'description' => 'The description of the floating IP.',
'sentAs' => 'description',
];
}

public function floatingNetworkIdJson(): array
{
return [
Expand Down Expand Up @@ -37,6 +46,15 @@ public function floatingIpAddressJson(): array
];
}

public function subnetIdJson(): array
{
return [
'type' => self::STRING_TYPE,
'description' => 'The UUID of the subnet of the floating Network associated with the floating IP.',
'sentAs' => 'subnet',
];
}

public function portIdJson(): array
{
return [
Expand Down
4 changes: 4 additions & 0 deletions tests/sample/Networking/v2/FloatingIpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ public function testCreate(): FloatingIpData
'name' => $this->randomStr(),
]);
$fixedIp = $this->findSubnetIp($data->port, $data->internalSubnet);
$description = $this->randomStr();

/** @var FloatingIp $floatingIp */
require_once $this->sampleFile('floatingIPs/create.php', [
'{networkId}' => $data->externalNetwork->id,
'{portId}' => $data->port->id,
'{fixedIpAddress}' => $fixedIp,
'{description}' => $description,
]);
$this->assertInstanceOf(FloatingIp::class, $floatingIp);
$this->assertEquals($data->externalNetwork->id, $floatingIp->floatingNetworkId);
$this->assertEquals($data->port->id, $floatingIp->portId);
$this->assertEquals($description, $floatingIp->description);

$data->floatingIp = $floatingIp;

Expand Down Expand Up @@ -123,6 +126,7 @@ public function testGet(FloatingIpData $data)
$this->assertInstanceOf(FloatingIp::class, $floatingIp);
$this->assertEquals($data->floatingIp->id, $floatingIp->id);
$this->assertEmpty($floatingIp->portId);
$this->assertEmpty($floatingIp->description);

$floatingIp->retrieve();
$this->assertEquals($data->floatingIp->portId, $floatingIp->portId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Content-Type: application/json
"fixed_ip_address": "10.0.0.3",
"floating_ip_address": "172.24.4.228",
"tenant_id": "4969c491a3c74ee4af974e6d800c62de",
"description": "some-floating-ip",
"status": "ACTIVE",
"port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab",
"id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Content-Type: application/json
"floating_ip_address": "172.24.4.228",
"port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab",
"id": "2f245a7b-796b-4f26-9cf9-9e82d248fda7",
"description": "some-floating-ip",
"status": "ACTIVE"
},
{
Expand All @@ -21,6 +22,7 @@ Content-Type: application/json
"floating_ip_address": "172.24.4.227",
"port_id": null,
"id": "61cea855-49cb-4846-997d-801b70c71bdd",
"description": "some-floating-ip",
"status": "DOWN"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public function test_it_updates()
$expectedJson = ['floatingip' => [
"floating_network_id" => "376da547-b977-4cfe-9cba-275c80debf57",
"port_id" => "ce705c24-c1ef-408a-bda3-7bbd946164ab",
"description" => "some-floating-ip",
]];

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

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

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

$this->floatingIp->retrieve();

self::assertEquals(
'some-floating-ip',
$this->floatingIp->description
);
self::assertEquals(
'376da547-b977-4cfe-9cba-275c80debf57',
$this->floatingIp->floatingNetworkId
Expand Down
Loading