Sha256: 6a3b63c2a6590bc8fb87e8ca8176bf5a8a36a385a32faf1801e2b8ed5ca530d6
Contents?: true
Size: 1.3 KB
Versions: 3
Compression:
Stored size: 1.3 KB
Contents
class Volume < ActiveRecord::Base belongs_to :server, inverse_of: :volumes belongs_to :availability_zone, inverse_of: :volumes has_many :tags, as: :taggable before_validation :set_hourly_rate def self.import(aws_volume) volume = Volume.where(remote_id: aws_volume.id).first || Volume.new(remote_id: aws_volume.id) volume.attributes = { name: aws_volume.tags["Name"], remote_id: aws_volume.id, state: aws_volume.state, volume_type: aws_volume.type, iops: aws_volume.iops, size: aws_volume.size, server: Server.where(remote_id: aws_volume.server_id).first, availability_zone: AvailabilityZone.find_or_create_by(name: aws_volume.availability_zone), created_at: aws_volume.created_at } volume.save! aws_volume.tags.each do |key, value| volume.tags.find_or_create_by(name: key.downcase).update_attributes(value: value.downcase) end volume end def set_hourly_rate self.hourly_rate = if volume_type == "standard" (0.10 * self.size) / 720 elsif volume_type == "io1" ((0.125 * self.size) + (0.10 * self.iops)) / 720 else raise "Unknown volume_type : #{self.volume_type}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
crop-duster-0.0.9 | lib/models/volume.rb |
crop-duster-0.0.8 | lib/models/volume.rb |
crop-duster-0.0.7 | lib/models/volume.rb |