Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CDN
      • Resource
    • CloudMonitoring
      • Collection
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Log
      • Resource
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Collection
      • Resource
    • Identity
      • Constants
      • Resource
    • Image
      • Enum
      • Resource
        • JsonPatch
        • Schema
    • LoadBalancer
      • Collection
      • Enum
      • Resource
    • Networking
      • Resource
    • ObjectStore
      • Constants
      • Enum
      • Exception
      • Resource
      • Upload
    • Orchestration
      • Resource
    • Queues
      • Collection
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • OpenStack
  • Rackspace
  • Version
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2012-2014 Rackspace US, Inc.
  4:  *
  5:  * Licensed under the Apache License, Version 2.0 (the "License");
  6:  * you may not use this file except in compliance with the License.
  7:  * You may obtain a copy of the License at
  8:  *
  9:  * http://www.apache.org/licenses/LICENSE-2.0
 10:  *
 11:  * Unless required by applicable law or agreed to in writing, software
 12:  * distributed under the License is distributed on an "AS IS" BASIS,
 13:  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14:  * See the License for the specific language governing permissions and
 15:  * limitations under the License.
 16:  */
 17: 
 18: namespace OpenCloud;
 19: 
 20: use OpenCloud\Common\Exceptions\CredentialError;
 21: use OpenCloud\Common\Service\ServiceBuilder;
 22: 
 23: /**
 24:  * Rackspace extends the OpenStack class with support for Rackspace's
 25:  * API key and tenant requirements.
 26:  *
 27:  * The only difference between Rackspace and OpenStack is that the
 28:  * Rackspace class generates credentials using the username
 29:  * and API key, as required by the Rackspace authentication
 30:  * service.
 31:  *
 32:  * Example:
 33:  * <pre><code>
 34:  * $client = new Rackspace(
 35:  *      'https://identity.api.rackspacecloud.com/v2.0/',
 36:  *      array(
 37:  *          'username' => 'FRED',
 38:  *          'apiKey'   => '0900af093093788912388fc09dde090ffee09'
 39:  *      )
 40:  * );
 41:  * </code></pre>
 42:  */
 43: class Rackspace extends OpenStack
 44: {
 45:     const US_IDENTITY_ENDPOINT = 'https://identity.api.rackspacecloud.com/v2.0/';
 46:     const UK_IDENTITY_ENDPOINT = 'https://lon.identity.api.rackspacecloud.com/v2.0/';
 47: 
 48:     /**
 49:      * Generates Rackspace API key credentials
 50:      * {@inheritDoc}
 51:      */
 52:     public function getCredentials()
 53:     {
 54:         $secret = $this->getSecret();
 55: 
 56:         if (!empty($secret['username']) && !empty($secret['apiKey'])) {
 57:             $credentials = array('auth' => array(
 58:                 'RAX-KSKEY:apiKeyCredentials' => array(
 59:                     'username' => $secret['username'],
 60:                     'apiKey'   => $secret['apiKey']
 61:                 )
 62:             ));
 63: 
 64:             if (!empty($secret['tenantName'])) {
 65:                 $credentials['auth']['tenantName'] = $secret['tenantName'];
 66:             } elseif (!empty($secret['tenantId'])) {
 67:                 $credentials['auth']['tenantId'] = $secret['tenantId'];
 68:             }
 69: 
 70:             return json_encode($credentials);
 71:         } else {
 72:             throw new CredentialError('Unrecognized credential secret');
 73:         }
 74:     }
 75: 
 76:     /**
 77:      * Creates a new Database service. Note: this is a Rackspace-only feature.
 78:      *
 79:      * @param string $name    The name of the service as it appears in the Catalog
 80:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
 81:      * @param string $urltype The URL type ("publicURL" or "internalURL")
 82:      * @return \OpenCloud\Database\Service
 83:      */
 84:     public function databaseService($name = null, $region = null, $urltype = null)
 85:     {
 86:         return ServiceBuilder::factory($this, 'OpenCloud\Database\Service', array(
 87:             'name'    => $name,
 88:             'region'  => $region,
 89:             'urlType' => $urltype
 90:         ));
 91:     }
 92: 
 93:     /**
 94:      * Creates a new Load Balancer service. Note: this is a Rackspace-only feature.
 95:      *
 96:      * @param string $name    The name of the service as it appears in the Catalog
 97:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
 98:      * @param string $urltype The URL type ("publicURL" or "internalURL")
 99:      * @return \OpenCloud\LoadBalancer\Service
100:      */
101:     public function loadBalancerService($name = null, $region = null, $urltype = null)
102:     {
103:         return ServiceBuilder::factory($this, 'OpenCloud\LoadBalancer\Service', array(
104:             'name'    => $name,
105:             'region'  => $region,
106:             'urlType' => $urltype
107:         ));
108:     }
109: 
110:     /**
111:      * Creates a new DNS service. Note: this is a Rackspace-only feature.
112:      *
113:      * @param string $name    The name of the service as it appears in the Catalog
114:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
115:      * @param string $urltype The URL type ("publicURL" or "internalURL")
116:      * @return OpenCloud\DNS\Service
117:      */
118:     public function dnsService($name = null, $region = null, $urltype = null)
119:     {
120:         return ServiceBuilder::factory($this, 'OpenCloud\DNS\Service', array(
121:             'name'    => $name,
122:             'region'  => $region,
123:             'urlType' => $urltype
124:         ));
125:     }
126: 
127:     /**
128:      * Creates a new CloudMonitoring service. Note: this is a Rackspace-only feature.
129:      *
130:      * @param string $name    The name of the service as it appears in the Catalog
131:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
132:      * @param string $urltype The URL type ("publicURL" or "internalURL")
133:      * @return \OpenCloud\CloudMonitoring\Service
134:      */
135:     public function cloudMonitoringService($name = null, $region = null, $urltype = null)
136:     {
137:         return ServiceBuilder::factory($this, 'OpenCloud\CloudMonitoring\Service', array(
138:             'name'    => $name,
139:             'region'  => $region,
140:             'urlType' => $urltype
141:         ));
142:     }
143: 
144:     /**
145:      * Creates a new CloudQueues service. Note: this is a Rackspace-only feature.
146:      *
147:      * @param string $name    The name of the service as it appears in the Catalog
148:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
149:      * @param string $urltype The URL type ("publicURL" or "internalURL")
150:      * @return \OpenCloud\Autoscale\Service
151:      */
152:     public function autoscaleService($name = null, $region = null, $urltype = null)
153:     {
154:         return ServiceBuilder::factory($this, 'OpenCloud\Autoscale\Service', array(
155:             'name'    => $name,
156:             'region'  => $region,
157:             'urlType' => $urltype
158:         ));
159:     }
160: 
161:     /**
162:      * Creates a new CloudQueues service. Note: this is a Rackspace-only feature.
163:      *
164:      * @param string $name    The name of the service as it appears in the Catalog
165:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
166:      * @param string $urltype The URL type ("publicURL" or "internalURL")
167:      * @return \OpenCloud\Queues\Service
168:      */
169:     public function queuesService($name = null, $region = null, $urltype = null)
170:     {
171:         return ServiceBuilder::factory($this, 'OpenCloud\Queues\Service', array(
172:             'name'    => $name,
173:             'region'  => $region,
174:             'urlType' => $urltype
175:         ));
176:     }
177: 
178:     /**
179:      * Creates a new CDN (Rackspace CDN) service object
180:      *
181:      * @param string $name    The name of the service as it appears in the Catalog
182:      * @param string $region  The region (DFW, IAD, ORD, LON, SYD)
183:      * @param string $urltype The URL type ("publicURL" or "internalURL")
184:      * @return \OpenCloud\Cdn\Service
185:      * @codeCoverageIgnore
186:      */
187:     public function cdnService($name = null, $region = null, $urltype = null)
188:     {
189:         return ServiceBuilder::factory($this, 'OpenCloud\CDN\Service', array(
190:             'name'    => $name,
191:             'type'    => 'rax:cdn',
192:             'region'  => $region,
193:             'urlType' => $urltype
194:         ));
195:     }
196: }
197: 
API documentation generated by ApiGen 2.8.0