Class: CfFactory::BaseVpc
- Inherits:
-
Object
- Object
- CfFactory::BaseVpc
- Defined in:
- lib/cf_factory/modules/base_vpc.rb
Instance Attribute Summary collapse
-
#private_route_table ⇒ Object
readonly
Returns the value of attribute private_route_table.
-
#public_route_table ⇒ Object
readonly
Returns the value of attribute public_route_table.
-
#subnets ⇒ Object
readonly
Returns the value of attribute subnets.
-
#vpc ⇒ Object
readonly
Returns the value of attribute vpc.
Instance Method Summary collapse
- #add_to_template(cf) ⇒ Object
- #define_subnets ⇒ Object
- #define_vpc ⇒ Object
-
#initialize(name, cidr, number_public_subnets, number_private_subnets, availability_zones, subnet_size = 256) ⇒ BaseVpc
constructor
A new instance of BaseVpc.
- #ip2num(ip_part) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(name, cidr, number_public_subnets, number_private_subnets, availability_zones, subnet_size = 256) ⇒ BaseVpc
Returns a new instance of BaseVpc.
5 6 7 8 9 10 11 12 13 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 5 def initialize(name, cidr, number_public_subnets, number_private_subnets, availability_zones, subnet_size = 256) @name = name @cidr = cidr @number_public_subnets = number_public_subnets @number_private_subnets = number_private_subnets @subnet_size = subnet_size @availability_zones = availability_zones setup() end |
Instance Attribute Details
#private_route_table ⇒ Object (readonly)
Returns the value of attribute private_route_table.
3 4 5 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 3 def private_route_table @private_route_table end |
#public_route_table ⇒ Object (readonly)
Returns the value of attribute public_route_table.
3 4 5 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 3 def public_route_table @public_route_table end |
#subnets ⇒ Object (readonly)
Returns the value of attribute subnets.
3 4 5 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 3 def subnets @subnets end |
#vpc ⇒ Object (readonly)
Returns the value of attribute vpc.
3 4 5 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 3 def vpc @vpc end |
Instance Method Details
#add_to_template(cf) ⇒ Object
15 16 17 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 15 def add_to_template(cf) cf.add_vpc(@vpc) end |
#define_subnets ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 36 def define_subnets myMask = IpMask.create_from_cidr(@cidr) puts "myMask = #{myMask.inspect}" divider_array = [@subnet_size]*(@number_public_subnets + @number_private_subnets) puts "divider_array = #{divider_array}" subnet_ranges = myMask.divide_individually(divider_array) puts "subnet ranges = #{subnet_ranges.inspect}" @subnets = [] 0.upto(@number_public_subnets-1) do |i| @vpc.add_subnet(CfSubnet.new("#{@name}PublicSubnet#{i+1}", @cidr, @availability_zones[i%(@availability_zones.size)], @public_route_table)) end 0.upto(@number_private_subnets-1) do |i| @vpc.add_subnet(CfSubnet.new("#{@name}PrivateSubnet#{i+1}", @cidr, @availability_zones[i%(@availability_zones.size)], @private_route_table)) end end |
#define_vpc ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 24 def define_vpc @vpc = CfVpc.new(@cidr) igw = CfInternetGateway.new("#{@name}Igw", @vpc) @vpc.add_internet_gateway(igw) @private_route_table = CfRouteTable.new("#{@name}PrivRt") @vpc.add_route_table(@private_route_table) @public_route_table = CfRouteTable.new("#{@name}PubRt") igw_route = CfRoute.new("IgwRoute", "0.0.0.0/0", igw) @public_route_table.add_route(igw_route) @vpc.add_route_table(@public_route_table) end |
#ip2num(ip_part) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 52 def ip2num(ip_part) sum = 0 exp = 3 ip_part.split(".").each() {|ip| sum += ip.to_i * (256 ** exp) exp -= 1 } sum end |
#setup ⇒ Object
19 20 21 22 |
# File 'lib/cf_factory/modules/base_vpc.rb', line 19 def setup define_vpc() define_subnets() end |