1: <?php
2: /**
3: * PHP OpenCloud library.
4: *
5: * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
6: * @license https://www.apache.org/licenses/LICENSE-2.0
7: * @author Glen Campbell <glen.campbell@rackspace.com>
8: * @author Jamie Hannaford <jamie.hannaford@rackspace.com>
9: */
10:
11: namespace OpenCloud;
12:
13: use OpenCloud\Common\Service\ServiceBuilder;
14:
15: /**
16: * Rackspace extends the OpenStack class with support for Rackspace's
17: * API key and tenant requirements.
18: *
19: * The only difference between Rackspace and OpenStack is that the
20: * Rackspace class generates credentials using the username
21: * and API key, as required by the Rackspace authentication
22: * service.
23: *
24: * Example:
25: * <pre><code>
26: * $client = new Rackspace(
27: * 'https://identity.api.rackspacecloud.com/v2.0/',
28: * array(
29: * 'username' => 'FRED',
30: * 'apiKey' => '0900af093093788912388fc09dde090ffee09'
31: * )
32: * );
33: * </code></pre>
34: */
35: class Rackspace extends OpenStack
36: {
37: const US_IDENTITY_ENDPOINT = 'https://identity.api.rackspacecloud.com/v2.0/';
38: const UK_IDENTITY_ENDPOINT = 'https://lon.identity.api.rackspacecloud.com/v2.0/';
39:
40: /**
41: * Generates Rackspace API key credentials
42: * {@inheritDoc}
43: */
44: public function getCredentials()
45: {
46: $secret = $this->getSecret();
47:
48: if (!empty($secret['username']) && !empty($secret['apiKey'])) {
49:
50: $credentials = array('auth' => array(
51: 'RAX-KSKEY:apiKeyCredentials' => array(
52: 'username' => $secret['username'],
53: 'apiKey' => $secret['apiKey']
54: )
55: ));
56:
57: if (!empty($secret['tenantName'])) {
58: $credentials['auth']['tenantName'] = $secret['tenantName'];
59: } elseif (!empty($secret['tenantId'])) {
60: $credentials['auth']['tenantId'] = $secret['tenantId'];
61: }
62:
63: return json_encode($credentials);
64:
65: } else {
66: throw new Exceptions\CredentialError(
67: Lang::translate('Unrecognized credential secret')
68: );
69: }
70: }
71:
72: /**
73: * Creates a new Database service. Note: this is a Rackspace-only feature.
74: *
75: * @param string $name The name of the service as it appears in the Catalog
76: * @param string $region The region (DFW, IAD, ORD, LON, SYD)
77: * @param string $urltype The URL type ("publicURL" or "internalURL")
78: * @return \OpenCloud\Database\Service
79: */
80: public function databaseService($name = null, $region = null, $urltype = null)
81: {
82: return ServiceBuilder::factory($this, 'OpenCloud\Database\Service', array(
83: 'name' => $name,
84: 'region' => $region,
85: 'urlType' => $urltype
86: ));
87: }
88:
89: /**
90: * Creates a new Load Balancer service. Note: this is a Rackspace-only feature.
91: *
92: * @param string $name The name of the service as it appears in the Catalog
93: * @param string $region The region (DFW, IAD, ORD, LON, SYD)
94: * @param string $urltype The URL type ("publicURL" or "internalURL")
95: * @return \OpenCloud\LoadBalancer\Service
96: */
97: public function loadBalancerService($name = null, $region = null, $urltype = null)
98: {
99: return ServiceBuilder::factory($this, 'OpenCloud\LoadBalancer\Service', array(
100: 'name' => $name,
101: 'region' => $region,
102: 'urlType' => $urltype
103: ));
104: }
105:
106: /**
107: * Creates a new DNS service. Note: this is a Rackspace-only feature.
108: *
109: * @param string $name The name of the service as it appears in the Catalog
110: * @param string $region The region (DFW, IAD, ORD, LON, SYD)
111: * @param string $urltype The URL type ("publicURL" or "internalURL")
112: * @return OpenCloud\DNS\Service
113: */
114: public function dnsService($name = null, $region = null, $urltype = null)
115: {
116: return ServiceBuilder::factory($this, 'OpenCloud\DNS\Service', array(
117: 'name' => $name,
118: 'region' => $region,
119: 'urlType' => $urltype
120: ));
121: }
122:
123: /**
124: * Creates a new CloudMonitoring service. Note: this is a Rackspace-only feature.
125: *
126: * @param string $name The name of the service as it appears in the Catalog
127: * @param string $region The region (DFW, IAD, ORD, LON, SYD)
128: * @param string $urltype The URL type ("publicURL" or "internalURL")
129: * @return \OpenCloud\CloudMonitoring\Service
130: */
131: public function cloudMonitoringService($name = null, $region = null, $urltype = null)
132: {
133: return ServiceBuilder::factory($this, 'OpenCloud\CloudMonitoring\Service', array(
134: 'name' => $name,
135: 'region' => $region,
136: 'urlType' => $urltype
137: ));
138: }
139:
140: /**
141: * Creates a new CloudQueues service. Note: this is a Rackspace-only feature.
142: *
143: * @param string $name The name of the service as it appears in the Catalog
144: * @param string $region The region (DFW, IAD, ORD, LON, SYD)
145: * @param string $urltype The URL type ("publicURL" or "internalURL")
146: * @return \OpenCloud\Autoscale\Service
147: */
148: public function autoscaleService($name = null, $region = null, $urltype = null)
149: {
150: return ServiceBuilder::factory($this, 'OpenCloud\Autoscale\Service', array(
151: 'name' => $name,
152: 'region' => $region,
153: 'urlType' => $urltype
154: ));
155: }
156:
157: /**
158: * Creates a new CloudQueues service. Note: this is a Rackspace-only feature.
159: *
160: * @param string $name The name of the service as it appears in the Catalog
161: * @param string $region The region (DFW, IAD, ORD, LON, SYD)
162: * @param string $urltype The URL type ("publicURL" or "internalURL")
163: * @return \OpenCloud\Queues\Service
164: */
165: public function queuesService($name = null, $region = null, $urltype = null)
166: {
167: return ServiceBuilder::factory($this, 'OpenCloud\Queues\Service', array(
168: 'name' => $name,
169: 'region' => $region,
170: 'urlType' => $urltype
171: ));
172: }
173:
174: }
175: