Skip to content

Commit 526745f

Browse files
committed
Networking: portSecurity, routerExternal for Network
1 parent 0aad1d0 commit 526745f

File tree

6 files changed

+72
-22
lines changed

6 files changed

+72
-22
lines changed

src/Networking/v2/Api.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public function getNetworks(): array
3535
'method' => 'GET',
3636
'path' => $this->pathPrefix.'/networks',
3737
'params' => [
38-
'name' => $this->params->queryName(),
39-
'tenantId' => $this->params->queryTenantId(),
40-
'status' => $this->params->queryStatus(),
38+
'name' => $this->params->queryName(),
39+
'tenantId' => $this->params->queryTenantId(),
40+
'status' => $this->params->queryStatus(),
41+
'routerExternal' => $this->params->queryRouterExternal(),
4142
],
4243
];
4344
}
@@ -201,7 +202,7 @@ public function getPorts(): array
201202
'displayName' => $this->params->displayNameQuery(),
202203
'adminState' => $this->params->adminStateQuery(),
203204
'networkId' => $this->notRequired($this->params->networkId()),
204-
'tenantId' => $this->params->tenantId(),
205+
'tenantId' => $this->params->tenantIdQuery(),
205206
'deviceOwner' => $this->params->deviceOwnerQuery(),
206207
'macAddress' => $this->params->macAddrQuery(),
207208
'portId' => $this->params->portIdQuery(),
@@ -230,6 +231,7 @@ public function postSinglePort(): array
230231
'allowedAddressPairs' => $this->params->allowedAddrPairs(),
231232
'deviceOwner' => $this->params->deviceOwner(),
232233
'deviceId' => $this->params->deviceId(),
234+
'portSecurityEnabled' => $this->params->portSecurityEnabled(),
233235
],
234236
];
235237
}

src/Networking/v2/Models/Network.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ class Network extends OperatorResource implements Listable, Retrievable, Creatab
4141
/** @var string */
4242
public $tenantId;
4343

44+
/** @var bool */
45+
public $routerExternal;
46+
4447
protected $aliases = [
45-
'admin_state_up' => 'adminStateUp',
46-
'tenant_id' => 'tenantId',
48+
'admin_state_up' => 'adminStateUp',
49+
'tenant_id' => 'tenantId',
50+
'router:external' => 'routerExternal',
4751
];
4852

4953
protected $resourceKey = 'network';

src/Networking/v2/Models/Port.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Port extends OperatorResource implements Creatable, Updateable, Deletable,
3636
/**
3737
* A set of zero or more allowed address pairs. An address pair consists of an IP address and MAC address.
3838
*
39-
* @var []string
39+
* @var array
4040
*/
4141
public $allowedAddressPairs;
4242

@@ -119,19 +119,22 @@ class Port extends OperatorResource implements Creatable, Updateable, Deletable,
119119
public $portSecurityEnabled;
120120

121121
protected $aliases = [
122-
'admin_state_up' => 'adminStateUp',
123-
'display_name' => 'displayName',
124-
'network_id' => 'networkId',
125-
'tenant_id' => 'tenantId',
126-
'device_owner' => 'deviceOwner',
127-
'mac_address' => 'macAddress',
128-
'port_id' => 'portId',
129-
'security_groups' => 'securityGroups',
130-
'device_id' => 'deviceId',
131-
'fixed_ips' => 'fixedIps',
122+
'port_security_enabled' => 'portSecurityEnabled',
123+
'admin_state_up' => 'adminStateUp',
124+
'display_name' => 'displayName',
125+
'network_id' => 'networkId',
126+
'tenant_id' => 'tenantId',
127+
'device_owner' => 'deviceOwner',
128+
'mac_address' => 'macAddress',
129+
'port_id' => 'portId',
130+
'security_groups' => 'securityGroups',
131+
'device_id' => 'deviceId',
132+
'fixed_ips' => 'fixedIps',
133+
'allowed_address_pairs' => 'allowedAddressPairs',
132134
];
133135

134-
protected $resourceKey = 'port';
136+
protected $resourceKey = 'port';
137+
protected $resourcesKey = 'ports';
135138

