1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-22 18:28:47 +02:00
phorge-phorge/src/applications/drydock/blueprint/DrydockLocalHostBlueprint.php
epriestley e4bb9255be Allow leases to be explicitly released via web or CLI
Summary: Permit the forcible release of Drydock leases. The implementation isn't very exciting for now.

Test Plan: Released leases via web and CLI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D4181
2012-12-14 15:42:58 -08:00

83 lines
1.9 KiB
PHP

<?php
final class DrydockLocalHostBlueprint extends DrydockBlueprint {
public function isEnabled() {
return PhabricatorEnv::getEnvConfig('drydock.localhost.enabled');
}
public function canAllocateMoreResources(array $pool) {
assert_instances_of($pool, 'DrydockResource');
// The localhost can be allocated only once.
foreach ($pool as $resource) {
if ($resource->getBlueprintClass() == $this->getBlueprintClass()) {
return false;
}
}
return true;
}
protected function executeAllocateResource(DrydockLease $lease) {
$path = PhabricatorEnv::getEnvConfig('drydock.localhost.path');
if (!Filesystem::pathExists($path)) {
throw new Exception(
"Path '{$path}' does not exist!");
}
Filesystem::assertIsDirectory($path);
Filesystem::assertWritable($path);
$resource = $this->newResourceTemplate('localhost');
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
$resource->setAttribute('path', $path);
$resource->save();
return $resource;
}
protected function canAllocateLease(
DrydockResource $resource,
DrydockLease $lease) {
return true;
}
protected function shouldAllocateLease(
DrydockResource $resource,
DrydockLease $lease,
array $other_leases) {
return true;
}
protected function executeAcquireLease(
DrydockResource $resource,
DrydockLease $lease) {
$lease_id = $lease->getID();
$full_path = $resource->getAttribute('path').$lease_id.'/';
$cmd = $lease->getInterface('command');
$cmd->execx('mkdir %s', $full_path);
$lease->setAttribute('path', $full_path);
}
public function getType() {
return 'host';
}
public function getInterface(
DrydockResource $resource,
DrydockLease $lease,
$type) {
switch ($type) {
case 'command':
return new DrydockLocalCommandInterface();
}
throw new Exception("No interface of type '{$type}'.");
}
}