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

Merge network services #392

Merged
merged 7 commits into from
Jan 27, 2024
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
2 changes: 1 addition & 1 deletion phpunit.sample.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value=""/>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="On"/>
<ini name="display_startup_errors" value="On"/>
</php>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value=""/>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="On"/>
<ini name="display_startup_errors" value="On"/>
</php>
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/floatingIPs/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']],
]);

$networking = $openstack->networkingV2ExtLayer3();
$networking = $openstack->networkingV2();

$floatingIp = $networking->createFloatingIp([
"floatingNetworkId" => "{networkId}",
Expand Down
7 changes: 4 additions & 3 deletions samples/Networking/v2/floatingIPs/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']],
]);

$openstack->networkingV2ExtLayer3()
->getFloatingIp('{id}')
->delete();
$networking = $openstack->networkingV2();
$floatIp = $networking->getFloatingIp('{id}');

$floatIp->delete();
2 changes: 1 addition & 1 deletion samples/Networking/v2/floatingIPs/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
'scope' => ['project' => ['id' => '{projectId}']],
]);

$floatingIp = $openstack->networkingV2ExtLayer3()
$floatingIp = $openstack->networkingV2()
->getFloatingIp('{id}');
2 changes: 1 addition & 1 deletion samples/Networking/v2/floatingIPs/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']],
]);

$floatingIps = $openstack->networkingV2ExtLayer3()
$floatingIps = $openstack->networkingV2()
->listFloatingIps();

foreach ($floatingIps as $floatingIp) {
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/floatingIPs/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']],
]);

$floatingIp = $openstack->networkingV2ExtLayer3()
$floatingIp = $openstack->networkingV2()
->getFloatingIp('{id}');

$floatingIp->portId = '{newPortId}';
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroupRules/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

$networking = $openstack->networkingV2ExtSecGroups();
$networking = $openstack->networkingV2();

/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroupRule $rule */
$rule = $networking->createSecurityGroupRule([
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroupRules/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]);

/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroupRule $rule */
$rule = $openstack->networkingV2ExtSecGroups()
$rule = $openstack->networkingV2()
->getSecurityGroupRule('{id}');

$rule->delete();
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroupRules/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
]);

/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroupRule $rule */
$rule = $openstack->networkingV2ExtSecGroups()
$rule = $openstack->networkingV2()
->getSecurityGroupRule('{id}');
7 changes: 3 additions & 4 deletions samples/Networking/v2/securityGroupRules/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

/** @var Service $networkingExtSecGroup */
$networkingExtSecGroup = $openstack->networkingV2ExtSecGroups();
$networking = $openstack->networkingV2();

