/**
  * @return array
  */
 public function report(array $ids = [])
 {
     $droplets = $this->allDroplets();
     $ids = empty($ids) ? Droplet::ids() : $ids;
     $filtered = array_filter($droplets, function ($instance) use($ids) {
         return in_array($instance->id, $ids);
     });
     $result = [];
     foreach ($filtered as $droplet) {
         $temp = new \stdClass();
         $temp->id = $droplet->id;
         $temp->name = $droplet->name;
         $temp->status = $droplet->status;
         $temp->ip_address = isset($droplet->networks->v4[0]) ? $droplet->networks->v4[0]->ip_address : '';
         $temp->region = $droplet->region->name;
         $temp->price_hourly = $droplet->size->price_hourly;
         $result[] = $temp;
     }
     return $result;
     //         return array_map(function($droplet) {
     //            return [
     //                'id'           => $droplet->id,
     //                'name'         => $droplet->name,
     //                'status'       => $droplet->status,
     //                'ip_address'   => isset($droplet->networks->v4[0]) ? $droplet->networks->v4[0]->ip_address : '',
     //                'region'       => $droplet->region->name,
     //                'price_hourly' => $droplet->size->price_hourly
     //            ];
     //        }, $filtered);
 }
Ejemplo n.º 2
0
 /**
  * Executes the current command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return null|int
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->provider->down();
     Droplet::delete();
     $output->writeln('<info>The instances are now being terminated...</info>');
 }
Ejemplo n.º 3
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  *
  * @return float
  */
 private function getNumberOfRequests(InputInterface $input)
 {
     return ceil($input->getOption('requests') / Droplet::count());
 }
Ejemplo n.º 4
0
 /**
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 private function waitUntilDropletsAreActive(OutputInterface $output)
 {
     $ready = false;
     while (!$ready) {
         $output->write('.');
         sleep(2);
         $droplets = $this->provider->report();
         foreach ($droplets as $droplet) {
             if ($droplet->status === 'active') {
                 $ready = true;
                 Droplet::save($droplets);
             }
         }
     }
     $output->writeln('.');
 }