/**
  * Returns an array with Images to be presented in the grid
  *
  * @param int  $apiPort     Network port to use in API call
  * @param bool $incDangling Flag to filter dangling images (not used)
  *
  * @return array $objects An array with Image objects
  *
  */
 public static function getImageList($apiPort, $incDangling)
 {
     $objects = array();
     $now = date("c");
     $url = "http://localhost:" . $apiPort . "/images/json?all=0";
     $response = OMVModuleDockerUtil::doApiCall($url);
     $data = array();
     foreach (json_decode($response) as $item) {
         $repoTags = explode(":", $item->RepoTags[0]);
         $repository = $repoTags[0];
         $tag = $repoTags[1];
         if (strcmp($repository, "<none>") === 0) {
             $repository = "none";
         }
         if (strcmp($tag, "<none>") === 0) {
             $tag = "none";
         }
         $created = OMVModuleDockerUtil::getWhen($now, date("c", $item->Created)) . " ago";
         $tmp = array("repository" => $repository, "tag" => $tag, "id" => substr($item->Id, 7, 12), "created" => $created, "size" => OMVModuleDockerUtil::bytesToSize($item->VirtualSize));
         array_push($objects, $tmp);
     }
     return $objects;
 }
예제 #2
0
 /**
  * Constructor. The image will be updated with all associated properties from commandline.
  *
  * @param string $id Id of the new container
  * @return void
  * @access public
  */
 public function __construct($id, $data, $apiPort)
 {
     $now = date("c");
     $curl = curl_init();
     curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 30, CURLOPT_CONNECTTIMEOUT => 5));
     $this->id = $id;
     $item = $data[substr($id, 0, 12)];
     if (is_array($item->RepoTags) && count($item->RepoTags) > 0) {
         $this->repository = preg_split('/\\:/', $item->RepoTags[0])[0];
         $this->tag = preg_split('/\\:/', $item->RepoTags[0])[1];
     } else {
         $this->repository = "none";
         $this->tag = "none";
     }
     $this->created = OMVModuleDockerUtil::getWhen($now, date("c", $item->Created)) . " ago";
     $this->size = OMVModuleDockerUtil::bytesToSize($item->VirtualSize);
     $url = "http://localhost:" . $apiPort . "/images/{$id}/json";
     curl_setopt($curl, CURLOPT_URL, $url);
     if (!($response = curl_exec($curl))) {
         throw new OMVModuleDockerException('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
     }
     $imageData = json_decode($response);
     $this->ports = array();
     foreach ($imageData->Config->ExposedPorts as $exposedport => $hostports) {
         array_push($this->ports, array("name" => $exposedport));
     }
     $this->envVars = array();
     if (is_array($imageData->Config->Env)) {
         foreach ($imageData->Config->Env as $eVar) {
             $eVarAry = explode("=", $eVar);
             $this->envVars[$eVarAry[0]] = $eVarAry[1];
         }
     }
     curl_close($curl);
 }
 /**
  * Constructor. The image will be updated with all associated properties
  * from commandline.
  *
  * @param string $id      Id of the new container
  * @param array  $data    Associative array with Image data
  * @param int    $apiPort Network port used by API calls
  */
 public function __construct($id, $data, $apiPort)
 {
     $now = date("c");
     $this->_id = $id;
     $item = $data[substr($id, 0, 12)];
     if (isset($item->RepoTags)) {
         $this->_repository = preg_split('/\\:/', $item->RepoTags[0])[0];
         $this->_tag = preg_split('/\\:/', $item->RepoTags[0])[1];
     } else {
         $this->_repository = "none";
         $this->_tag = "none";
     }
     $this->_created = OMVModuleDockerUtil::getWhen($now, date("c", $item->Created)) . " ago";
     $this->_size = OMVModuleDockerUtil::bytesToSize($item->VirtualSize);
     $url = "http://localhost:" . $apiPort . "/images/{$id}/json";
     $response = OMVModuleDockerUtil::doApiCall($url);
     $imageData = json_decode($response);
     $this->_timestamp = date("U", $item->Created);
     $this->_ports = array();
     if (isset($imageData->Config->ExposedPorts)) {
         foreach ($imageData->Config->ExposedPorts as $exposedport => $hostports) {
             array_push($this->_ports, array("name" => $exposedport));
         }
     }
     $this->_envVars = array();
     if (isset($imageData->Config->Env)) {
         foreach ($imageData->Config->Env as $eVar) {
             $eVarAry = explode("=", $eVar);
             $this->_envVars[$eVarAry[0]] = $eVarAry[1];
         }
     }
     $this->_volumes = array();
     if (isset($imageData->Config->Volumes)) {
         foreach ($imageData->Config->Volumes as $key => $val) {
             array_push($this->_volumes, array($key));
         }
     }
 }