136139
/**
137140
* {@inheritdoc}

src/Networking/v2/Params.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public function adminStateUp(): array
6161
];
6262
}
6363

64+
public function portSecurityEnabled(): array
65+
{
66+
return [
67+
'type' => self::BOOL_TYPE,
68+
'location' => self::JSON,
69+
'sentAs' => 'port_security_enabled',
70+
'description' => 'The port security status. A valid value is enabled (true) or disabled (false). If port security is enabled for the port, security
71+
group rules and anti-spoofing rules are applied to the traffic on the port. If disabled, no such rules are applied.',
72+
];
73+
}
74+
6475
public function networkId(): array
6576
{
6677
return [
@@ -100,6 +111,16 @@ public function tenantId(): array
100111
];
101112
}
102113

114+
public function projectId(): array
115+
{
116+
return [
117+
'type' => self::STRING_TYPE,
118+
'sentAs' => 'project_id',
119+
'location' => self::QUERY,
120+
'description' => 'The ID of the tenant who owns the network. Only administrative users can specify a tenant ID other than their own. You cannot change this value through authorization policies',
121+
];
122+
}
123+
103124
public function gatewayIp(): array
104125
{
105126
return [
@@ -337,6 +358,7 @@ public function secGroupIds(): array
337358
return [
338359
'type' => self::ARRAY_TYPE,
339360
'location' => self::JSON,
361+
'sentAs' => 'security_groups',
340362
'items' => [
341363
'type' => self::STRING_TYPE,
342364
'description' => 'The UUID of the security group',
@@ -426,6 +448,15 @@ public function routerAccessibleJson(): array
426448
];
427449
}
428450

451+
public function queryRouterExternal(): array
452+
{
453+
return [
454+
'type' => self::BOOL_TYPE,
455+
'location' => self::QUERY,
456+
'sentAs' => 'router:external',
457+
];
458+
}
459+
429460
protected function quotaLimit(string $sentAs, string $description): array
430461
{
431462
return [

tests/unit/Networking/v2/Fixtures/port_get.resp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Content-Type: application/json
44
{
55
"port": {
66
"status": "ACTIVE",
7-
"name": "",
7+
"name": "port-name",
88
"allowed_address_pairs": [],
99
"admin_state_up": true,
1010
"network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7",
1111
"tenant_id": "7e02058126cc4950b75f9970368ba177",
1212
"extra_dhcp_opts": [],
1313
"device_owner": "network:router_interface",
14-
"mac_address": "fa:16:3e:23:fd:d7",
14+
"mac_address": "00:11:22:33:44:55",
1515
"fixed_ips": [
1616
{
1717
"subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2",
@@ -20,6 +20,7 @@ Content-Type: application/json
2020
],
2121
"id": "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
2222
"security_groups": [],
23-
"device_id": "5e3898d7-11be-483e-9732-b2f5eccd2b2e"
23+
"device_id": "fake-device-id",
24+
"port_security_enabled": true
2425
}
2526
}

tests/unit/Networking/v2/Models/PortTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,18 @@ public function test_it_updates()
4949

5050
public function test_it_retrieves()
5151
{
52-
$this->setupMock('GET', 'v2.0/ports/' . self::PORT_ID, null, [], new Response(204));
52+
$this->setupMock('GET', 'v2.0/ports/' . self::PORT_ID, null, [], 'port_get');
5353

5454
$this->port->retrieve();
55+
$this->assertEquals('46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2', $this->port->id);
56+
$this->assertEquals('ACTIVE', $this->port->status);
57+
$this->assertEquals('port-name', $this->port->name);
58+
$this->assertEquals(true, $this->port->adminStateUp);
59+
$this->assertEquals(true,$this->port->portSecurityEnabled);
60+
$this->assertEquals('network:router_interface', $this->port->deviceOwner);
61+
$this->assertEquals('fake-device-id', $this->port->deviceId);
62+
$this->assertEquals('00:11:22:33:44:55', $this->port->macAddress);
63+
$this->assertCount(1, $this->port->fixedIps);
5564
}
5665

5766
public function test_it_deletes()

0 commit comments

Comments
 (0)