Overview
  • Namespace
  • Class

Namespaces

  • OpenCloud
    • Autoscale
      • 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
      • Exception
      • Resource
      • Upload
    • Orchestration
      • Resource
    • Queues
      • Collection
      • Exception
      • Resource
    • Volume
      • Resource

Classes

  • OpenCloud\Volume\Resource\Snapshot
  • OpenCloud\Volume\Resource\Volume
  • OpenCloud\Volume\Resource\VolumeType
  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\DNS;
 19 
 20 use OpenCloud\Common\Http\Message\Formatter;
 21 use OpenCloud\Common\Service\CatalogService;
 22 use OpenCloud\DNS\Collection\DnsIterator;
 23 use OpenCloud\DNS\Resource\AsyncResponse;
 24 use OpenCloud\DNS\Resource\Domain;
 25 use OpenCloud\DNS\Resource\HasPtrRecordsInterface;
 26 
 27 /**
 28  * DNS Service.
 29  */
 30 class Service extends CatalogService
 31 {
 32     const DEFAULT_TYPE = 'rax:dns';
 33     const DEFAULT_NAME = 'cloudDNS';
 34 
 35     protected $regionless = true;
 36 
 37     public function collection($class, $url = null, $parent = null, $data = null)
 38     {
 39         $options = $this->makeResourceIteratorOptions($this->resolveResourceClass($class));
 40         $options['baseUrl'] = $url;
 41 
 42         $parent = $parent ? : $this;
 43 
 44         return DnsIterator::factory($parent, $options, $data);
 45     }
 46 
 47     /**
 48      * Returns a domain
 49      *
 50      * @param mixed $info either the ID, an object, or array of parameters
 51      * @return Resource\Domain
 52      */
 53     public function domain($info = null)
 54     {
 55         return $this->resource('Domain', $info);
 56     }
 57 
 58     /**
 59      * Returns a collection of domains
 60      *
 61      * @param array $filter key/value pairs to use as query strings
 62      * @return \OpenCloud\Common\Collection
 63      */
 64     public function domainList($filter = array())
 65     {
 66         $url = $this->getUrl(Domain::resourceName());
 67         $url->setQuery($filter);
 68 
 69         return $this->resourceList('Domain', $url);
 70     }
 71 
 72     /**
 73      * returns a PtrRecord object for a server
 74      *
 75      * @param mixed $info ID, array, or object containing record data
 76      * @return Resource\Record
 77      */
 78     public function ptrRecord($info = null)
 79     {
 80         return $this->resource('PtrRecord', $info);
 81     }
 82 
 83     /**
 84      * returns a Collection of PTR records for a given Server
 85      *
 86      * @param \OpenCloud\Compute\Resource\Server $server the server for which to
 87      *                                                   retrieve the PTR records
 88      * @return \OpenCloud\Common\Collection
 89      */
 90     public function ptrRecordList(HasPtrRecordsInterface $parent)
 91     {
 92         $url = $this->getUrl()
 93             ->addPath('rdns')
 94             ->addPath($parent->getService()->getName())
 95             ->setQuery(array('href' => (string) $parent->getUrl()));
 96 
 97         return $this->resourceList('PtrRecord', $url);
 98     }
 99 
100     /**
101      * retrieves an asynchronous response
102      *
103      * This method calls the provided `$url` and expects an asynchronous
104      * response. It checks for various HTTP error codes and returns
105      * an `AsyncResponse` object. This object can then be used to poll
106      * for the status or to retrieve the final data as needed.
107      *
108      * @param string $url     the URL of the request
109      * @param string $method  the HTTP method to use
110      * @param array  $headers key/value pairs for headers to include
111      * @param string $body    the body of the request (for PUT and POST)
112      * @return Resource\AsyncResponse
113      */
114     public function asyncRequest($url, $method = 'GET', $headers = array(), $body = null)
115     {
116         $response = $this->getClient()->createRequest($method, $url, $headers, $body)->send();
117 
118         return new AsyncResponse($this, Formatter::decode($response));
119     }
120 
121     /**
122      * Imports domain records
123      *
124      * Note that this function is called from the service (DNS) level, and
125      * not (as you might suspect) from the Domain object. Because the function
126      * return an AsyncResponse, the domain object will not actually exist
127      * until some point after the import has occurred.
128      *
129      * @param string $data the BIND_9 formatted data to import
130      * @return Resource\AsyncResponse
131      */
132     public function import($data)
133     {
134         $url = clone $this->getUrl();
135         $url->addPath('domains');
136         $url->addPath('import');
137 
138         $object = (object) array(
139             'domains' => array(
140                 (object) array(
141                     'contents'    => $data,
142                     'contentType' => 'BIND_9'
143                 )
144             )
145         );
146 
147         // encode it
148         $json = json_encode($object);
149 
150         // perform the request
151         return $this->asyncRequest($url, 'POST', self::getJsonHeader(), $json);
152     }
153 
154     /**
155      * returns a list of limits
156      */
157     public function limits($type = null)
158     {
159         $url = $this->getUrl('limits');
160 
161         if ($type) {
162             $url->addPath($type);
163         }
164 
165         $response = $this->getClient()->get($url)->send();
166         $body = Formatter::decode($response);
167 
168         return isset($body->limits) ? $body->limits : $body;
169     }
170 
171     /**
172      * returns an array of limit types
173      *
174      * @return array
175      */
176     public function limitTypes()
177     {
178         $response = $this->getClient()->get($this->getUrl('limits/types'))->send();
179         $body = Formatter::decode($response);
180 
181         return $body->limitTypes;
182     }
183 
184     public function listAsyncJobs(array $query = array())
185     {
186         $url = clone $this->getUrl();
187         $url->addPath('status');
188         $url->setQuery($query);
189 
190         return DnsIterator::factory($this, array(
191             'baseUrl'        => $url,
192             'resourceClass'  => 'AsyncResponse',
193             'key.collection' => 'asyncResponses'
194         ));
195     }
196 
197     public function getAsyncJob($jobId, $showDetails = true)
198     {
199         $url = clone $this->getUrl();
200         $url->addPath('status');
201         $url->addPath((string) $jobId);
202         $url->setQuery(array('showDetails' => ($showDetails) ? 'true' : 'false'));
203 
204         $response = $this->getClient()->get($url)->send();
205 
206         return new AsyncResponse($this, Formatter::decode($response));
207     }
208 }
209 
API documentation generated by ApiGen