//List all security group rules
foreach ($networkingExtSecGroup->listSecurityGroupRules() as $rule) {
foreach ($networking->listSecurityGroupRules() as $rule) {
/** @var SecurityGroupRule $rule */
}

/** @var SecurityGroup $securityGroup */
$securityGroup = $networkingExtSecGroup->getSecurityGroup(['id' => '{uuid}']);
$securityGroup = $networking->getSecurityGroup('{uuid}');

//List rules belong to a security group
foreach ($securityGroup->securityGroupRules as $rule) {
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroups/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

$networking = $openstack->networkingV2ExtSecGroups();
$networking = $openstack->networkingV2();

/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup $secGroup */
$secGroup = $networking->createSecurityGroup([
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroups/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

$networking = $openstack->networkingV2ExtSecGroups();
$networking = $openstack->networkingV2();

/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup $secGroup */
$secGroup = $networking->getSecurityGroup('{id}');
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroups/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

$networking = $openstack->networkingV2ExtSecGroups();
$networking = $openstack->networkingV2();

/** @var \OpenStack\Networking\v2\Extensions\SecurityGroups\Models\SecurityGroup $secGroup */
$secGroup = $networking->getSecurityGroup('{id}');
Expand Down
2 changes: 1 addition & 1 deletion samples/Networking/v2/securityGroups/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'scope' => ['project' => ['id' => '{projectId}']]
]);

$networking = $openstack->networkingV2ExtSecGroups();
$networking = $openstack->networkingV2();

$secGroups = $networking->listSecurityGroups();

Expand Down
2 changes: 0 additions & 2 deletions src/Common/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ private function getClasses($namespace)
*
* @param string $namespace The namespace of the service
* @param array $serviceOptions The service-specific options to use
*
* @throws \Exception
*/
public function createService(string $namespace, array $serviceOptions = []): ServiceInterface
{
Expand Down
5 changes: 5 additions & 0 deletions src/Networking/v2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace OpenStack\Networking\v2;

use OpenStack\Common\Api\AbstractApi;
use OpenStack\Networking\v2\Extensions\Layer3\ApiTrait as Layer3;
use OpenStack\Networking\v2\Extensions\SecurityGroups\ApiTrait as SecurityGroup;

/**
* A representation of the Neutron (Nova) v2 REST API.
Expand All @@ -13,6 +15,9 @@
*/
class Api extends AbstractApi
{
use Layer3;
use SecurityGroup;

private $pathPrefix = 'v2.0';

public function __construct()
Expand Down
5 changes: 5 additions & 0 deletions src/Networking/v2/Extensions/Layer3/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use OpenStack\Common\Api\AbstractApi;

/**
* @deprecated Use Networking\v2\Api instead
*
* @internal
*/
class Api extends AbstractApi
{
private $pathPrefix = 'v2.0';
Expand Down
172 changes: 172 additions & 0 deletions src/Networking/v2/Extensions/Layer3/ApiTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

declare(strict_types=1);

namespace OpenStack\Networking\v2\Extensions\Layer3;

/**
* @property \OpenStack\Networking\v2\Params $params
* @property string $pathPrefix
*
* @internal
*/
trait ApiTrait
{
public function postFloatingIps(): array
{
return [
'method' => 'POST',
'path' => $this->pathPrefix.'/floatingips',
'jsonKey' => 'floatingip',
'params' => [
'tenantId' => $this->params->tenantIdJson(),
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
'portId' => $this->params->portIdJson(),
],
];
}

public function getFloatingIps(): array
{
return [
'method' => 'GET',
'path' => $this->pathPrefix.'/floatingips',
'params' => [
'tenantId' => $this->params->queryTenantId(),
],
];
}

public function putFloatingIp(): array
{
return [
'method' => 'PUT',
'path' => $this->pathPrefix.'/floatingips/{id}',
'jsonKey' => 'floatingip',
'params' => [
'id' => $this->params->idPath(),
'floatingNetworkId' => $this->notRequired($this->params->floatingNetworkIdJson()),
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
'portId' => $this->params->portIdJson(),
],
];
}

public function getFloatingIp(): array
{
return [
'method' => 'GET',
'path' => $this->pathPrefix.'/floatingips/{id}',
'params' => [
'id' => $this->params->idPath(),
'portId' => $this->params->portIdJson(),
],
];
}

public function deleteFloatingIp(): array
{
return [
'method' => 'DELETE',
'path' => $this->pathPrefix.'/floatingips/{id}',
'params' => [
'id' => $this->params->idPath(),
],
];
}

public function postRouters(): array
{
return [
'method' => 'POST',
'path' => $this->pathPrefix.'/routers',
'jsonKey' => 'router',
'params' => [
'name' => $this->params->nameJson(),
'externalGatewayInfo' => $this->params->externalGatewayInfo(),
'adminStateUp' => $this->params->adminStateUp(),
'tenantId' => $this->params->tenantId(),
'distributed' => $this->params->distributedJson(),
'ha' => $this->params->haJson(),
],
];
}

public function getRouters(): array
{
return [
'method' => 'GET',
'path' => $this->pathPrefix.'/routers',
'params' => [
'name' => $this->params->queryName(),
'tenantId' => $this->params->queryTenantId(),
],
];
}

public function putRouter(): array
{
return [
'method' => 'PUT',
'path' => $this->pathPrefix.'/routers/{id}',
'jsonKey' => 'router',
'params' => [
'id' => $this->params->idPath(),
'name' => $this->params->nameJson(),
'externalGatewayInfo' => $this->params->externalGatewayInfo(),
'adminStateUp' => $this->params->adminStateUp(),
],
];
}

public function getRouter(): array
{
return [
'method' => 'GET',
'path' => $this->pathPrefix.'/routers/{id}',
'params' => [
'id' => $this->params->idPath(),
],
];
}

public function deleteRouter(): array
{
return [
'method' => 'DELETE',
'path' => $this->pathPrefix.'/routers/{id}',
'params' => [
'id' => $this->params->idPath(),
],
];
}

public function putAddInterface(): array
{
return [
'method' => 'PUT',
'path' => $this->pathPrefix.'/routers/{id}/add_router_interface',
'params' => [
'id' => $this->params->idPath(),
'subnetId' => $this->params->subnetId(),
'portId' => $this->params->portIdJson(),
],
];
}

public function putRemoveInterface(): array
{
return [
'method' => 'PUT',
'path' => $this->pathPrefix.'/routers/{id}/remove_router_interface',
'params' => [
'id' => $this->params->idPath(),
'subnetId' => $this->params->subnetId(),
'portId' => $this->params->portIdJson(),
],
];
}
}
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 @@ -51,6 +51,9 @@ class FloatingIp extends OperatorResource implements Listable, Creatable, Retrie
protected $resourceKey = 'floatingip';
protected $resourcesKey = 'floatingips';

/**
* {@inheritdoc}
*/
public function create(array $userOptions): Creatable
{
$response = $this->execute($this->api->postFloatingIps(), $userOptions);
Expand Down
3 changes: 3 additions & 0 deletions src/Networking/v2/Extensions/Layer3/Models/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ protected function getAliases(): array
];
}

/**
* {@inheritdoc}
*/
public function create(array $userOptions): Creatable
{
$response = $this->execute($this->api->postRouters(), $userOptions);
Expand Down
Loading
Loading