1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# frozen_string_literal: true
require 'fog/core/model'
module Fog
module Compute
class Aliyun
class Image < Fog::Model
identity :id, aliases: 'ImageId'
attribute :description, aliases: 'Description'
attribute :product_code, aliases: 'ProductCode'
attribute :os_type, aliases: 'OSType'
attribute :architecture, aliases: 'Architecture'
attribute :os_name, aliases: 'OSName'
attribute :disk_device_mappings, aliases: 'DiskDeviceMappings'
attribute :owner_alias, aliases: 'ImageOwnerAlias'
attribute :progress, aliases: 'Progress'
attribute :usage, aliases: 'Usage'
attribute :created_at, aliases: 'CreationTime'
attribute :tags, aliases: 'Tags'
attribute :version, aliases: 'ImageVersion'
attribute :state, aliases: 'Status'
attribute :name, aliases: 'ImageName'
attribute :is_self_shared, aliases: 'IsSelfShared'
attribute :is_copied, aliases: 'IsCopied'
attribute :is_subscribed, aliases: 'IsSubscribed'
attribute :platform, aliases: 'Platform'
attribute :size, aliases: 'Size'
attribute :snapshot_id, aliases: 'SnapshotId'
def initialize(attributes)
unless attributes['DiskDeviceMappings']['DiskDeviceMapping'].empty?
self.snapshot_id = attributes['DiskDeviceMappings']['DiskDeviceMapping'][0]['SnapshotId']
end
super
end
def save(options = {})
requires :snapshot_id
options[:name] = name if name
options[:description] = description if description
data = Fog::JSON.decode(service.create_image(snapshot_id, options).body)
merge_attributes(data)
true
end
def destroy
requires :id
service.delete_image(id)
true
end
def ready?
state == 'Available'
end
def snapshot
requires :snapshot_id
Fog::Compute::Aliyun::Snapshots.new(service: service).all(snapshotIds: [snapshot_id])[0]
end
private
def snapshot=(new_snapshot)
self.snapshot_id = new_snapshot.id
end
end
end
end
end
|