Class: Fog::Compute::Vsphere::Volumes

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/vsphere/models/compute/volumes.rb

Instance Method Summary collapse

Instance Method Details

#all(filters = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/vsphere/models/compute/volumes.rb', line 12

def all(filters = {})
  requires :server_id

  case server
    when Fog::Compute::Vsphere::Server
      load service.list_vm_volumes(server.id)
    when Fog::Compute::Vsphere::Template
      load service.list_template_volumes(server.id)
    else
      raise 'volumes should have vm or template'
    end

  self.each { |volume| volume.server_id = server.id }
  self
end

#get(id) ⇒ Object



28
29
30
# File 'lib/fog/vsphere/models/compute/volumes.rb', line 28

def get(id)
  new service.get_volume(id)
end

#new(attributes = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/vsphere/models/compute/volumes.rb', line 32

def new(attributes = {})
  if server_id
    # Default to the root volume datastore if one is not configured.
    datastore = ! attributes.key?(:datastore) && self.any? ? self.first.datastore : nil

    super({ :server_id => server_id, :datastore => datastore }.merge!(attributes))
  else
    super
  end
end

#serverObject



43
44
45
46
# File 'lib/fog/vsphere/models/compute/volumes.rb', line 43

def server
  return nil if server_id.nil?
  service.servers.get(server_id)
end

#server=(new_server) ⇒ Object



48
49
50
# File 'lib/fog/vsphere/models/compute/volumes.rb', line 48

def server=(new_server)
  server_id = new_server.id
end