Class: Kelbim::ELBWrapper::LoadBalancerCollection
- Inherits:
-
Object
- Object
- Kelbim::ELBWrapper::LoadBalancerCollection
- Includes:
- Logger::ClientHelper
- Defined in:
- lib/kelbim/wrapper/policy.rb,
lib/kelbim/wrapper/listener.rb,
lib/kelbim/wrapper/load-balancer.rb,
lib/kelbim/wrapper/policy-collection.rb,
lib/kelbim/wrapper/listener-collection.rb,
lib/kelbim/wrapper/load-balancer-collection.rb
Defined Under Namespace
Classes: LoadBalancer
Instance Method Summary collapse
- #create(dsl, vpc) ⇒ Object
- #each ⇒ Object
-
#initialize(load_balancers, options) ⇒ LoadBalancerCollection
constructor
A new instance of LoadBalancerCollection.
Methods included from Logger::ClientHelper
Constructor Details
#initialize(load_balancers, options) ⇒ LoadBalancerCollection
Returns a new instance of LoadBalancerCollection.
11 12 13 14 |
# File 'lib/kelbim/wrapper/load-balancer-collection.rb', line 11 def initialize(load_balancers, ) @load_balancers = load_balancers @options = end |
Instance Method Details
#create(dsl, vpc) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kelbim/wrapper/load-balancer-collection.rb', line 22 def create(dsl, vpc) log(:info, 'Create LoadBalancer', :cyan, "#{vpc || :classic} > #{dsl.name}") if @options.dry_run listeners = dsl.listeners lb = OpenStruct.new({ :id => "<new load balancer name=#{dsl.name}>", :name => dsl.name, :vpc_id => vpc, :instances => [], # instancesはLoadBalancerの処理で更新 :scheme => dsl.scheme, :health_check => {}, # health_checkはLoadBalancerの処理で更新 :attributes => {}, # attributesはLoadBalancerの処理で更新 }) lb.listeners = dsl.listeners.map do |lstnr| LoadBalancer::ListenerCollection.create_mock_listener(lstnr, lb) end if vpc lb.subnets = dsl.subnets.map {|i| OpenStruct.new(:id => i) } sg_names = @options.security_group_names[vpc] || {} lb.security_group_ids = dsl.security_groups {|i| sg_names.key(i) || i } else lb.availability_zones = dsl.availability_zones.map {|i| OpenStruct.new(:name => i) } end else opts = { :scheme => dsl.scheme, :listeners => [], } # instancesはLoadBalancerの処理で更新 dsl.listeners.each do |lstnr| lstnr_opts = LoadBalancer::ListenerCollection.(lstnr, @options.iam) opts[:listeners] << lstnr_opts end if vpc opts[:subnets] = dsl.subnets.map {|i| AWS::EC2::Subnet.new(i) } sg_names = @options.security_group_names[vpc] || {} opts[:security_groups] = dsl.security_groups.map do |i| AWS::EC2::SecurityGroup.new(sg_names.key(i) || i) end else opts[:availability_zones] = dsl.availability_zones.map {|i| AWS::EC2::AvailabilityZone.new(i) } end # health_check、attributesはLoadBalancerの処理で更新 lb = @load_balancers.create(dsl.name, opts) @options.updated = true end LoadBalancer.new(lb, @options) end |
#each ⇒ Object
16 17 18 19 20 |
# File 'lib/kelbim/wrapper/load-balancer-collection.rb', line 16 def each @load_balancers.each do |lb| yield(LoadBalancer.new(lb, @options)) end end |