Class: Cumulus::EC2::EbsGroupConfig
- Inherits:
-
Object
- Object
- Cumulus::EC2::EbsGroupConfig
- Defined in:
- lib/ec2/models/EbsGroupConfig.rb
Overview
Public: An object representing configuration for a group of EBS volumes
Instance Attribute Summary collapse
-
#availability_zone ⇒ Object
readonly
Returns the value of attribute availability_zone.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#volume_groups ⇒ Object
readonly
Returns the value of attribute volume_groups.
Instance Method Summary collapse
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(name, json = nil) ⇒ EbsGroupConfig
constructor
Public: Constructor.
-
#populate!(aws) ⇒ Object
Public: Populate a config object with AWS configuration.
- #to_hash ⇒ Object
Constructor Details
#initialize(name, json = nil) ⇒ EbsGroupConfig
Public: Constructor
json - a hash containing the JSON configuration for the group
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |
Instance Attribute Details
#availability_zone ⇒ Object (readonly)
Returns the value of attribute availability_zone.
40 41 42 |
# File 'lib/ec2/models/EbsGroupConfig.rb', line 40 def availability_zone @availability_zone end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/ec2/models/EbsGroupConfig.rb', line 38 def name @name end |
#volume_groups ⇒ Object (readonly)
Returns the value of attribute volume_groups.
39 40 41 |
# File 'lib/ec2/models/EbsGroupConfig.rb', line 39 def volume_groups @volume_groups end |
Instance Method Details
#diff(aws) ⇒ Object
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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# 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) ⇒ Object
Public: Populate a config object with AWS configuration
aws - the ebs volumes in the group. All volumes should be in the same AZ
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
62 63 64 65 66 67 |
# File 'lib/ec2/models/EbsGroupConfig.rb', line 62 def to_hash { "availability-zone" => @availability_zone, "volumes" => @volume_groups.map(&:to_hash), } end |