Class: Fog::Compute::Cloudstack::Volume

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/cloudstack/models/compute/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#project_idObject

Returns the value of attribute project_id.



29
30
31
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 29

def project_id
  @project_id
end

#snapshot_idObject

Returns the value of attribute snapshot_id.



29
30
31
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 29

def snapshot_id
  @snapshot_id
end

Instance Method Details

#attach(instance_or_id, mountpoint = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 85

def attach(instance_or_id, mountpoint=nil)
  requires :id
  instance_id = instance_or_id.is_a?(Server) ? instance_or_id.id : instance_or_id
  unless instance_id
    raise ArgumentError, "Missing required argument: instance_or_id"
  end

  options = {
    'id'               => id,
    'virtualmachineid' => instance_id,
  }
  options.merge!('deviceid' => mountpoint) if mountpoint

  data = service.attach_volume(options)

					service.jobs.new(data["attachvolumeresponse"])
end

#destroyObject



111
112
113
114
115
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 111

def destroy
  requires :id
  service.delete_volume('id' => id)
  true
end

#detachObject



103
104
105
106
107
108
109
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 103

def detach
  requires :id

  data = service.detach_volume('id' => id)

  service.jobs.new(data["detachvolumeresponse"])
end

#flavorObject Also known as: disk_offering



50
51
52
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 50

def flavor
  service.disk_offerings.get(self.disk_offering_id)
end

#ready?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 46

def ready?
  state == 'Allocated' || state == 'Ready'
end

#reloadObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 66

def reload
  requires :identity

  return unless data = begin
                         collection.get(identity)
                       rescue Excon::Errors::SocketError
                         nil
                       end

  new_attributes = {
    'virtualmachineid' => nil,
    'vmname' => nil,
    'vmdisplayname' => nil
  }.merge(data.attributes)

  merge_attributes(new_attributes)
  self
end

#saveObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 31

def save
  requires :name, :disk_offering_id, :zone_id

  options = {
    'size'           => size,
    'name'           => name,
    'diskofferingid' => disk_offering_id,
    'zoneid'         => zone_id,
    'snapshotid'     => snapshot_id,
    'projectid'      => project_id
  }
  data = service.create_volume(options)
  merge_attributes(data['createvolumeresponse'])
end

#serverObject



55
56
57
58
59
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 55

def server
  if server_id
    service.servers.get(server_id)
  end
end

#snapshotsObject



61
62
63
64
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 61

def snapshots
  requires :id
  service.snapshots.all('volumeid' => id)
end