|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Networking\v2\Models; |
|
4
|
|
|
|
|
5
|
|
|
use OpenStack\Common\Resource\OperatorResource; |
|
6
|
|
|
use OpenStack\Common\Resource\Listable; |
|
7
|
|
|
use OpenStack\Common\Resource\Creatable; |
|
8
|
|
|
use OpenStack\Common\Resource\Updateable; |
|
9
|
|
|
use OpenStack\Common\Resource\Deletable; |
|
10
|
|
|
use OpenStack\Common\Resource\Retrievable; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Represents a Networking v2 Network. |
|
14
|
|
|
* |
|
15
|
|
|
* @property \OpenStack\Networking\v2\Api $api |
|
16
|
|
|
*/ |
|
17
|
|
|
class Subnet extends OperatorResource implements Listable, Retrievable, Creatable, Deletable, Updateable |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
public $id; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
public $name; |
|
24
|
|
|
|
|
25
|
|
|
/** @var bool */ |
|
26
|
|
|
public $enableDhcp; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
public $networkId; |
|
30
|
|
|
|
|
31
|
|
|
/** @var array */ |
|
32
|
|
|
public $dnsNameservers; |
|
33
|
|
|
|
|
34
|
|
|
/** @var array */ |
|
35
|
|
|
public $allocationPools; |
|
36
|
|
|
|
|
37
|
|
|
/** @var array */ |
|
38
|
|
|
public $hostRoutes; |
|
39
|
|
|
|
|
40
|
|
|
/** @var int */ |
|
41
|
|
|
public $ipVersion; |
|
42
|
|
|
|
|
43
|
|
|
/** @var string */ |
|
44
|
|
|
public $gatewayIp; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
public $cidr; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string */ |
|
50
|
|
|
public $tenantId; |
|
51
|
|
|
|
|
52
|
|
|
/** @var array */ |
|
53
|
|
|
public $links; |
|
54
|
|
|
|
|
55
|
|
|
protected $aliases = [ |
|
56
|
|
|
'enable_dhcp' => 'enableDhcp', |
|
57
|
|
|
'network_id' => 'networkId', |
|
58
|
|
|
'dns_nameservers' => 'dnsNameservers', |
|
59
|
|
|
'allocation_pools' => 'allocationPools', |
|
60
|
|
|
'host_routes' => 'hostRoutes', |
|
61
|
|
|
'ip_version' => 'ipVersion', |
|
62
|
|
|
'gateway_ip' => 'gatewayIp', |
|
63
|
|
|
'tenant_id' => 'tenantId' |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
protected $resourceKey = 'subnet'; |
|
67
|
|
|
protected $resourcesKey = 'subnets'; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritDoc} |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function retrieve() |
|
73
|
|
|
{ |
|
74
|
1 |
|
$response = $this->execute($this->api->getSubnet(), ['id' => (string)$this->id]); |
|
75
|
1 |
|
$this->populateFromResponse($response); |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Creates multiple subnets in a single request. |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $data {@see \OpenStack\Networking\v2\Api::postSubnets} |
|
82
|
|
|
* |
|
83
|
|
|
* @return Subnet[] |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function bulkCreate(array $data): array |
|
86
|
|
|
{ |
|
87
|
2 |
|
$response = $this->execute($this->api->postSubnets(), ['subnets' => $data]); |
|
88
|
2 |
|
return $this->extractMultipleInstances($response); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* {@inheritDoc} |
|
93
|
|
|
* |
|
94
|
|
|
* @param array $data {@see \OpenStack\Networking\v2\Api::postSubnet} |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function create(array $data): Creatable |
|
97
|
|
|
{ |
|
98
|
2 |
|
$response = $this->execute($this->api->postSubnet(), $data); |
|
99
|
2 |
|
return $this->populateFromResponse($response); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* {@inheritDoc} |
|
104
|
|
|
*/ |
|
105
|
1 |
|
public function update() |
|
106
|
|
|
{ |
|
107
|
1 |
|
$response = $this->executeWithState($this->api->putSubnet()); |
|
108
|
1 |
|
$this->populateFromResponse($response); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritDoc} |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function delete() |
|
115
|
|
|
{ |
|
116
|
1 |
|
$this->executeWithState($this->api->deleteSubnet()); |
|
117
|
1 |
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* {@inheritDoc} |
|
121
|
|
|
*/ |
|
122
|
|
|
protected function getAttrs(array $keys) |
|
123
|
|
|
{ |
|
124
|
|
|
$output = parent::getAttrs($keys); |
|
125
|
|
|
|
|
126
|
|
|
if ($this->gatewayIp === '') { |
|
127
|
|
|
$output['gatewayIp'] = null; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $output; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|