      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\Volume;
     19:
     20: use OpenCloud\Common\Service\NovaService;
     21: use OpenCloud\Volume\Resource\Snapshot;
     22:
     23: class Service extends NovaService
     24: {
     25:     const DEFAULT_TYPE = 'volume';
     26:     const DEFAULT_NAME = 'cloudBlockStorage';
     27:
     28:     /**
     29:      * Returns a Volume object
     30:      *
     31:      * @param string $id the Volume ID
     32:      * @return Resource\Volume
     33:      */
     34:     public function volume($id = null)
     35:     {
     36:         return $this->resource('Volume', $id);
     37:     }
     38:
     39:     /**
     40:      * Returns a Collection of Volume objects
     41:      *
     42:      * @param boolean $details if TRUE, return all details
     43:      * @param array   $filter  array of filter key/value pairs
     44:      * @return \OpenCloud\Common\Collection
     45:      */
     46:     public function volumeList($details = true, $filter = array())
     47:     {
     48:         $url = clone $this->getUrl(Resource\Volume::ResourceName());
     49:
     50:         if ($details === true) {
     51:             $url->addPath('detail');
     52:         }
     53:
     54:         $url->setQuery($filter);
     55:
     56:         return $this->resourceList('Volume', $url);
     57:     }
     58:
     59:     /**
     60:      * Returns a VolumeType object
     61:      *
     62:      * @param string $id the VolumeType ID
     63:      * @return Resource\Volume
     64:      */
     65:     public function volumeType($id = null)
     66:     {
     67:         return $this->resource('VolumeType', $id);
     68:     }
     69:
     70:     /**
     71:      * Returns a Collection of VolumeType objects
     72:      *
     73:      * @param array $filter array of filter key/value pairs
     74:      * @return \OpenCloud\Common\Collection
     75:      */
     76:     public function volumeTypeList($filter = array())
     77:     {
     78:         return $this->resourceList('VolumeType');
     79:     }
     80:
     81:     /**
     82:      * Returns a Snapshot object associated with this volume
     83:      *
     84:      * @param null $id
     85:      * @return Resource\Snapshot
     86:      */
     87:     public function snapshot($id = null)
     88:     {
     89:         return $this->resource('Snapshot', $id);
     90:     }
     91:
     92:     /**
     93:      * Returns a Collection of Snapshot objects
     94:      *
     95:      * @param array $filter array of filter key/value pairs
     96:      * @return \OpenCloud\Common\Collection
     97:      */
     98:     public function snapshotList($filter = array())
     99:     {
    100:         $url = clone $this->getUrl();
    101:         $url->addPath(Snapshot::resourceName())->setQuery($filter);
    102:
    103:         return $this->resourceList('Snapshot', $url);
    104:     }
    105: }
    106: