Skip to content

Commit bcea3b0

Browse files
author
Jamie Hannaford
committed
Add networking classes
1 parent 722dd88 commit bcea3b0

File tree

27 files changed

+2051
-13
lines changed

27 files changed

+2051
-13
lines changed

src/Networking/v2/Api.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare (strict_types=1);
1+
<?php declare (strict_types = 1);
22

33
namespace OpenStack\Networking\v2;
44

@@ -44,9 +44,11 @@ public function postNetwork(): array
4444
'method' => 'POST',
4545
'jsonKey' => 'network',
4646
'params' => [
47-
'name' => $this->params->name('network'),
48-
'shared' => $this->params->shared(),
49-
'adminStateUp' => $this->params->adminStateUp(),
47+
'name' => $this->params->name('network'),
48+
'shared' => $this->params->shared(),
49+
'adminStateUp' => $this->params->adminStateUp(),
50+
'routerAccessible' => $this->params->routerAccessibleJson(),
51+
'tenantId' => $this->params->tenantId(),
5052
],
5153
];
5254
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
3+
namespace OpenStack\Networking\v2\Extensions\Layer3;
4+
5+
use OpenCloud\Common\Api\AbstractApi;
6+
7+
class Api extends AbstractApi
8+
{
9+
private $pathPrefix = 'v2.0';
10+
11+
public function __construct()
12+
{
13+
$this->params = new Params();
14+
}
15+
16+
public function postFloatingIps(): array
17+
{
18+
return [
19+
'method' => 'POST',
20+
'path' => $this->pathPrefix . '/floatingips',
21+
'jsonKey' => 'floatingip',
22+
'params' => [
23+
'tenantId' => $this->params->tenantIdJson(),
24+
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
25+
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
26+
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
27+
'portId' => $this->params->portIdJson(),
28+
],
29+
];
30+
}
31+
32+
public function getFloatingIps(): array
33+
{
34+
return [
35+
'method' => 'GET',
36+
'path' => $this->pathPrefix . '/floatingips',
37+
'params' => [],
38+
];
39+
}
40+
41+
public function putFloatingIp(): array
42+
{
43+
return [
44+
'method' => 'PUT',
45+
'path' => $this->pathPrefix . '/floatingips/{id}',
46+
'jsonKey' => 'floatingip',
47+
'params' => [
48+
'id' => $this->params->idPath(),
49+
'floatingNetworkId' => $this->params->floatingNetworkIdJson(),
50+
'fixedIpAddress' => $this->params->fixedIpAddressJson(),
51+
'floatingIpAddress' => $this->params->floatingIpAddressJson(),
52+
'portId' => $this->params->portIdJson(),
53+
],
54+
];
55+
}
56+
57+
public function getFloatingIp(): array
58+
{
59+
return [
60+
'method' => 'GET',
61+
'path' => $this->pathPrefix . '/floatingips/{id}',
62+
'params' => [
63+
'id' => $this->params->idPath(),
64+
'portId' => $this->params->portIdJson(),
65+
],
66+
];
67+
}
68+
69+
public function deleteFloatingIp(): array
70+
{
71+
return [
72+
'method' => 'DELETE',
73+
'path' => $this->pathPrefix . '/floatingips/{id}',
74+
'params' => [
75+
'id' => $this->params->idPath(),
76+
],
77+
];
78+
}
79+
80+
public function postRouters(): array
81+
{
82+
return [
83+
'method' => 'POST',
84+
'path' => $this->pathPrefix . '/routers',
85+
'jsonKey' => 'router',
86+
'params' => [
87+
'name' => $this->params->nameJson(),
88+
'externalGatewayInfo' => $this->params->externalGatewayInfo(),
89+
'adminStateUp' => $this->params->adminStateUp(),
90+
'tenantId' => $this->params->tenantId(),
91+
'distributed' => $this->params->distributedJson(),
92+
'ha' => $this->params->haJson(),
93+
],
94+
];
95+
}
96+
97+
public function getRouters(): array
98+
{
99+
return [
100+
'method' => 'GET',
101+
'path' => $this->pathPrefix . '/routers',
102+
'params' => [],
103+
];
104+
}
105+
106+
public function putRouter(): array
107+
{
108+
return [
109+
'method' => 'PUT',
110+
'path' => $this->pathPrefix . '/routers/{id}',
111+
'jsonKey' => 'router',
112+
'params' => [
113+
'id' => $this->params->idPath(),
114+
'name' => $this->params->nameJson(),
115+
'externalGatewayInfo' => $this->params->externalGatewayInfo(),
116+
'adminStateUp' => $this->params->adminStateUp(),
117+
],
118+
];
119+
}
120+
121+
public function getRouter(): array
122+
{
123+
return [
124+
'method' => 'GET',
125+
'path' => $this->pathPrefix . '/routers/{id}',
126+
'params' => [
127+
'id' => $this->params->idPath(),
128+
],
129+
];
130+
}
131+
132+
public function deleteRouter(): array
133+
{
134+
return [
135+
'method' => 'DELETE',
136+
'path' => $this->pathPrefix . '/routers/{id}',
137+
'params' => [
138+
'id' => $this->params->idPath(),
139+
],
140+
];
141+
}
142+
143+
public function putAddInterface()
144+
{
145+
return [
146+
'method' => 'PUT',
147+
'path' => $this->pathPrefix . '/routers/{id}/add_router_interface',
148+
'params' => [
149+
'id' => $this->params->idPath(),
150+
'subnetId' => $this->params->subnetId(),
151+
'portId' => $this->params->portIdJson(),
152+
],
153+
];
154+
}
155+
156+
public function putRemoveInterface()
157+
{
158+
return [
159+
'method' => 'PUT',
160+
'path' => $this->pathPrefix . '/routers/{id}/remove_router_interface',
161+
'params' => [
162+
'id' => $this->params->idPath(),
163+
'subnetId' => $this->params->subnetId(),
164+
'portId' => $this->params->portIdJson(),
165+
],
166+
];
167+
}
168+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace OpenStack\Networking\v2\Extensions\Layer3\Models;
4+
5+
use OpenCloud\Common\Resource\AbstractResource;
6+
7+
class FixedIp extends AbstractResource
8+
{
9+
/** @var string */
10+
public $subnetId;
11+
12+
/** @var string */
13+
public $ip;
14+
15+
protected $aliases = [
16+
'subnet_id' => 'subnetId'
17+
];
18+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace OpenStack\Networking\v2\Extensions\Layer3\Models;
4+
5+
use OpenCloud\Common\Resource\OperatorResource;
6+
use OpenCloud\Common\Resource\Creatable;
7+
use OpenCloud\Common\Resource\Deletable;
8+
use OpenCloud\Common\Resource\Listable;
9+
use OpenCloud\Common\Resource\Retrievable;
10+
use OpenCloud\Common\Resource\Updateable;
11+
use OpenStack\Networking\v2\Extensions\Layer3\Api;
12+
13+
/**
14+
* @property Api $api
15+
*/
16+
class FloatingIp extends OperatorResource implements Listable, Creatable, Retrievable, Updateable, Deletable
17+
{
18+
/** @var string */
19+
public $id;
20+
21+
/** @var string */
22+
public $status;
23+
24+
/** @var string */
25+
public $floatingNetworkId;
26+
27+
/** @var string */
28+
public $routerId;
29+
30+
/** @var string */
31+
public $fixedIpAddress;
32+
33+
/** @var string */
34+
public $floatingIpAddress;
35+
36+
/** @var string */
37+
public $tenantId;
38+
39+
/** @var string */
40+
public $portId;
41+
42+
protected $aliases = [
43+
"floating_network_id" => 'floatingNetworkId',
44+
"router_id" => 'routerId',
45+
"fixed_ip_address" => 'fixedIpAddress',
46+
"floating_ip_address" => 'floatingIpAddress',
47+
"tenant_id" => 'tenantId',
48+
"port_id" => 'portId',
49+
];
50+
51+
protected $resourceKey = 'floatingip';
52+
protected $resourcesKey = 'floatingips';
53+
54+
public function create(array $userOptions): Creatable
55+
{
56+
$response = $this->execute($this->api->postFloatingIps(), $userOptions);
57+
return $this->populateFromResponse($response);
58+
}
59+
60+
public function update()
61+
{
62+
$response = $this->executeWithState($this->api->putFloatingIp());
63+
$this->populateFromResponse($response);
64+
}
65+
66+
public function delete()
67+
{
68+
$this->executeWithState($this->api->deleteFloatingIp());
69+
}
70+
71+
public function retrieve()
72+
{
73+
$this->executeWithState($this->api->getFloatingIp());
74+
}
75+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace OpenStack\Networking\v2\Extensions\Layer3\Models;
4+
5+
use OpenCloud\Common\Resource\AbstractResource;
6+
7+
class GatewayInfo extends AbstractResource
8+
{
9+
/** @var string */
10+
public $networkId;
11+
12+
/** @var string */
13+
public $enableSnat;
14+
15+
/** @var []FixedIp */
16+
public $fixedIps;
17+
18+
protected $aliases = [
19+
'network_id' => 'networkId',
20+
'enable_snat' => 'enableSnat',
21+
'fixed_ips' => 'fixedIps',
22+
];
23+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace OpenStack\Networking\v2\Extensions\Layer3\Models;
4+
5+
use OpenCloud\Common\Resource\OperatorResource;
6+
use OpenCloud\Common\Resource\Creatable;
7+
use OpenCloud\Common\Resource\Deletable;
8+
use OpenCloud\Common\Resource\Listable;
9+
use OpenCloud\Common\Resource\Retrievable;
10+
use OpenCloud\Common\Resource\Updateable;
11+
use OpenStack\Networking\v2\Extensions\Layer3\Api;
12+
13+
/**
14+
* @property Api $api
15+
*/
16+
class Router extends OperatorResource implements Listable, Creatable, Retrievable, Updateable, Deletable
17+
{
18+
/** @var string */
19+
public $status;
20+
21+
/** @var GatewayInfo */
22+
public $externalGatewayInfo;
23+
24+
/** @var string */
25+
public $name;
26+
27+
/** @var string */
28+
public $adminStateUp;
29+
30+
/** @var string */
31+
public $tenantId;
32+
33+
/** @var array */
34+
public $routes;
35+
36+
/** @var string */
37+
public $id;
38+
39+
protected $aliases = [
40+
'external_gateway_info' => 'externalGatewayInfo',
41+
'admin_state_up' => 'adminStateUp',
42+
'tenant_id' => 'tenantId',
43+
];
44+
45+
public function create(array $userOptions): Creatable
46+
{
47+
$response = $this->execute($this->api->postRouters(), $userOptions);
48+
return $this->populateFromResponse($response);
49+
}
50+
51+
public function update()
52+
{
53+
$this->executeWithState($this->api->putRouter());
54+
}
55+
56+
public function retrieve()
57+
{
58+
$this->executeWithState($this->api->getRouter());
59+
}
60+
61+
public function delete()
62+
{
63+
$this->executeWithState($this->api->deleteRouter());
64+
}
65+
66+
/**
67+
* @param array $userOptions {@see \OpenStack\Networking\v2\Extensions\Layer3\Api::putAddInterface}
68+
*/
69+
public function addInterface(array $userOptions)
70+
{
71+
$userOptions['id'] = $this->id;
72+
$this->execute($this->api->putAddInterface(), $userOptions);
73+
}
74+
75+
/**
76+
* @param array $userOptions {@see \OpenStack\Networking\v2\Extensions\Layer3\Api::putRemoveInterface}
77+
*/
78+
public function removeInterface(array $userOptions)
79+
{
80+
$userOptions['id'] = $this->id;
81+
$this->execute($this->api->putRemoveInterface(), $userOptions);
82+
}
83+
}

0 commit comments

Comments
 (0)