Differential D10547 Diff 25906 src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | final class DrydockPreallocatedHostBlueprintImplementation | ||||
protected function executeAcquireLease( | protected function executeAcquireLease( | ||||
DrydockResource $resource, | DrydockResource $resource, | ||||
DrydockLease $lease) { | DrydockLease $lease) { | ||||
// Because preallocated resources are manually created, we should verify | // Because preallocated resources are manually created, we should verify | ||||
// we have all the information we need. | // we have all the information we need. | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$resource->getAttributesForTypeSpec( | $resource->getAttributesForTypeSpec( | ||||
array('platform', 'host', 'port', 'credential', 'path')), | array('platform', 'protocol', 'host', 'port', 'credential', 'path')), | ||||
array( | array( | ||||
'platform' => 'string', | 'platform' => 'string', | ||||
'protocol' => 'string', | |||||
'host' => 'string', | 'host' => 'string', | ||||
'port' => 'string', // Value is a string from the command line | 'port' => 'string', // Value is a string from the command line | ||||
'credential' => 'string', | 'credential' => 'string', | ||||
'path' => 'string', | 'path' => 'string', | ||||
)); | )); | ||||
$v_platform = $resource->getAttribute('platform'); | $v_platform = $resource->getAttribute('platform'); | ||||
$v_protocol = $resource->getAttribute('protocol'); | |||||
$v_path = $resource->getAttribute('path'); | $v_path = $resource->getAttribute('path'); | ||||
// Verify the provided protocol. | |||||
if ($v_platform === 'windows') { | |||||
if ($v_protocol !== 'ssh' && $v_protocol !== 'winrm') { | |||||
throw new Exception( | |||||
'Invalid protocol set for Windows platform; '. | |||||
'expected \'ssh\' or \'winrm\'.'); | |||||
} | |||||
} else { | |||||
if ($v_protocol !== 'ssh') { | |||||
throw new Exception( | |||||
'Invalid protocol set for UNIX platform; '. | |||||
'expected \'ssh\'.'); | |||||
} | |||||
} | |||||
// Similar to DrydockLocalHostBlueprint, we create a folder | // Similar to DrydockLocalHostBlueprint, we create a folder | ||||
// on the remote host that the lease can use. | // on the remote host that the lease can use. | ||||
$lease_id = $lease->getID(); | $lease_id = $lease->getID(); | ||||
// Can't use DIRECTORY_SEPERATOR here because that is relevant to | // Can't use DIRECTORY_SEPERATOR here because that is relevant to | ||||
// the platform we're currently running on, not the platform we are | // the platform we're currently running on, not the platform we are | ||||
// remoting to. | // remoting to. | ||||
Show All 20 Lines | final class DrydockPreallocatedHostBlueprintImplementation | ||||
public function getInterface( | public function getInterface( | ||||
DrydockResource $resource, | DrydockResource $resource, | ||||
DrydockLease $lease, | DrydockLease $lease, | ||||
$type) { | $type) { | ||||
switch ($type) { | switch ($type) { | ||||
case 'command': | case 'command': | ||||
return id(new DrydockSSHCommandInterface()) | $interface = new DrydockSSHCommandInterface(); | ||||
if ($resource->getAttribute('protocol') === 'winrm') { | |||||
$interface = new DrydockWinRMCommandInterface(); | |||||
} | |||||
return $interface | |||||
->setConfiguration(array( | ->setConfiguration(array( | ||||
'host' => $resource->getAttribute('host'), | 'host' => $resource->getAttribute('host'), | ||||
'port' => $resource->getAttribute('port'), | 'port' => $resource->getAttribute('port'), | ||||
'credential' => $resource->getAttribute('credential'), | 'credential' => $resource->getAttribute('credential'), | ||||
'platform' => $resource->getAttribute('platform'), | 'platform' => $resource->getAttribute('platform'), | ||||
)) | )) | ||||
->setWorkingDirectory($lease->getAttribute('path')); | ->setWorkingDirectory($lease->getAttribute('path')); | ||||
case 'filesystem': | case 'filesystem': | ||||
Show All 28 Lines |