Class: Fog::Brightbox::Compute::Volume
- Includes:
- ResourceLocking
- Defined in:
- lib/fog/brightbox/models/compute/volume.rb
Instance Method Summary collapse
- #attach(server) ⇒ Object
- #attached? ⇒ Boolean
-
#copy(options = {}) ⇒ Fog::Compute::Volume
A new model for the copy.
- #creating? ⇒ Boolean
- #deleted? ⇒ Boolean
- #deleting? ⇒ Boolean
- #destroy ⇒ Object
- #detach ⇒ Object
- #detached? ⇒ Boolean
- #failed? ⇒ Boolean
- #finished? ⇒ Boolean
- #ready? ⇒ Boolean
- #resize(options) ⇒ Object
- #save ⇒ Object
Methods included from ResourceLocking
Methods included from ModelHelper
#collection_name, #resource_name
Instance Method Details
#attach(server) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 39 def attach(server) requires :identity data = service.attach_volume(identity, server: server.id) merge_attributes(data) true end |
#attached? ⇒ Boolean
46 47 48 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 46 def attached? state == "attached" end |
#copy(options = {}) ⇒ Fog::Compute::Volume
Returns a new model for the copy.
57 58 59 60 61 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 57 def copy( = {}) requires :identity data = service.copy_volume(identity, ) service.volumes.new(data) end |
#creating? ⇒ Boolean
63 64 65 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 63 def creating? state == "creating" end |
#deleted? ⇒ Boolean
67 68 69 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 67 def deleted? state == "deleted" end |
#deleting? ⇒ Boolean
71 72 73 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 71 def deleting? state == "deleting" end |
#destroy ⇒ Object
146 147 148 149 150 151 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 146 def destroy requires :identity data = service.delete_volume(identity) merge_attributes(data) true end |
#detach ⇒ Object
75 76 77 78 79 80 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 75 def detach requires :identity data = service.detach_volume(identity) merge_attributes(data) true end |
#detached? ⇒ Boolean
82 83 84 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 82 def detached? state == "detached" end |
#failed? ⇒ Boolean
86 87 88 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 86 def failed? state == "failed" end |
#finished? ⇒ Boolean
90 91 92 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 90 def finished? deleted? || failed? end |
#ready? ⇒ Boolean
94 95 96 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 94 def ready? attached? || detached? end |
#resize(options) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 100 def resize() requires :identity # The API requires the old "from" size to avoid acting on stale data # We can merge this and if the API rejects the request, the model was out of sync [:from] = size data = service.resize_volume(identity, ) merge_attributes(data) true end |
#save ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/fog/brightbox/models/compute/volume.rb', line 112 def save if persisted? = { delete_with_server: delete_with_server, description: description, name: name, serial: serial }.delete_if { |_k, v| v.nil? || v == "" } data = service.update_volume(identity, ) else raise Fog::Errors::Error, "'image_id' and 'filesystem_type' are mutually exclusive" if image_id && filesystem_type raise Fog::Errors::Error, "'image_id' or 'filesystem_type' is required" unless image_id || filesystem_type = { delete_with_server: delete_with_server, description: description, encrypted: encrypted, filesystem_label: filesystem_label, filesystem_type: filesystem_type, name: name, serial: serial, size: size }.delete_if { |_k, v| v.nil? || v == "" } [:image] = image_id unless image_id.nil? || image_id == "" data = service.create_volume() end merge_attributes(data) true end |