Class: Fog::Compute::Aliyun::Volume

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



47
48
49
50
51
52
# File 'lib/fog/aliyun/models/compute/volume.rb', line 47

def destroy
  requires :id

  service.delete_disk(id)
  true
end

#imageObject



76
77
78
79
# File 'lib/fog/aliyun/models/compute/volume.rb', line 76

def image
  requires :image_id
  Fog::Compute::Aliyun::Images.new(service: service).all(imageId: image_id)[0]
end

#ready?Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/fog/aliyun/models/compute/volume.rb', line 54

def ready?
  requires :state
  state == 'Available'
end

#save(options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/aliyun/models/compute/volume.rb', line 59

def save(options = {})
  # raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  # requires :availability_zone
  requires_one :size, :snapshot_id
  options[:name] = name if name
  options[:description] = description if description
  if snapshot_id
    data = Fog::JSON.decode(service.create_disk_by_snapshot(snapshot_id, options).body)
    merge_attributes(data)
  elsif size
    data = Fog::JSON.decode(service.create_disk(size, options).body)
    merge_attributes(data)
  end

  true
end

#snapshotsObject



81
82
83
84
# File 'lib/fog/aliyun/models/compute/volume.rb', line 81

def snapshots
  requires :id
  Fog::Compute::Aliyun::Snapshots.new(service: service).all(volume_id: id)
end

#sourceObject



86
87
88
89
# File 'lib/fog/aliyun/models/compute/volume.rb', line 86

def source
  requires :snapshot_id
  Fog::Compute::Aliyun::Snapshots.new(service: service).all(snapshotIds: [snapshot_id])[0]
end