Class: OpenStack::Nova::Compute::VolumeAttachment
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Common
- Base
- OpenStack::Nova::Compute::VolumeAttachment
- Defined in:
- lib/open_stack/nova/compute/volume_attachment.rb
Overview
A Volume attachment (this class describes an attachment of a volume to a server)
Attributes
-
device
- The volume (unique) name (e.g. /dev/vdc)
Instance Method Summary collapse
-
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method.
-
#initialize(attributes = {}, persisted = false) ⇒ VolumeAttachment
constructor
:notnew:.
-
#server ⇒ Object
Return the server to which this volume_attachment is related (if any).
-
#server=(server) ⇒ Object
Bind the volume_attachment to a sever.
-
#volume ⇒ Object
Return the volume to which this volume_attachment is related (if any).
-
#volume=(volume) ⇒ Object
Bind the volume_attachment to a volume.
Methods inherited from Base
Methods inherited from Common
collection_path, custom_method_collection_url, element_path
Methods inherited from Base
Methods inherited from ActiveResource::Base
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ VolumeAttachment
:notnew:
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/open_stack/nova/compute/volume_attachment.rb', line 45 def initialize(attributes = {}, persisted = false) # :notnew: attributes = attributes.with_indifferent_access new_attributes = { :device => attributes[:device], } = super(new_attributes, persisted) if attributes[:volume].present? .volume_id = attributes[:volume].id else .volume_id = attributes[:volumeId] end if attributes[:server].present? .server_id = attributes[:server].id else .server_id = attributes[:serverId] end .[:server_id] = .server_id end |
Instance Method Details
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/open_stack/nova/compute/volume_attachment.rb', line 71 def encode(={}) # :nodoc: Custom encoding to deal with openstack API to_encode = { VolumeAttachment.element_name => { :device => device, :volumeId => volume_id, :serverId => server_id } } to_encode.send("to_#{self.class.format.extension}", ) end |
#server ⇒ Object
Return the server to which this volume_attachment is related (if any)
83 84 85 |
# File 'lib/open_stack/nova/compute/volume_attachment.rb', line 83 def server Server.find(server_id) if server_id.present? end |
#server=(server) ⇒ Object
Bind the volume_attachment to a sever
Attributes
-
server
- an OpenStack::Nova::Compute::Server instance
91 92 93 |
# File 'lib/open_stack/nova/compute/volume_attachment.rb', line 91 def server=(server) @attributes[:server_id] = server.id if !persisted? end |
#volume ⇒ Object
Return the volume to which this volume_attachment is related (if any)
96 97 98 |
# File 'lib/open_stack/nova/compute/volume_attachment.rb', line 96 def volume Volume::Volume.find(volume_id) if volume_id.present? end |
#volume=(volume) ⇒ Object
Bind the volume_attachment to a volume
Attributes
-
volume
- an OpenStack::Nova::Compute::Volume instance
104 105 106 |
# File 'lib/open_stack/nova/compute/volume_attachment.rb', line 104 def volume=(volume) @attributes[:volume_id] = volume.id if !persisted? end |