Page MenuHomePhabricator

D10469.id25175.diff
No OneTemporary

D10469.id25175.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -619,6 +619,7 @@
'DrydockManagementCreateResourceWorkflow' => 'applications/drydock/management/DrydockManagementCreateResourceWorkflow.php',
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
'DrydockManagementReleaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseWorkflow.php',
+ 'DrydockManagementSSHWorkflow' => 'applications/drydock/management/DrydockManagementSSHWorkflow.php',
'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php',
'DrydockPreallocatedHostBlueprintImplementation' => 'applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php',
'DrydockQuery' => 'applications/drydock/query/DrydockQuery.php',
@@ -3384,6 +3385,7 @@
'DrydockManagementCreateResourceWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementReleaseWorkflow' => 'DrydockManagementWorkflow',
+ 'DrydockManagementSSHWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementWorkflow' => 'PhabricatorManagementWorkflow',
'DrydockPreallocatedHostBlueprintImplementation' => 'DrydockBlueprintImplementation',
'DrydockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/drydock/management/DrydockManagementSSHWorkflow.php b/src/applications/drydock/management/DrydockManagementSSHWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/management/DrydockManagementSSHWorkflow.php
@@ -0,0 +1,56 @@
+<?php
+
+final class DrydockManagementSSHWorkflow
+ extends DrydockManagementWorkflow {
+
+ public function didConstruct() {
+ $this
+ ->setName('ssh')
+ ->setSynopsis('Run a command on a remote host.')
+ ->setArguments(
+ array(
+ array(
+ 'name' => 'id',
+ 'param' => 'lease',
+ ),
+ array(
+ 'name' => 'command',
+ 'param' => 'command',
+ ),
+ ));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $console = PhutilConsole::getConsole();
+
+ $id = $args->getArg('id');
+ if (!$id) {
+ throw new PhutilArgumentUsageException(
+ 'Specify a lease ID to run the command on.');
+ }
+
+ $viewer = $this->getViewer();
+
+ $leases = id(new DrydockLeaseQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->execute();
+ $lease = idx($leases, $id);
+
+ if (!$lease) {
+ $console->writeErr("Lease %d does not exist!\n", $id);
+ } else if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
+ $console->writeErr("Lease %d is not 'active'!\n", $id);
+ } else {
+ $interface = $lease->getInterface('command');
+ $future = $interface->getExecFuture('%C', $args->getArg('command'));
+
+ list($err, $stdout, $stderr) = $future->resolve();
+ $console->writeOut("Result: %d\n\n", $err);
+ $console->writeOut("%s\n", $stdout);
+ $console->writeErr("%s\n", $stderr);
+ }
+
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 14, 4:29 PM (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7662036
Default Alt Text
D10469.id25175.diff (3 KB)

Event Timeline