Exemple #1
0
 /**
  * Convert the attributes of Rackspace server into attributes of Infrastructure
  * 
  * @param  array $attr
  * @return array|boolean 
  */
 protected function convertAttributes($attr)
 {
     $result = array();
     if (!empty($attr) && is_array($attr)) {
         $result[Instance::INSTANCE_ID] = $attr['id'];
         unset($attr['id']);
         $result[Instance::INSTANCE_NAME] = $attr['name'];
         unset($attr['name']);
         $result[Instance::INSTANCE_STATUS] = $this->mapStatus[$attr['status']];
         unset($attr['status']);
         $result[Instance::INSTANCE_IMAGEID] = $attr['imageId'];
         unset($attr['imageId']);
         if ($this->region == RackspaceServers::US_AUTH_URL) {
             $result[Instance::INSTANCE_ZONE] = self::RACKSPACE_ZONE_USA;
         } else {
             $result[Instance::INSTANCE_ZONE] = self::RACKSPACE_ZONE_UK;
         }
         if (empty($this->flavors)) {
             $this->flavors = $this->rackspace->listFlavors(true);
         }
         if (!empty($this->flavors)) {
             $result[Instance::INSTANCE_RAM] = $this->flavors[$attr['flavorId']]['ram'];
             $result[Instance::INSTANCE_STORAGE] = $this->flavors[$attr['flavorId']]['disk'];
         }
         unset($attr['flavorId']);
         $result[Instance::INSTANCE_PUBLICDNS] = $attr['addresses']['public'][0];
         $result = array_merge($attr, $result);
     }
     return $result;
 }
Exemple #2
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)) {
            throw new Exception\InvalidArgumentException('Invalid options provided');
        }
        
        if (!isset($options[self::RACKSPACE_USER])) {
            throw new Exception\InvalidArgumentException('Rackspace access user not specified!');
        }

        if (!isset($options[self::RACKSPACE_KEY])) {
            throw new Exception\InvalidArgumentException('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= RackspaceServers::UK_AUTH_URL;
                    break;
                case self::RACKSPACE_ZONE_USA:
                    $this->region = RackspaceServers::US_AUTH_URL;
                    break;
                default:
                    throw new Exception\InvalidArgumentException('The region is not valid');
            }
        } else {
            $this->region = RackspaceServers::US_AUTH_URL;
        }

        try {
            $this->rackspace = new RackspaceServers($this->accessUser,$this->accessKey, $this->region);
        } catch (\Zend\Service\Rackspace\Exception  $e) {
            throw new Exception\RuntimeException('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);
    }
Exemple #3
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']));
 }