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

  • Snapshot
  • Volume
  • VolumeType
  • 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\Volume\Resource;
 19: 
 20: use OpenCloud\Common\Exceptions;
 21: use OpenCloud\Common\Lang;
 22: use OpenCloud\Common\Resource\PersistentResource;
 23: 
 24: /**
 25:  * The Volume class represents a single block storage volume
 26:  */
 27: class Volume extends PersistentResource
 28: {
 29:     public $id;
 30:     public $status;
 31:     public $display_name;
 32:     public $display_description;
 33:     public $size;
 34:     public $volume_type;
 35:     public $metadata = array();
 36:     public $availability_zone;
 37:     public $snapshot_id;
 38:     public $attachments = array();
 39:     public $created_at;
 40:     public $source_volid;
 41:     public $imageRef;
 42:     public $bootable;
 43: 
 44:     protected static $json_name = 'volume';
 45:     protected static $url_resource = 'volumes';
 46: 
 47:     protected $createKeys = array(
 48:         'snapshot_id',
 49:         'display_name',
 50:         'display_description',
 51:         'size',
 52:         'volume_type',
 53:         'availability_zone',
 54:         'metadata',
 55:         'source_volid',
 56:         'bootable',
 57:         'imageRef'
 58:     );
 59: 
 60:     protected $associatedResources = array();
 61: 
 62:     public function update($params = array())
 63:     {
 64:         throw new Exceptions\UpdateError(
 65:             Lang::translate('Block storage volumes cannot be updated')
 66:         );
 67:     }
 68: 
 69:     /**
 70:      * Rename either the `display_description` or the `display_name` properties
 71:      *
 72:      * @param array $params
 73:      * @return \Guzzle\Http\Message\Response
 74:      * @throws \InvalidArgumentException
 75:      */
 76:     public function rename(array $params = array())
 77:     {
 78:         $data = array();
 79: 
 80:         $keys = array('display_description', 'display_name');
 81: 
 82:         foreach ($params as $key => $value) {
 83:             if (in_array($key, $keys)) {
 84:                 $data[$key] = $value;
 85:             } else {
 86:                 throw new \InvalidArgumentException(sprintf(
 87:                     'You cannot update the %s volume property. Valid keys are: %s',
 88:                     $key, implode($keys, ',')
 89:                 ));
 90:             }
 91:         }
 92: 
 93:         $json = json_encode(array(
 94:            'volume' => $data
 95:         ));
 96: 
 97:         return $this->getClient()
 98:             ->put($this->getUrl(), self::getJsonHeader(), $json)
 99:             ->send();
100:     }
101: 
102:     public function name()
103:     {
104:         return $this->display_name;
105:     }
106: 
107:     protected function createJson()
108:     {
109:         $element = parent::createJson();
110: 
111:         if ($this->getProperty('volume_type') instanceof VolumeType) {
112:             $element->volume->volume_type = $this->volume_type->name();
113:         }
114: 
115:         return $element;
116:     }
117: }
118: 
API documentation generated by ApiGen 2.8.0