Skip to content

Commit 8003494

Browse files
committed
Add get interface attachment
1 parent 40c88f0 commit 8003494

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
$openstack = new OpenStack\OpenStack([
6+
'authUrl' => '{authUrl}',
7+
'region' => '{region}',
8+
'user' => [
9+
'id' => '{userId}',
10+
'password' => '{password}'
11+
],
12+
'scope' => ['project' => ['id' => '{projectId}']]
13+
]);
14+
15+
$compute = $openstack->computeV2(['region' => '{region}']);
16+
17+
$server = $compute->getServer(['id' => '{serverId}']);
18+
19+
$server->getInterfaceAttachment('{portId}');

src/Compute/v2/Api.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,18 @@ public function getInterfaceAttachments(): array
471471
];
472472
}
473473

474+
public function getInterfaceAttachment(): array
475+
{
476+
return [
477+
'method' => 'GET',
478+
'path' => 'servers/{id}/os-interface/{portId}',
479+
'params' => [
480+
'id' => $this->params->urlId('server'),
481+
'portId' => $this->params->portId()
482+
]
483+
];
484+
}
485+
474486
public function postInterfaceAttachment(): array
475487
{
476488
return [
@@ -494,7 +506,7 @@ public function deleteInterfaceAttachment(): array
494506
'path' => 'servers/{id}/os-interface/{portId}',
495507
'params' => [
496508
'id' => $this->params->urlId('image'),
497-
'portId' => $this->params->portId(),
509+
'portId' => $this->params->portId()
498510
]
499511
];
500512
}

src/Compute/v2/Models/Server.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ public function listInterfaceAttachments(array $options = []): \Generator
328328
return $this->model(InterfaceAttachment::class)->enumerate($this->api->getInterfaceAttachments(), ['id' => $this->id]);
329329
}
330330

331+
/**
332+
* Gets an interface attachment.
333+
*
334+
* @param string $portId The unique ID of the port.
335+
* @return InterfaceAttachment
336+
*/
337+
public function getInterfaceAttachment($portId): InterfaceAttachment
338+
{
339+
$response = $this->execute($this->api->getInterfaceAttachment(), [
340+
'id' => $this->id,
341+
'portId' => $portId
342+
]);
343+
344+
return $this->model(InterfaceAttachment::class)->populateFromResponse($response);
345+
}
346+
331347
/**
332348
* Creates an interface attachment.
333349
*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"interfaceAttachment": {
6+
"port_state": "ACTIVE",
7+
"fixed_ips": [
8+
{
9+
"subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef",
10+
"ip_address": "192.168.1.3"
11+
}
12+
],
13+
"port_id": "ce531f90-199f-48c0-816c-13e38010b442",
14+
"net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6",
15+
"mac_addr": "fa:16:3e:4c:2c:30"
16+
}
17+
}

tests/unit/Compute/v2/Models/ServerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,23 @@ public function test_it_lists_interface_attachments()
444444
$this->assertInstanceOf(InterfaceAttachment::class, $interfaceAttachments[0]);
445445
}
446446

447+
/** @test */
448+
public function it_gets_interface_attachments()
449+
{
450+
$portId = 'fooooobarrrr';
451+
452+
$this->setupMock('GET', 'servers/serverId/os-interface/' . $portId, ['port_id' => 'fooooobarrrr'], [], 'server-interface-attachment-get');
453+
454+
$interfaceAttachment = $this->server->getInterfaceAttachment($portId);
455+
456+
$this->assertEquals('ce531f90-199f-48c0-816c-13e38010b442', $interfaceAttachment->portId);
457+
$this->assertEquals('ACTIVE', $interfaceAttachment->portState);
458+
$this->assertEquals('3cb9bc59-5699-4588-a4b1-b87f96708bc6', $interfaceAttachment->netId);
459+
$this->assertEquals('fa:16:3e:4c:2c:30', $interfaceAttachment->macAddr);
460+
$this->assertEquals('192.168.1.3', $interfaceAttachment->fixedIps[0]['ip_address']);
461+
$this->assertEquals('f8a6e8f8-c2ec-497c-9f23-da9616de54ef', $interfaceAttachment->fixedIps[0]['subnet_id']);
462+
}
463+
447464
/** @test */
448465
public function test_it_creates_interface_attachments()
449466
{

0 commit comments

Comments
 (0)