Class: Cumulus::VPC::SubnetConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vpc/models/SubnetConfig.rb

Overview

Public: An object representing configuration for a Subnet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, json = nil) ⇒ SubnetConfig

Public: Constructor

json - a hash containing the JSON configuration for the subnet



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vpc/models/SubnetConfig.rb', line 24

def initialize(name, json = nil)
  @name = name
  if !json.nil?
    @cidr_block = json["cidr-block"]
    @map_public_ip = json["map-public-ip"] || false
    @route_table = json["route-table"]
    @network_acl = json["network-acl"]
    @availability_zone = json["availability-zone"]
    @tags = json["tags"] || {}
  end
end

Instance Attribute Details

#availability_zoneObject (readonly)

Returns the value of attribute availability_zone.



18
19
20
# File 'lib/vpc/models/SubnetConfig.rb', line 18

def availability_zone
  @availability_zone
end

#cidr_blockObject (readonly)

Returns the value of attribute cidr_block.



14
15
16
# File 'lib/vpc/models/SubnetConfig.rb', line 14

def cidr_block
  @cidr_block
end

#map_public_ipObject (readonly)

Returns the value of attribute map_public_ip.



15
16
17
# File 'lib/vpc/models/SubnetConfig.rb', line 15

def map_public_ip
  @map_public_ip
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/vpc/models/SubnetConfig.rb', line 13

def name
  @name
end

#network_aclObject

Returns the value of attribute network_acl.



17
18
19
# File 'lib/vpc/models/SubnetConfig.rb', line 17

def network_acl
  @network_acl
end

#route_tableObject

Returns the value of attribute route_table.



16
17
18
# File 'lib/vpc/models/SubnetConfig.rb', line 16

def route_table
  @route_table
end

#tagsObject (readonly)

Returns the value of attribute tags.



19
20
21
# File 'lib/vpc/models/SubnetConfig.rb', line 19

def tags
  @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 SubnetDiffs that were found



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/vpc/models/SubnetConfig.rb', line 74

def diff(aws)
  diffs = []

  if @cidr_block != aws.cidr_block
    diffs << SubnetDiff.new(SubnetChange::CIDR, aws.cidr_block, @cidr_block)
  end

  if @map_public_ip != aws.map_public_ip_on_launch
    diffs << SubnetDiff.new(SubnetChange::PUBLIC, aws.map_public_ip_on_launch, @map_public_ip)
  end

  # For route table try to get the AWS name or default to id
  aws_subnet_rt = EC2::subnet_route_tables[aws.subnet_id]
  aws_rt_name = if aws_subnet_rt then aws_subnet_rt.name || aws_subnet_rt.route_table_id end
  if @route_table != aws_rt_name
    diffs << SubnetDiff.new(SubnetChange::ROUTE_TABLE, aws_rt_name, @route_table)
  end

  # For network acl try to get the AWS name or default to its id
  aws_subnet_net_acl = EC2::subnet_network_acls[aws.subnet_id]
  aws_net_acl_name = aws_subnet_net_acl.name || aws_subnet_net_acl.network_acl_id
  if @network_acl != aws_net_acl_name
    diffs << SubnetDiff.new(SubnetChange::NETWORK_ACL, aws_net_acl_name, @network_acl)
  end

  if @availability_zone != aws.availability_zone
    diffs << SubnetDiff.new(SubnetChange::AZ, aws.availability_zone, @availability_zone)
  end

  aws_tags = Hash[aws.tags.map { |tag| [tag.key, tag.value] }]
  if @tags != aws_tags
    diffs << SubnetDiff.new(SubnetChange::TAGS, aws_tags, @tags)
  end

  diffs
end

#populate!(aws, route_table_map = {}, network_acl_map = {}) ⇒ Object

Public: Populate a config object with AWS configuration

aws - the AWS configuration for the subnet route_table_map - an optional mapping of route table ids to names network_acl_map - an optional mapping of network acl ids to names



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vpc/models/SubnetConfig.rb', line 52

def populate!(aws, route_table_map = {}, network_acl_map = {})
  @cidr_block = aws.cidr_block
  @map_public_ip = aws.map_public_ip_on_launch

  subnet_rt = EC2::subnet_route_tables[aws.subnet_id]
  @route_table = if subnet_rt then route_table_map[subnet_rt.route_table_id] || subnet_rt.route_table_id end

  subnet_acl = EC2::subnet_network_acls[aws.subnet_id]
  @network_acl = network_acl_map[subnet_acl.network_acl_id] || subnet_acl.network_acl_id

  @availability_zone = aws.availability_zone
  @tags = Hash[aws.tags.map { |tag| [tag.key, tag.value] }]

  self
end

#to_hashObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/vpc/models/SubnetConfig.rb', line 36

def to_hash
  {
    "cidr-block" => @cidr_block,
    "map-public-ip" => @map_public_ip,
    "route-table" => @route_table,
    "network-acl" => @network_acl,
    "availability-zone" => @availability_zone,
    "tags" => @tags,
  }
end