setName('lease') ->setSynopsis('Lease a resource.') ->setArguments( array( array( 'name' => 'type', 'param' => 'resource_type', 'help' => 'Resource type.', ), array( 'name' => 'spec', 'param' => 'name=value,...', 'help' => 'Resource specficiation.', ), )); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $resource_type = $args->getArg('type'); if (!$resource_type) { throw new PhutilArgumentUsageException( "Specify a resource type with `--type`."); } $spec = $args->getArg('spec'); if ($spec) { $options = new PhutilSimpleOptions(); $spec = $options->parse($spec); } $allocator = new DrydockAllocator(); $allocator->setResourceType($resource_type); if ($spec) { // TODO: Shove this in there. } $lease = $allocator->allocate(); $root = dirname(phutil_get_library_root('phabricator')); $wait = new ExecFuture( 'php -f %s wait-for-lease --id %s', $root.'/scripts/drydock/drydock_control.php', $lease->getID()); foreach (Futures(array($wait))->setUpdateInterval(1) as $key => $future) { if ($future) { $future->resolvex(); break; } // TODO: Pull logs. $console->writeErr("Working...\n"); } $console->writeOut("Acquired Lease %s\n", $lease->getID()); return 0; } }