Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

  • Service
  • Snapshot
  • Volume
  • VolumeType
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * Defines a block storage volume
  4:  *
  5:  * @copyright 2012-2013 Rackspace Hosting, Inc.
  6:  * See COPYING for licensing information
  7:  *
  8:  * @package phpOpenCloud
  9:  * @version 1.0
 10:  * @author Glen Campbell <glen.campbell@rackspace.com>
 11:  */
 12: 
 13: namespace OpenCloud\Volume;
 14: 
 15: use OpenCloud\Common\PersistentObject;
 16: use OpenCloud\Common\Lang;
 17: use OpenCloud\Common\Exceptions;
 18: 
 19: /**
 20:  * The Volume class represents a single block storage volume
 21:  *
 22:  * @api
 23:  * @author Glen Campbell <glen.campbell@rackspace.com>
 24:  */
 25: class Volume extends PersistentObject 
 26: {
 27: 
 28:     public $id;
 29:     public $status;
 30:     public $display_name;
 31:     public $display_description;
 32:     public $size;
 33:     public $volume_type;
 34:     public $metadata = array();
 35:     public $availability_zone;
 36:     public $snapshot_id;
 37:     public $attachments = array();
 38:     public $created_at;
 39:     
 40:     protected static $json_name = 'volume';
 41:     protected static $url_resource = 'volumes';
 42: 
 43:     private $_create_keys = array(
 44:         'snapshot_id',
 45:         'display_name',
 46:         'display_description',
 47:         'size',
 48:         'volume_type',
 49:         'availability_zone'
 50:     );
 51: 
 52:     /**
 53:      * Always throws an error; updates are not permitted
 54:      *
 55:      * @throws OpenCloud\UpdateError always
 56:      */
 57:     public function Update($params = array()) 
 58:     {
 59:         throw new Exceptions\UpdateError(
 60:             Lang::translate('Block storage volumes cannot be updated')
 61:         );
 62:     }
 63: 
 64:     /**
 65:      * returns the name of the volume
 66:      *
 67:      * @api
 68:      * @return string
 69:      */
 70:     public function Name() 
 71:     {
 72:         return $this->display_name;
 73:     }
 74: 
 75:     /********** PROTECTED METHODS **********/
 76: 
 77:     /**
 78:      * Creates the JSON object for the Create() method
 79:      *
 80:      * @return stdClass
 81:      */
 82:     protected function CreateJson() 
 83:     {
 84:         $element = $this->JsonName();
 85:         $object = new \stdClass();
 86:         $object->$element = new \stdClass();
 87: 
 88:         foreach ($this->_create_keys as $name) {
 89:             if ($this->$name) {
 90:                 switch($name) {
 91:                     case 'volume_type':
 92:                         $object->$element->$name = $this->volume_type->Name();
 93:                         break;
 94:                     default:
 95:                         $object->$element->$name = $this->$name;
 96:                         break;
 97:                 }
 98:             }
 99:         }
100: 
101:         if (is_array($this->metadata) && count($this->metadata)) {
102:             $object->$element->metadata = new \stdClass();
103:             foreach($this->metadata as $key => $value) {
104:                 $object->$element->metadata->$key = $value;
105:             }
106:         }
107: 
108:         return $object;
109:     }
110: 
111: }
112: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0