Ejemplo n.º 1
0
    /**
     * Constructor
     *
     * @param  array|Zend_Config $options
     * @return void
     */
    public function __construct($options = array())
    {
        if (is_object($options)) {
            if (method_exists($options, 'toArray')) {
                $options= $options->toArray();
            } elseif ($options instanceof Traversable) {
                $options = iterator_to_array($options);
            }
        }
        
        if (empty($options) || !is_array($options)) {
            require_once 'Zend/Cloud/Infrastructure/Exception.php';
            throw new Zend_Cloud_Infrastructure_Exception('Invalid options provided');
        }
        
        if (!isset($options[self::RACKSPACE_USER])) {
            require_once 'Zend/Cloud/Infrastructure/Exception.php';
            throw new Zend_Cloud_Infrastructure_Exception('Rackspace access user not specified!');
        }

        if (!isset($options[self::RACKSPACE_KEY])) {
            require_once 'Zend/Cloud/Infrastructure/Exception.php';
            throw new Zend_Cloud_Infrastructure_Exception('Rackspace access key not specified!');
        }
        
        $this->accessUser = $options[self::RACKSPACE_USER];
        $this->accessKey  = $options[self::RACKSPACE_KEY];
        
        if (isset($options[self::RACKSPACE_REGION])) {
            switch ($options[self::RACKSPACE_REGION]) {
                case self::RACKSPACE_ZONE_UK:
                    $this->region= Zend_Service_Rackspace_Servers::UK_AUTH_URL;
                    break;
                case self::RACKSPACE_ZONE_USA:
                    $this->region = Zend_Service_Rackspace_Servers::US_AUTH_URL;
                    break;
                default:
                    require_once 'Zend/Cloud/Infrastructure/Exception.php';
                    throw new Zend_Cloud_Infrastructure_Exception('The region is not valid');
            }
        } else {
            $this->region = Zend_Service_Rackspace_Servers::US_AUTH_URL;
        }

        try {
            $this->rackspace = new Zend_Service_Rackspace_Servers($this->accessUser,$this->accessKey, $this->region);
        } catch (Exception  $e) {
            require_once 'Zend/Cloud/Infrastructure/Exception.php';
            throw new Zend_Cloud_Infrastructure_Exception('Error on create: ' . $e->getMessage(), $e->getCode(), $e);
        }

        if (isset($options[self::HTTP_ADAPTER])) {
            $this->rackspace->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
        }
        
        $this->flavors= $this->rackspace->listFlavors(true);
    }
Ejemplo n.º 2
0
 /**
  * Test list flavors
  */
 public function testListFlavors()
 {
     self::$flavors = $this->rackspace->listFlavors(true);
     $this->assertTrue(is_array(self::$flavors) && !empty(self::$flavors));
     $this->assertTrue(isset(self::$flavors[0]['id']));
 }