Class: Cumulus::EC2::InstanceDiff

Inherits:
Common::Diff show all
Includes:
Common::TagsDiff, InstanceChange
Defined in:
lib/ec2/models/InstanceDiff.rb

Overview

Public: Represents a single difference between local configuration and AWS configuration

Constant Summary

Constants included from InstanceChange

Cumulus::EC2::InstanceChange::EBS, Cumulus::EC2::InstanceChange::INTERFACES, Cumulus::EC2::InstanceChange::MONITORING, Cumulus::EC2::InstanceChange::PROFILE, Cumulus::EC2::InstanceChange::SDCHECK, Cumulus::EC2::InstanceChange::SECURITY_GROUPS, Cumulus::EC2::InstanceChange::SUBNET, Cumulus::EC2::InstanceChange::TAGS, Cumulus::EC2::InstanceChange::TENANCY, Cumulus::EC2::InstanceChange::TYPE, Cumulus::EC2::InstanceChange::VOLUME_GROUPS

Constants included from Common::DiffChange

Common::DiffChange::ADD, Common::DiffChange::MODIFIED, Common::DiffChange::UNMANAGED

Instance Attribute Summary

Attributes inherited from Common::Diff

#aws, #changes, #info_only, #local, #type

Instance Method Summary collapse

Methods included from Common::TagsDiff

#tags_diff_string, #tags_to_add, #tags_to_remove

Methods included from Common::DiffChange

next_change_id

Methods inherited from Common::Diff

#add_string, added, #initialize, #local_name, modified, #to_s, unmanaged, #unmanaged_string

Constructor Details

This class inherits a constructor from Cumulus::Common::Diff

Instance Method Details

#asset_typeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ec2/models/InstanceDiff.rb', line 31

def asset_type
  case @type
  when EBS then "EBS Optimized"
  when PROFILE then "Instance Profile"
  when MONITORING then "Monitoring"
  when INTERFACES then "Network Interfaces"
  when SDCHECK then "Source Dest Check"
  when SECURITY_GROUPS then "Security Groups"
  when SUBNET then "Subnet"
  when TYPE then "Type"
  when TENANCY then "Tenancy"
  when VOLUME_GROUPS then "Volume Groups"
  when TAGS then "Tags"
  else
    "EC2 Instance"
  end
end

#aws_nameObject



49
50
51
# File 'lib/ec2/models/InstanceDiff.rb', line 49

def aws_name
  @aws.name
end

#aws_tagsObject



57
58
59
# File 'lib/ec2/models/InstanceDiff.rb', line 57

def aws_tags
  @aws
end

#diff_stringObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ec2/models/InstanceDiff.rb', line 61

def diff_string
  case @type
  when EBS, PROFILE, MONITORING, INTERFACES, SDCHECK, SUBNET, TYPE, TENANCY
    [
      "#{asset_type}:",
      Colors.aws_changes("\tAWS - #{aws}"),
      Colors.local_changes("\tLocal - #{local}"),
    ].join("\n")
  when SECURITY_GROUPS
    [
      "#{asset_type}:",
      @changes.removed.map { |sg| Colors.unmanaged("\t#{sg}") },
      @changes.added.map { |sg| Colors.added("\t#{sg}") }
    ].flatten.join("\n")
  when VOLUME_GROUPS
    [
      "#{asset_type}:",
      @changes.removed.map { |vg, _| Colors.unmanaged("\t#{vg} is attached but not managed by Cumulus") },
      @changes.added.map { |vg, _| Colors.added("\t#{vg} will be attached to the instance") },
      @changes.modified.map do |vg, diff|
        [
          "\t#{vg}:",
          diff.changes.map do |diff|
            diff.to_s.lines.map { |l| "\t\t#{l}".chomp("\n") }
          end
        ]
      end
    ].flatten.join("\n")
  when TAGS
    tags_diff_string
  end
end

#local_tagsObject



53
54
55
# File 'lib/ec2/models/InstanceDiff.rb', line 53

def local_tags
  @local
end