Differential D14148 Diff 34188 src/applications/drydock/management/DrydockManagementLeaseWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/management/DrydockManagementLeaseWorkflow.php
Show All 9 Lines | $this | ||||
->setArguments( | ->setArguments( | ||||
array( | array( | ||||
array( | array( | ||||
'name' => 'type', | 'name' => 'type', | ||||
'param' => 'resource_type', | 'param' => 'resource_type', | ||||
'help' => pht('Resource type.'), | 'help' => pht('Resource type.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'until', | |||||
'param' => 'time', | |||||
'help' => pht('Set lease expiration time.'), | |||||
chad: align? | |||||
), | |||||
array( | |||||
'name' => 'attributes', | 'name' => 'attributes', | ||||
'param' => 'name=value,...', | 'param' => 'name=value,...', | ||||
'help' => pht('Resource specficiation.'), | 'help' => pht('Resource specficiation.'), | ||||
), | ), | ||||
)); | )); | ||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
$resource_type = $args->getArg('type'); | $resource_type = $args->getArg('type'); | ||||
if (!$resource_type) { | if (!$resource_type) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht( | pht( | ||||
'Specify a resource type with `%s`.', | 'Specify a resource type with `%s`.', | ||||
'--type')); | '--type')); | ||||
} | } | ||||
$until = $args->getArg('until'); | |||||
if (strlen($until)) { | |||||
$until = strtotime($until); | |||||
if ($until <= 0) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Unable to parse argument to "%s".', | |||||
'--until')); | |||||
} | |||||
} | |||||
$attributes = $args->getArg('attributes'); | $attributes = $args->getArg('attributes'); | ||||
if ($attributes) { | if ($attributes) { | ||||
$options = new PhutilSimpleOptions(); | $options = new PhutilSimpleOptions(); | ||||
$options->setCaseSensitive(true); | $options->setCaseSensitive(true); | ||||
$attributes = $options->parse($attributes); | $attributes = $options->parse($attributes); | ||||
} | } | ||||
$lease = id(new DrydockLease()) | $lease = id(new DrydockLease()) | ||||
->setResourceType($resource_type); | ->setResourceType($resource_type); | ||||
if ($attributes) { | if ($attributes) { | ||||
$lease->setAttributes($attributes); | $lease->setAttributes($attributes); | ||||
} | } | ||||
if ($until) { | |||||
$lease->setUntil($until); | |||||
} | |||||
$lease->queueForActivation(); | $lease->queueForActivation(); | ||||
echo tsprintf( | echo tsprintf( | ||||
"%s\n", | "%s\n", | ||||
pht('Waiting for daemons to activate lease...')); | pht('Waiting for daemons to activate lease...')); | ||||
$lease->waitUntilActive(); | $lease->waitUntilActive(); | ||||
echo tsprintf( | echo tsprintf( | ||||
"%s\n", | "%s\n", | ||||
pht('Activated lease "%s".', $lease->getID())); | pht('Activated lease "%s".', $lease->getID())); | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } |
align?