Skip to content

Commit 40c88f0

Browse files
committed
Add interface detaching
1 parent f9e5054 commit 40c88f0

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
/**@var OpenStack\Compute\v2\Models\Server $server */
18+
$server = $compute->getServer(['id' => '{serverId}']);
19+
20+
$server->detachInterface('{portId}');

src/Compute/v2/Api.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,18 @@ public function postInterfaceAttachment(): array
487487
];
488488
}
489489

490+
public function deleteInterfaceAttachment(): array
491+
{
492+
return [
493+
'method' => 'DELETE',
494+
'path' => 'servers/{id}/os-interface/{portId}',
495+
'params' => [
496+
'id' => $this->params->urlId('image'),
497+
'portId' => $this->params->portId(),
498+
]
499+
];
500+
}
501+
490502
public function getServerMetadata(): array
491503
{
492504
return [

src/Compute/v2/Models/Server.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ public function createInterfaceAttachment(array $userOptions): InterfaceAttachme
344344
return $this->model(InterfaceAttachment::class)->populateFromResponse($response);
345345
}
346346

347+
/**
348+
* Detaches an interface attachment.
349+
*
350+
* @param string $portId
351+
*/
352+
public function detachInterface(string $portId)
353+
{
354+
$this->execute($this->api->deleteInterfaceAttachment(), [
355+
'id' => $this->id,
356+
'portId' => $portId,
357+
]);
358+
}
359+
347360
/**
348361
* Retrieves metadata from the API.
349362
*

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,13 @@ public function test_it_creates_interface_attachments()
460460
$this->assertEquals('ACTIVE', $interfaceAttachment->portState);
461461
$this->assertEquals('10.0.0.1', $interfaceAttachment->fixedIps[0]['ip_address']);
462462
}
463+
464+
public function test_it_detaches_interfaces()
465+
{
466+
$portId = 'a-dummy-port-id';
467+
468+
$this->setupMock('DELETE', 'servers/serverId/os-interface/' . $portId, ['port_id' => $portId], [], new Response(202));
469+
470+
$this->server->detachInterface($portId);
471+
}
463472
}

0 commit comments

Comments
 (0)