[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DrydockPreallocatedHostBlueprintImplementation 4 extends DrydockBlueprintImplementation { 5 6 public function isEnabled() { 7 return true; 8 } 9 10 public function getBlueprintName() { 11 return pht('Preallocated Remote Hosts'); 12 } 13 14 public function getDescription() { 15 return pht('Allows Drydock to run on specific remote hosts you configure.'); 16 } 17 18 public function canAllocateMoreResources(array $pool) { 19 return false; 20 } 21 22 protected function executeAllocateResource(DrydockLease $lease) { 23 throw new Exception("Preallocated hosts can't be dynamically allocated."); 24 } 25 26 protected function canAllocateLease( 27 DrydockResource $resource, 28 DrydockLease $lease) { 29 return 30 $lease->getAttribute('platform') === $resource->getAttribute('platform'); 31 } 32 33 protected function shouldAllocateLease( 34 DrydockResource $resource, 35 DrydockLease $lease, 36 array $other_leases) { 37 return true; 38 } 39 40 protected function executeAcquireLease( 41 DrydockResource $resource, 42 DrydockLease $lease) { 43 44 // Because preallocated resources are manually created, we should verify 45 // we have all the information we need. 46 PhutilTypeSpec::checkMap( 47 $resource->getAttributesForTypeSpec( 48 array('platform', 'host', 'port', 'credential', 'path')), 49 array( 50 'platform' => 'string', 51 'host' => 'string', 52 'port' => 'string', // Value is a string from the command line 53 'credential' => 'string', 54 'path' => 'string', 55 )); 56 $v_platform = $resource->getAttribute('platform'); 57 $v_path = $resource->getAttribute('path'); 58 59 // Similar to DrydockLocalHostBlueprint, we create a folder 60 // on the remote host that the lease can use. 61 62 $lease_id = $lease->getID(); 63 64 // Can't use DIRECTORY_SEPERATOR here because that is relevant to 65 // the platform we're currently running on, not the platform we are 66 // remoting to. 67 $separator = '/'; 68 if ($v_platform === 'windows') { 69 $separator = '\\'; 70 } 71 72 // Clean up the directory path a little. 73 $base_path = rtrim($v_path, '/'); 74 $base_path = rtrim($base_path, '\\'); 75 $full_path = $base_path.$separator.$lease_id; 76 77 $cmd = $lease->getInterface('command'); 78 79 if ($v_platform !== 'windows') { 80 $cmd->execx('mkdir %s', $full_path); 81 } else { 82 // Windows is terrible. The mkdir command doesn't even support putting 83 // the path in quotes. IN QUOTES. ARGUHRGHUGHHGG!! Do some terribly 84 // inaccurate sanity checking since we can't safely escape the path. 85 if (preg_match('/^[A-Z]\\:\\\\[a-zA-Z0-9\\\\\\ ]/', $full_path) === 0) { 86 throw new Exception( 87 'Unsafe path detected for Windows platform: "'.$full_path.'".'); 88 } 89 $cmd->execx('mkdir %C', $full_path); 90 } 91 92 $lease->setAttribute('path', $full_path); 93 } 94 95 public function getType() { 96 return 'host'; 97 } 98 99 public function getInterface( 100 DrydockResource $resource, 101 DrydockLease $lease, 102 $type) { 103 104 switch ($type) { 105 case 'command': 106 return id(new DrydockSSHCommandInterface()) 107 ->setConfiguration(array( 108 'host' => $resource->getAttribute('host'), 109 'port' => $resource->getAttribute('port'), 110 'credential' => $resource->getAttribute('credential'), 111 'platform' => $resource->getAttribute('platform'), 112 )) 113 ->setWorkingDirectory($lease->getAttribute('path')); 114 case 'filesystem': 115 return id(new DrydockSFTPFilesystemInterface()) 116 ->setConfiguration(array( 117 'host' => $resource->getAttribute('host'), 118 'port' => $resource->getAttribute('port'), 119 'credential' => $resource->getAttribute('credential'), 120 )); 121 } 122 123 throw new Exception("No interface of type '{$type}'."); 124 } 125 126 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |