Example #1
0
 public function testGet()
 {
     $ipExpected = trim(file_get_contents('http://checkip.amazonaws.com/'));
     $service = new PublicIpService();
     $ip = $service->get();
     $this->assertSame($ipExpected, $ip);
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->loadConfig($input->getOption('config'));
     $hosts = $input->getArgument('hosts');
     $refresh = $input->getOption('refresh');
     $ip = $input->getOption('ip');
     $all = $input->getOption('all');
     if ($refresh && $ip) {
         throw new \RuntimeException('--refresh can not be used in conjunction with --ip.');
     }
     if ($all) {
         if (count($hosts)) {
             throw new \RuntimeException('--all can not be used in conjunction with a list of hosts.');
         }
         $hosts = $config->getAllHosts();
     }
     if ($ip === 'public') {
         $output->write('Determine public IP ... ');
         $service = new PublicIpService();
         $ip = $service->get();
         $output->writeln('<info>OK</info>');
     }
     if (!$ip && !$refresh && $config->isIpRequired($hosts)) {
         throw new \RuntimeException('Unable to determine IP (use --ip).');
     }
     foreach ($hosts as $host) {
         if ($refresh) {
             $ip = $this->resolve($host . '.');
         }
         $output->write(sprintf('Update %s ... ', $host));
         $this->updateHost($config, $host, $ip);
         $output->writeln('<info>OK</info>');
     }
 }
Example #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $service = new PublicIpService();
     $output->writeln($service->get());
 }