AwsInspector\Model\Ec2\Repository::findEc2Instance PHP Method

findEc2Instance() public method

public findEc2Instance ( $value ) : false | Instance
$value
return false | Instance
    public function findEc2Instance($value)
    {
        foreach (['instance-id', 'ip-address', 'private-ip-address'] as $field) {
            $instance = $this->findEc2InstanceBy($field, $value);
            if ($instance !== false) {
                return $instance;
            }
        }
        return false;
    }

Usage Example

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;
 }
All Usage Examples Of AwsInspector\Model\Ec2\Repository::findEc2Instance