1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 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: 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:
42: 43: 44:
45: public $imageRef;
46: public $bootable;
47:
48: protected static $json_name = 'volume';
49: protected static $url_resource = 'volumes';
50:
51: protected $createKeys = array(
52: 'snapshot_id',
53: 'display_name',
54: 'display_description',
55: 'size',
56: 'volume_type',
57: 'availability_zone',
58: 'metadata',
59: 'source_volid',
60: 'bootable',
61: 'imageRef'
62: );
63:
64: protected $associatedResources = array();
65:
66: public function update($params = array())
67: {
68: throw new Exceptions\UpdateError(
69: Lang::translate('Block storage volumes cannot be updated')
70: );
71: }
72:
73: 74: 75: 76: 77: 78: 79:
80: public function rename(array $params = array())
81: {
82: $data = array();
83:
84: $keys = array('display_description', 'display_name');
85:
86: foreach ($params as $key => $value) {
87: if (in_array($key, $keys)) {
88: $data[$key] = $value;
89: } else {
90: throw new \InvalidArgumentException(sprintf(
91: 'You cannot update the %s volume property. Valid keys are: %s',
92: $key, implode($keys, ',')
93: ));
94: }
95: }
96:
97: $json = json_encode(array(
98: 'volume' => $data
99: ));
100:
101: return $this->getClient()
102: ->put($this->getUrl(), self::getJsonHeader(), $json)
103: ->send();
104: }
105:
106: public function name()
107: {
108: return $this->display_name;
109: }
110:
111: protected function createJson()
112: {
113: $element = parent::createJson();
114:
115: if ($this->getProperty('volume_type') instanceof VolumeType) {
116: $element->volume->volume_type = $this->volume_type->name();
117: }
118:
119: return $element;
120: }
121: }
122: