Class: Cumulus::VPC::SubnetConfig
- Inherits:
-
Object
- Object
- Cumulus::VPC::SubnetConfig
- Defined in:
- lib/vpc/models/SubnetConfig.rb
Overview
Public: An object representing configuration for a Subnet
Instance Attribute Summary collapse
-
#availability_zone ⇒ Object
readonly
Returns the value of attribute availability_zone.
-
#cidr_block ⇒ Object
readonly
Returns the value of attribute cidr_block.
-
#map_public_ip ⇒ Object
readonly
Returns the value of attribute map_public_ip.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#network_acl ⇒ Object
Returns the value of attribute network_acl.
-
#route_table ⇒ Object
Returns the value of attribute route_table.
-
#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) ⇒ SubnetConfig
constructor
Public: Constructor.
-
#populate!(aws, route_table_map = {}, network_acl_map = {}) ⇒ Object
Public: Populate a config object with AWS configuration.
- #to_hash ⇒ Object
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_zone ⇒ Object (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_block ⇒ Object (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_ip ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/vpc/models/SubnetConfig.rb', line 13 def name @name end |
#network_acl ⇒ Object
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_table ⇒ Object
Returns the value of attribute route_table.
16 17 18 |
# File 'lib/vpc/models/SubnetConfig.rb', line 16 def route_table @route_table end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
19 20 21 |
# File 'lib/vpc/models/SubnetConfig.rb', line 19 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 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 = Hash[aws..map { |tag| [tag.key, tag.value] }] if @tags != diffs << SubnetDiff.new(SubnetChange::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..map { |tag| [tag.key, tag.value] }] self end |
#to_hash ⇒ Object
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 |