class Cumulus::EC2::EbsGroupConfig
Public: An object representing configuration for a group of EBS volumes
Attributes
availability_zone[R]
name[R]
volume_groups[R]
Public Class Methods
new(name, json = nil)
click to toggle source
Public: Constructor
json - a hash containing the JSON configuration for the group
# File lib/ec2/models/EbsGroupConfig.rb, line 45 def initialize(name, json = nil) @name = name if !json.nil? @availability_zone = json["availability-zone"] @volume_groups = (json["volumes"] || []).map do |vg_json| VolumeGroup.new( vg_json["size"], vg_json["type"], if vg_json["type"] == "io1" then vg_json["iops"] end, vg_json["count"], vg_json["encrypted"] || false, if vg_json["encrypted"] then vg_json["kms-key"] end ) end end end
Public Instance Methods
diff(aws)
click to toggle source
Public: Produce an array of differences between this local configuration and the configuration in AWS
aws - the AWS resource
Returns an array of the EbsGroupDiffs that were found
# File lib/ec2/models/EbsGroupConfig.rb, line 99 def diff(aws) diffs = [] if @availability_zone != aws.availability_zone diffs << EbsGroupDiff.new(EbsGroupChange::AZ, aws.availability_zone, @availability_zone) end # Group the aws and local versions by hash_key aws_grouped = Hash[aws.volume_groups.map { |vg| [vg.hash_key, vg] }] local_grouped = Hash[@volume_groups.map { |vg| [vg.hash_key, vg] }] # added local_grouped.reject { |key, vg| aws_grouped.has_key? key }.each do |key, vg| diffs << EbsGroupDiff.new(EbsGroupChange::VG_ADDED, nil, vg) end # removed aws_grouped.reject { |key, vg| local_grouped.has_key? key }.each do |key, vg| diffs << EbsGroupDiff.new(EbsGroupChange::VG_REMOVED, vg, nil) end # count is different local_grouped.select { |key, vg| aws_grouped.has_key? key }.each do |key, local_vg| aws_vg = aws_grouped[key] if local_vg.count != aws_vg.count diffs << EbsGroupDiff.new(EbsGroupDiff::VG_COUNT, aws_vg, local_vg) end end diffs.sort_by { |diff| diff.type } end
populate!(aws)
click to toggle source
Public: Populate a config object with AWS configuration
aws - the ebs volumes in the group. All volumes should be in the same AZ
# File lib/ec2/models/EbsGroupConfig.rb, line 72 def populate!(aws) # Group the aws volumes by size, type, iops, encryped, kms-key vol_groups = aws.group_by { |vol| "#{vol.size}|#{vol.volume_type}|#{vol.iops}|#{vol.encrypted}|#{vol.kms_key_id}" } @volume_groups = vol_groups.map do |_, vols| VolumeGroup.new( vols.first.size, vols.first.volume_type, if vols.first.volume_type == "io1" then vols.first.iops end, vols.length, vols.first.encrypted, vols.first.kms_key_id ) end # Get the AZ of the first volume @availability_zone = aws.first.availability_zone self end
to_hash()
click to toggle source
# File lib/ec2/models/EbsGroupConfig.rb, line 62 def to_hash { "availability-zone" => @availability_zone, "volumes" => @volume_groups.map(&:to_hash), } end