| @@ 587-611 (lines=25) @@ | ||
| 584 | * @param string $destFilename |
|
| 585 | * @return \DataSift\Storyplayer\CommandLib\CommandResult |
|
| 586 | */ |
|
| 587 | public function downloadFile($sourceFilename, $destFilename) |
|
| 588 | { |
|
| 589 | // what are we doing? |
|
| 590 | $log = usingLog()->startAction("download file '{$this->args[0]}':'{$sourceFilename}' to '{$destFilename}'"); |
|
| 591 | ||
| 592 | // make sure we have valid host details |
|
| 593 | $hostDetails = $this->getHostDetails(); |
|
| 594 | ||
| 595 | // get an object to talk to this host |
|
| 596 | $host = OsLib::getHostAdapter($this->st, $hostDetails->osName); |
|
| 597 | ||
| 598 | // upload the file |
|
| 599 | $result = $host->downloadFile($hostDetails, $sourceFilename, $destFilename); |
|
| 600 | ||
| 601 | // did the command used to upload succeed? |
|
| 602 | if ($result->didCommandFail()) { |
|
| 603 | $msg = "download failed with return code '{$result->returnCode}' and output '{$result->output}'"; |
|
| 604 | $log->endAction($msg); |
|
| 605 | throw Exceptions::newActionFailedException(__METHOD__, $msg); |
|
| 606 | } |
|
| 607 | ||
| 608 | // all done |
|
| 609 | $log->endAction(); |
|
| 610 | return $result; |
|
| 611 | } |
|
| 612 | ||
| 613 | /** |
|
| 614 | * @param string $filename |
|
| @@ 63-87 (lines=25) @@ | ||
| 60 | */ |
|
| 61 | class UsingHost extends HostBase |
|
| 62 | { |
|
| 63 | public function runCommand($command) |
|
| 64 | { |
|
| 65 | // what are we doing? |
|
| 66 | $log = usingLog()->startAction("run command '{$command}' on host '{$this->args[0]}'"); |
|
| 67 | ||
| 68 | // make sure we have valid host details |
|
| 69 | $hostDetails = $this->getHostDetails(); |
|
| 70 | ||
| 71 | // get an object to talk to this host |
|
| 72 | $host = OsLib::getHostAdapter($this->st, $hostDetails->osName); |
|
| 73 | ||
| 74 | // run the command in the guest operating system |
|
| 75 | $result = $host->runCommand($hostDetails, $command); |
|
| 76 | ||
| 77 | // did the command succeed? |
|
| 78 | if ($result->didCommandFail()) { |
|
| 79 | $msg = "command failed with return code '{$result->returnCode}' and output '{$result->output}'"; |
|
| 80 | $log->endAction($msg); |
|
| 81 | throw Exceptions::newActionFailedException(__METHOD__, $msg); |
|
| 82 | } |
|
| 83 | ||
| 84 | // all done |
|
| 85 | $log->endAction(); |
|
| 86 | return $result; |
|
| 87 | } |
|
| 88 | ||
| 89 | public function runCommandAsUser($command, $user) |
|
| 90 | { |
|