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



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

def destroy
  requires :id

  service.delete_disk(id)
  true
end

#imageObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#save(options = {}) ⇒ Object



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

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



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

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

#sourceObject



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

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