Class: OpenStack::Nova::Compute::VolumeAttachment

Inherits:
Base show all
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

Methods inherited from Base

site, site=

Methods inherited from Common

collection_path, custom_method_collection_url, element_path

Methods inherited from Base

headers

Methods inherited from ActiveResource::Base

#load

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],
  }

  new_attachment = super(new_attributes, persisted)

  if attributes[:volume].present?
    new_attachment.volume_id = attributes[:volume].id
  else
    new_attachment.volume_id = attributes[:volumeId]
  end

  if attributes[:server].present?
    new_attachment.server_id = attributes[:server].id
  else
    new_attachment.server_id = attributes[:serverId]
  end

  new_attachment.prefix_options[:server_id] = new_attachment.server_id

  new_attachment
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(options={}) # :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}", options)
end

#serverObject

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

#volumeObject

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