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.



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

def project_id
  @project_id
end

#snapshot_idObject

Returns the value of attribute snapshot_id.



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

def snapshot_id
  @snapshot_id
end

Instance Method Details

#attach(instance_or_id, mountpoint = nil) ⇒ Object



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

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



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

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

#detachObject



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

def detach
  requires :id

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

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

#flavorObject Also known as: disk_offering



52
53
54
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 52

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

#ready?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/fog/cloudstack/models/compute/volume.rb', line 48

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

#reloadObject



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

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



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

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



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

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

#snapshotsObject



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

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