Class: Cumulus::VPC::RouteTableConfig
- Inherits:
-
Object
- Object
- Cumulus::VPC::RouteTableConfig
- Defined in:
- lib/vpc/models/RouteTableConfig.rb
Overview
Public: An object representing configuration for a VPC route table
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#propagate_vgws ⇒ Object
readonly
Returns the value of attribute propagate_vgws.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
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) ⇒ RouteTableConfig
constructor
Public: Constructor.
- #populate!(aws) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, json = nil) ⇒ RouteTableConfig
Public: Constructor
json - a hash containing the JSON configuration for the route table
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 21 def initialize(name, json = nil) @name = name @excludes = [] if !json.nil? @routes = (json["routes"] || []).map { |route| RouteConfig.new(route) } @propagate_vgws = json["propagate-vgws"] || [] @tags = json["tags"] @excludes = json["exclude-cidr-blocks"] || [] end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 13 def name @name end |
#propagate_vgws ⇒ Object (readonly)
Returns the value of attribute propagate_vgws.
15 16 17 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 15 def propagate_vgws @propagate_vgws end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
14 15 16 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 14 def routes @routes end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
16 17 18 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 16 def @tags 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 RouteTableDiffs that were found
60 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 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 60 def diff(aws) diffs = [] aws_routes = aws.diffable_routes.reject { |route| @excludes.include? route.destination_cidr_block } local_routes = @routes.reject { |route| @excludes.include? route.dest_cidr } ignored_aws_routes = aws.diffable_routes.select { |route| @excludes.include? route.destination_cidr_block }.map(&:destination_cidr_block).join(", ") ignored_local_routes = @routes.select { |route| @excludes.include? route.dest_cidr }.map(&:dest_cidr).join(", ") puts "Ignoring local routes: #{ignored_local_routes}" if !ignored_local_routes.empty? puts "Ignoring AWS routes: #{ignored_aws_routes}" if !ignored_aws_routes.empty? routes_diff = RouteTableDiff.routes(aws_routes, local_routes) if routes_diff diffs << routes_diff end aws_vgw_ids = aws.propagating_vgws.map(&:gateway_id) if @propagate_vgws.sort != aws_vgw_ids.sort diffs << RouteTableDiff.propagate_vgws(aws_vgw_ids, @propagate_vgws) end = Hash[aws..map { |tag| [tag.key, tag.value] }] if @tags != diffs << RouteTableDiff.new(RouteTableChange::TAGS, , @tags) end diffs end |
#populate!(aws) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 40 def populate!(aws) @routes = aws.diffable_routes.reject { |route| @excludes.include? route.destination_cidr_block }.map do |aws_route| cumulus_route = RouteConfig.new cumulus_route.populate!(aws_route) cumulus_route end @propagate_vgws = aws.propagating_vgws.map(&:gateway_id) @tags = Hash[aws..map { |tag| [tag.key, tag.value] }] self end |
#to_hash ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/vpc/models/RouteTableConfig.rb', line 32 def to_hash { "routes" => @routes.map(&:to_hash), "propagate-vgws" => @propagate_vgws, "tags" => @tags, }.reject { |k, v| v.nil? } end |