Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     Registry::set('output', $output);
     $instance = $input->getArgument('instance');
     $repository = new Repository();
     $instance = $repository->findEc2Instance($instance);
     if (!$instance instanceof Instance) {
         throw new \Exception('Could not find instance');
     }
     $output->writeln('[Found instance: ' . $instance->getDefaultUsername() . '@' . $instance->getConnectionIp() . ']');
     $connection = $instance->getSshConnection();
     if ($command = $input->getOption('command')) {
         $commandObj = new \AwsInspector\Ssh\Command($connection, $command);
         if ($input->getOption('print')) {
             $output->writeln($commandObj->__toString());
             return 0;
         }
         $res = $commandObj->exec();
         $output->writeln($res['output']);
         return $res['returnVar'];
     }
     if ($input->getOption('print')) {
         $output->writeln($connection->__toString());
         return 0;
     }
     $connection->connect();
     return 0;
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tags = $input->getOption('tag');
     $tags = $this->convertTags($tags);
     $mapping = ['InstanceId' => 'InstanceId', 'ImageId' => 'ImageId', 'State' => 'State.Name', 'SubnetId' => 'SubnetId', 'AZ' => 'Placement.AvailabilityZone', 'PublicIp' => 'PublicIpAddress', 'PrivateIp' => 'PrivateIpAddress', 'KeyName' => 'KeyName'];
     // dynamically add current tags
     foreach (array_keys($tags) as $tagName) {
         $mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]';
     }
     foreach ($input->getOption('column') as $tagName) {
         $mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]';
     }
     $repository = new Repository();
     $instanceCollection = $repository->findEc2InstancesByTags($tags);
     $rows = [];
     foreach ($instanceCollection as $instance) {
         /* @var $instance Instance */
         $rows[] = $instance->extractData($mapping);
     }
     if (count($rows)) {
         $table = new \Symfony\Component\Console\Helper\Table($output);
         $table->setHeaders(array_keys(end($rows)))->setRows($rows);
         $table->render();
     } else {
         $output->writeln('No matching instances found.');
     }
 }
Example #3
0
 /**
  * Get jump host (bastion server)
  *
  * Overwrite this method in your inheriting class and return
  * a \AwsInspector\Model\Ec2\Instance representing your bastion server
  *
  * @return null|Instance
  */
 public function getJumpHost()
 {
     if ($config = $this->getInspectorConfiguration('jumptags')) {
         $ec2Repository = new Repository();
         return $ec2Repository->findEc2InstancesByTags($config)->getFirst();
     }
     return null;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('force')) {
         throw new \Exception('Operation aborted (use --force)');
     }
     $instance = $input->getArgument('instance');
     $repository = new Repository();
     $instance = $repository->findEc2Instance($instance);
     if (!$instance instanceof Instance) {
         throw new \Exception('Could not find instance');
     }
     $instance->terminate();
     $output->writeln('Terminating instance: ' . $instance->getInstanceId());
     return 0;
 }
Example #5
0
 /**
  * Get jump host (bastion server)
  *
  * Overwrite this method in your inheriting class and return
  * a \AwsInspector\Model\Ec2\Instance representing your bastion server
  *
  * @return Instance|null
  * @throws \Exception
  */
 public function getJumpHost()
 {
     if ($config = $this->getInspectorConfiguration('jumptags')) {
         $ec2Repository = new Repository();
         $instances = $ec2Repository->findEc2InstancesByTags($config);
         if (count($instances) == 0) {
             throw new \Exception('Could not fund jump host for: ' . var_export($config, true));
         }
         return $instances->getFirst();
     }
     return null;
 }