示例#1
0
文件: Ec2.php 项目: ruflin/zf2
    /**
     * Return a list of all the available instance images
     *
     * @return ImageList
     */ 
    public function imagesInstance()
    {
        if (!isset($this->ec2Image)) {
            $this->ec2Image = new Ec2Image($this->accessKey, $this->accessSecret, $this->region);
        }

        $this->adapterResult = $this->ec2Image->describe();
                
        $images = array();

        foreach ($this->adapterResult as $result) {
            switch (strtolower($result['platform'])) {
                case 'windows' :
                    $platform = Image::IMAGE_WINDOWS;
                    break;
                default:
                    $platform = Image::IMAGE_LINUX;
                    break;
            }

            $images[]= array (
                Image::IMAGE_ID           => $result['imageId'],
                Image::IMAGE_NAME         => '',
                Image::IMAGE_DESCRIPTION  => $result['imageLocation'],
                Image::IMAGE_OWNERID      => $result['imageOwnerId'],
                Image::IMAGE_ARCHITECTURE => $result['architecture'],
                Image::IMAGE_PLATFORM     => $platform,
            );
        }
        return new ImageList($images,$this->ec2Image);
    }
示例#2
0
 /**
  * Prepares the environment before running a test.
  */
 protected function setUp()
 {
     $this->ec2ImageInstance = new Ec2\Image('access_key', 'secret_access_key');
     $adapter = new \Zend\Http\Client\Adapter\Test();
     $client = new \Zend\Http\Client(null, array('adapter' => $adapter));
     $this->adapter = $adapter;
     Ec2\Image::setDefaultHTTPClient($client);
 }
示例#3
0
 /**
  * Prepares the environment before running a test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->Zend_Service_Amazon_Ec2_Image = new Ec2\Image('access_key', 'secret_access_key');
     $adapter = new \Zend\HTTP\Client\Adapter\Test();
     $client = new \Zend\HTTP\Client(null, array('adapter' => $adapter));
     $this->adapter = $adapter;
     Ec2\Image::setDefaultHTTPClient($client);
 }
示例#4
0
文件: Ec2.php 项目: necrogami/zf2
    /**
     * Return a list of all the available instance images
     *
     * @return boolean|ImageList
     */ 
    public function imagesInstance()
    {
        if (!isset($this->ec2Image)) {
            $this->ec2Image = new Ec2Image($this->accessKey, $this->accessSecret, $this->region);
            $this->ec2Image->setHttpClient($this->ec2->getHttpClient());
        }
        
        $this->resetError();
        try {
            $this->adapterResult = $this->ec2Image->describe();
        } catch (Ec2Exception\RunTimeException $e) {
            $this->setError($e);
            return false;
        }
        
        $images = array();
        $i = 0;
        foreach ($this->adapterResult as $result) {
            switch (strtolower($result['platform'])) {
                case 'windows' :
                    $platform = Image::IMAGE_WINDOWS;
                    break;
                default:
                    $platform = Image::IMAGE_LINUX;
                    break;
            }

            $images[$i] = array (
                Image::IMAGE_ID           => $result['imageId'],
                Image::IMAGE_NAME         => '',
                Image::IMAGE_DESCRIPTION  => $result['imageLocation'],
                Image::IMAGE_OWNERID      => $result['imageOwnerId'],
                Image::IMAGE_ARCHITECTURE => $result['architecture'],
                Image::IMAGE_PLATFORM     => $platform,
            );
            unset($result['imageId']);
            unset($result['imageLocation']);
            unset($result['imageOwnerId']);
            unset($result['architecture']);
            unset($result['platform']);
            $images[$i] = array_merge($result, $images[$i]);
            $i++;
        }
        if (empty($images)) {
            return null;
        }
        return new ImageList($images,$this->ec2Image);
    }