kelbim 0.2.9 → 0.3.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f17dc184fd3cf7fe7567a5bc11be8731a120ce5
4
- data.tar.gz: 7fe61d62a7ab76d658cb478c1e88578811c10c96
3
+ metadata.gz: b2a329d50ba93b5acaacef247844fa11372b8492
4
+ data.tar.gz: 2c1e85f5409c3e6ed565a3cc2fc5609ffdc13f6f
5
5
  SHA512:
6
- metadata.gz: 957db04a1a2719744695d2ac378a94fc0fba548e526d87e1408dd76a762a3f112eb1a855c4f8a249d45abfa8337e8a080996ab645a4c84d387e75d89c6468fd9
7
- data.tar.gz: 78e2173873bf2481c80b8e0a51276a2d3fa822823a0c852abce2b23c57336be2755bfa05789ad8cd598ed4f38afc639bc0b29f6bca6a87f88dd34fb0ddae768e
6
+ metadata.gz: a181f841ecef76a507607c5c802af5421ba5a24933a42b0b92d54a72cad17b3856e789ff1a33aa5d80e1341750e9d7fea22fcafd30d1e768f6d0cbabdd386e29
7
+ data.tar.gz: fce277ac7f3f8be8669ee105a4ccc31fd675b81660fed61048c4f5ac89999a052d452d8abec6aea4ab8183c49fd763023d2b22e870727edc40ae812e68c33bab
data/README.md CHANGED
@@ -4,7 +4,7 @@ Kelbim is a tool to manage ELB.
4
4
 
5
5
  It defines the state of ELB using DSL, and updates ELB according to DSL.
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/kelbim.png)](http://badge.fury.io/rb/kelbim)
7
+ [![Gem Version](https://badge.fury.io/rb/kelbim.svg)](https://badge.fury.io/rb/kelbim)
8
8
  [![Build Status](https://travis-ci.org/winebarrel/kelbim.svg?branch=master)](https://travis-ci.org/winebarrel/kelbim)
9
9
 
10
10
  **Notice**
@@ -148,6 +148,33 @@ ec2 "vpc-XXXXXXXXX" do
148
148
  end
149
149
  ```
150
150
 
151
+ ## Use template
152
+
153
+ ```ruby
154
+ template "listeners" do
155
+ listeners do
156
+ listener [:tcp, 80] => [:tcp, context.backend_port]
157
+ listener [:https, 443] => [:http, context.backend_port] do
158
+ app_cookie_stickiness "CookieName"=>"20"
159
+ ssl_negotiation ["Protocol-TLSv1", "Protocol-SSLv3", "AES256-SHA", ...]
160
+ server_certificate "my-cert"
161
+ end
162
+ end
163
+ end
164
+
165
+ ec2 "vpc-XXXXXXXXX" do
166
+ load_balancer "my-load-balancer", :internal => true do
167
+ instances(
168
+ "nyar",
169
+ "yog"
170
+ )
171
+
172
+ include_template "listeners", backend_port: 80
173
+ ...
174
+ end
175
+ end
176
+ ```
177
+
151
178
  ## Test
152
179
 
153
180
  ```ruby
data/bin/kelbim CHANGED
@@ -36,7 +36,8 @@ ARGV.options do |opt|
36
36
  opt.on('-r', '--region REGION') {|v| region = v }
37
37
  opt.on('-a', '--apply') { mode = :apply }
38
38
  opt.on('-f', '--file FILE') {|v| file = v }
39
- opt.on('-n', '--elb-names NAMES', Array) {|v| options[:elb_names] = v }
39
+ opt.on('-n', '--elb-name REGEXP') {|v| options[:elb_name] = Regexp.new(v) }
40
+ opt.on('', '--exclude-elb-name REGEXP') {|v| options[:exclude_elb_name] = Regexp.new(v) }
40
41
  opt.on('', '--dry-run') { options[:dry_run] = true }
41
42
  opt.on('', '--ec2s VPC_IDS', Array) {|v| options[:ec2s] = v }
42
43
  opt.on('', '--without-deleting-policy') { options[:without_deleting_policy] = true }
data/lib/kelbim/client.rb CHANGED
@@ -1,16 +1,7 @@
1
- require 'aws-sdk-v1'
2
- require 'kelbim/dsl'
3
- require 'kelbim/exporter'
4
- require 'kelbim/ext/ec2-ext'
5
- require 'kelbim/ext/elb-load-balancer-ext'
6
- require 'kelbim/policy-types'
7
- require 'kelbim/tester'
8
- require 'kelbim/wrapper/elb-wrapper'
9
- require 'kelbim/logger'
10
-
11
1
  module Kelbim
12
2
  class Client
13
3
  include Logger::ClientHelper
4
+ include Kelbim::Utils::Helper
14
5
 
15
6
  def initialize(options = {})
16
7
  @options = OpenStruct.new(options)
@@ -147,11 +138,7 @@ module Kelbim
147
138
 
148
139
  lb_list_dsl.each do |key, lb_dsl|
149
140
  name = key[0]
150
-
151
- if @options.elb_names
152
- next unless @options.elb_names.include?(name)
153
- end
154
-
141
+ next unless matched_elb?(name)
155
142
  lb_aws = lb_list_aws[key]
156
143
 
157
144
  unless lb_aws
@@ -162,11 +149,7 @@ module Kelbim
162
149
 
163
150
  lb_list_dsl.each do |key, lb_dsl|
164
151
  name = key[0]
165
-
166
- if @options.elb_names
167
- next unless @options.elb_names.include?(name)
168
- end
169
-
152
+ next unless matched_elb?(name)
170
153
  log(:info, "Comparing #{vpc || :classic} > #{name}", :intense_black)
171
154
 
172
155
  lb_aws = lb_list_aws.delete(key)
@@ -175,11 +158,7 @@ module Kelbim
175
158
 
176
159
  lb_list_aws.each do |key, lb_aws|
177
160
  name = key[0]
178
-
179
- if @options.elb_names
180
- next unless @options.elb_names.include?(name)
181
- end
182
-
161
+ next unless matched_elb?(name)
183
162
  lb_aws.delete
184
163
  end
185
164
  end
@@ -264,7 +243,7 @@ module Kelbim
264
243
  end
265
244
 
266
245
  if orig_policy_names.sort != new_policies.map {|i| i.name }.sort
267
- listener.policies = new_policies
246
+ listener.update_policies(new_policies, old_policies)
268
247
  end
269
248
 
270
249
  if not old_policies.empty? and not @options.without_deleting_policy
@@ -1,15 +1,14 @@
1
- require 'ostruct'
2
- require 'kelbim/dsl/checker'
3
-
4
1
  module Kelbim
5
2
  class DSL
6
3
  class EC2
7
4
  class LoadBalancer
8
5
  class Attributes
9
6
  include Checker
7
+ include Kelbim::TemplateHelper
10
8
 
11
- def initialize(load_balancer, &block)
9
+ def initialize(context, load_balancer, &block)
12
10
  @error_identifier = "LoadBalancer `#{load_balancer}`"
11
+ @context = context.dup
13
12
  @result = {}
14
13
  instance_eval(&block)
15
14
  end
@@ -1,5 +1,3 @@
1
- require 'kelbim/policy-types'
2
-
3
1
  module Kelbim
4
2
  class DSL
5
3
  class Converter
@@ -1,14 +1,13 @@
1
- require 'ostruct'
2
- require 'set'
3
- require 'kelbim/dsl/load-balancer'
4
-
5
1
  module Kelbim
6
2
  class DSL
7
3
  class EC2
4
+ include Kelbim::TemplateHelper
5
+
8
6
  attr_reader :result
9
7
 
10
- def initialize(vpc, load_balancers, &block)
8
+ def initialize(context, vpc, load_balancers, &block)
11
9
  @error_identifier = "EC2 `#{vpc || :classic}`"
10
+ @context = context.merge(:vpc => vpc)
12
11
 
13
12
  @result = OpenStruct.new({
14
13
  :vpc => vpc,
@@ -29,7 +28,7 @@ module Kelbim
29
28
  raise "LoadBalancer `#{name}`: Invalid option keys: #{invalid_keys}"
30
29
  end
31
30
 
32
- @result.load_balancers << LoadBalancer.new(name, @result.vpc, opts[:internal], &block).result
31
+ @result.load_balancers << LoadBalancer.new(@context, name, @result.vpc, opts[:internal], &block).result
33
32
  @names << name
34
33
  end
35
34
  end # EC2
@@ -1,15 +1,14 @@
1
- require 'ostruct'
2
- require 'kelbim/dsl/checker'
3
-
4
1
  module Kelbim
5
2
  class DSL
6
3
  class EC2
7
4
  class LoadBalancer
8
5
  class HealthCheck
9
6
  include Checker
7
+ include Kelbim::TemplateHelper
10
8
 
11
- def initialize(load_balancer, &block)
9
+ def initialize(context, load_balancer, &block)
12
10
  @error_identifier = "LoadBalancer `#{load_balancer}`"
11
+ @context = context.dup
13
12
  @result = {}
14
13
  instance_eval(&block)
15
14
  end
@@ -1,7 +1,3 @@
1
- require 'ostruct'
2
- require 'kelbim/dsl/checker'
3
- require 'kelbim/policy-types'
4
-
5
1
  module Kelbim
6
2
  class DSL
7
3
  class EC2
@@ -9,9 +5,11 @@ module Kelbim
9
5
  class Listeners
10
6
  class Listener
11
7
  include Checker
8
+ include Kelbim::TemplateHelper
12
9
 
13
- def initialize(load_balancer, protocol_prots, &block)
14
- @error_identifier = "LoadBalancer `#{load_balancer}`: #{protocol_prots}"
10
+ def initialize(context, load_balancer, protocol_ports, &block)
11
+ @error_identifier = "LoadBalancer `#{load_balancer}`: #{protocol_ports}"
12
+ @context = context.merge(:protocol_ports => protocol_ports)
15
13
 
16
14
  @result = OpenStruct.new({
17
15
  :policies => []
@@ -32,7 +30,7 @@ module Kelbim
32
30
  expected_type(value, Hash)
33
31
 
34
32
  unless value.kind_of?(Hash)
35
- raise "LoadBalancer `#{@load_balancer}`: #{@protocol_prots}: Invalid policies: #{value}"
33
+ raise "LoadBalancer `#{@load_balancer}`: #{@protocol_ports}: Invalid policies: #{value}"
36
34
  end
37
35
 
38
36
  value = value.map do |policy, name_or_attrs|
@@ -1,16 +1,14 @@
1
- require 'ostruct'
2
- require 'kelbim/dsl/checker'
3
- require 'kelbim/dsl/listener'
4
-
5
1
  module Kelbim
6
2
  class DSL
7
3
  class EC2
8
4
  class LoadBalancer
9
5
  class Listeners
10
6
  include Checker
7
+ include Kelbim::TemplateHelper
11
8
 
12
- def initialize(load_balancer, &block)
9
+ def initialize(context, load_balancer, &block)
13
10
  @error_identifier = "LoadBalancer `#{load_balancer}`"
11
+ @context = context.dup
14
12
  @result = {}
15
13
  instance_eval(&block)
16
14
  end
@@ -47,7 +45,7 @@ module Kelbim
47
45
  expected_type(port, Integer)
48
46
  end
49
47
 
50
- @result[protocol_ports] = Listener.new(@load_balancer, protocol_ports, &block).result
48
+ @result[protocol_ports] = Listener.new(@context, @load_balancer, protocol_ports, &block).result
51
49
  end
52
50
  end # Listeners
53
51
  end # LoadBalancer
@@ -1,19 +1,15 @@
1
- require 'ostruct'
2
- require 'kelbim/dsl/checker'
3
- require 'kelbim/dsl/health-check'
4
- require 'kelbim/dsl/attributes'
5
- require 'kelbim/dsl/listeners'
6
-
7
1
  module Kelbim
8
2
  class DSL
9
3
  class EC2
10
4
  class LoadBalancer
11
5
  include Checker
6
+ include Kelbim::TemplateHelper
12
7
 
13
- def initialize(name, vpc, internal, &block)
8
+ def initialize(context, name, vpc, internal, &block)
14
9
  @name = name
15
10
  @vpc = vpc
16
11
  @error_identifier = "LoadBalancer `#{name}`"
12
+ @context = context.merge(:load_balancer_name => name)
17
13
 
18
14
  @result = OpenStruct.new({
19
15
  :name => name,
@@ -57,17 +53,17 @@ module Kelbim
57
53
 
58
54
  def listeners(&block)
59
55
  call_once(:listeners)
60
- @result.listeners = Listeners.new(@name, &block).result
56
+ @result.listeners = Listeners.new(@context, @name, &block).result
61
57
  end
62
58
 
63
59
  def health_check(&block)
64
60
  call_once(:health_check)
65
- @result.health_check = HealthCheck.new(@name, &block).result
61
+ @result.health_check = HealthCheck.new(@context, @name, &block).result
66
62
  end
67
63
 
68
64
  def attributes(&block)
69
65
  call_once(:attributes)
70
- @result.attributes = Attributes.new(@name, &block).result
66
+ @result.attributes = Attributes.new(@context, @name, &block).result
71
67
  end
72
68
 
73
69
  def subnets(*values)
data/lib/kelbim/dsl.rb CHANGED
@@ -1,9 +1,7 @@
1
- require 'ostruct'
2
- require 'kelbim/dsl/converter'
3
- require 'kelbim/dsl/ec2'
4
-
5
1
  module Kelbim
6
2
  class DSL
3
+ include Kelbim::TemplateHelper
4
+
7
5
  class << self
8
6
  def define(source, path)
9
7
  self.new(path) do
@@ -21,27 +19,38 @@ module Kelbim
21
19
  def initialize(path, &block)
22
20
  @path = path
23
21
  @result = OpenStruct.new(:ec2s => {})
22
+
23
+ @context = Hashie::Mash.new(
24
+ :path => path,
25
+ :templates => {}
26
+ )
27
+
24
28
  instance_eval(&block)
25
29
  end
26
30
 
27
31
  private
32
+
28
33
  def require(file)
29
- balancerfile = File.expand_path(File.join(File.dirname(@path), file))
34
+ balancerfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))
30
35
 
31
36
  if File.exist?(balancerfile)
32
- instance_eval(File.read(balancerfile))
37
+ instance_eval(File.read(balancerfile), balancerfile)
33
38
  elsif File.exist?(balancerfile + '.rb')
34
- instance_eval(File.read(balancerfile + '.rb'))
39
+ instance_eval(File.read(balancerfile + '.rb'), balancerfile + '.rb')
35
40
  else
36
41
  Kernel.require(file)
37
42
  end
38
43
  end
39
44
 
45
+ def template(name, &block)
46
+ @context.templates[name.to_s] = block
47
+ end
48
+
40
49
  def ec2(vpc = nil, &block)
41
50
  if (ec2_result = @result.ec2s[vpc])
42
- @result.ec2s[vpc] = EC2.new(vpc, ec2_result.load_balancers, &block).result
51
+ @result.ec2s[vpc] = EC2.new(@context, vpc, ec2_result.load_balancers, &block).result
43
52
  else
44
- @result.ec2s[vpc] = EC2.new(vpc, [], &block).result
53
+ @result.ec2s[vpc] = EC2.new(@context, vpc, [], &block).result
45
54
  end
46
55
  end
47
56
  end # DSL
@@ -1,8 +1,7 @@
1
- require 'kelbim/ext/elb-load-balancer-ext'
2
- require 'kelbim/ext/elb-listener-ext'
3
-
4
1
  module Kelbim
5
2
  class Exporter
3
+ include Kelbim::Utils::Helper
4
+
6
5
  class << self
7
6
  def export(elb, options = {})
8
7
  self.new(elb, options).export
@@ -19,12 +18,11 @@ module Kelbim
19
18
  lbs = @elb.load_balancers
20
19
 
21
20
  ec2s = @options[:ec2s]
22
- elb_names = @options[:elb_names]
23
21
 
24
- if ec2s or elb_names
22
+ if ec2s or @options[:elb_name] or @options[:exclude_elb_name]
25
23
  lbs = lbs.select do |lb|
26
24
  (ec2s.nil? or ec2s.include?(lb.vpc_id || 'classic')) &&
27
- (elb_names.nil? or elb_names.include?(lb.name))
25
+ matched_elb?(lb.name)
28
26
  end
29
27
  end
30
28
 
data/lib/kelbim/logger.rb CHANGED
@@ -1,7 +1,3 @@
1
- require 'logger'
2
- require 'singleton'
3
- require 'kelbim/ext/string-ext'
4
-
5
1
  module Kelbim
6
2
  class Logger < ::Logger
7
3
  include Singleton
@@ -26,7 +22,8 @@ module Kelbim
26
22
  message << ": #{log_id}" if log_id
27
23
  message << ' (dry-run)' if @options && @options.dry_run
28
24
  logger = (@options && @options.logger) || Kelbim::Logger.instance
29
- logger.send(level, message.send(color))
25
+ message = message.send(color) if color
26
+ logger.send(level, message)
30
27
  end
31
28
  end # ClientHelper
32
29
  end # Logger
@@ -1,6 +1,3 @@
1
- require 'rspec'
2
- require 'rspec/core/formatters/progress_formatter'
3
-
4
1
  module Kelbim
5
2
  class RSpecFormatter < RSpec::Core::Formatters::ProgressFormatter
6
3
  def dump_failure_info(example)
@@ -0,0 +1,20 @@
1
+ module Kelbim
2
+ module TemplateHelper
3
+ def include_template(template_name, context = {})
4
+ tmplt = @context.templates[template_name.to_s]
5
+
6
+ unless tmplt
7
+ raise "Template `#{template_name}` is not defined"
8
+ end
9
+
10
+ context_orig = @context
11
+ @context = @context.merge(context)
12
+ instance_eval(&tmplt)
13
+ @context = context_orig
14
+ end
15
+
16
+ def context
17
+ @context
18
+ end
19
+ end
20
+ end
data/lib/kelbim/tester.rb CHANGED
@@ -1,9 +1,3 @@
1
- require 'rspec'
2
- require 'net/http'
3
- require 'socket'
4
- require 'timeout'
5
- require 'kelbim/logger'
6
-
7
1
  module Kelbim
8
2
  class Tester
9
3
  class << self
@@ -0,0 +1,33 @@
1
+ module Kelbim
2
+ class Utils
3
+ module Helper
4
+ def matched_elb?(name)
5
+ result = true
6
+
7
+ if @options[:exclude_elb_name]
8
+ result &&= name !~ @options[:exclude_elb_name]
9
+ end
10
+
11
+ if @options[:elb_name]
12
+ result &&= name =~ @options[:elb_name]
13
+ end
14
+
15
+ result
16
+ end
17
+ end # Helper
18
+
19
+ class << self
20
+ def diff(obj1, obj2, options = {})
21
+ diffy = Diffy::Diff.new(
22
+ obj1.pretty_inspect,
23
+ obj2.pretty_inspect,
24
+ :diff => '-u'
25
+ )
26
+
27
+ out = diffy.to_s(options[:color] ? :color : :text).gsub(/\s+\z/m, '')
28
+ out.gsub!(/^/, options[:indent]) if options[:indent]
29
+ out
30
+ end
31
+ end # of class methods
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Kelbim
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0.beta"
3
3
  end
4
4
 
5
5
  Version = Kelbim::VERSION
@@ -1,6 +1,3 @@
1
- require 'kelbim/wrapper/load-balancer-collection'
2
- require 'kelbim/ext/ec2-ext'
3
-
4
1
  module Kelbim
5
2
  class ELBWrapper
6
3
  def initialize(elb, options)
@@ -1,8 +1,3 @@
1
- require 'ostruct'
2
- require 'kelbim/wrapper/listener'
3
- require 'kelbim/wrapper/policy-collection'
4
- require 'kelbim/logger'
5
-
6
1
  module Kelbim
7
2
  class ELBWrapper
8
3
  class LoadBalancerCollection
@@ -1,8 +1,3 @@
1
- require 'forwardable'
2
- require 'kelbim/ext/elb-listener-ext'
3
- require 'kelbim/wrapper/policy-collection'
4
- require 'kelbim/logger'
5
-
6
1
  module Kelbim
7
2
  class ELBWrapper
8
3
  class LoadBalancerCollection
@@ -32,8 +27,9 @@ module Kelbim
32
27
  def update(dsl)
33
28
  log(:info, 'Update Listener', :green, log_id)
34
29
 
35
- compare_server_certificate(dsl) do
36
- log(:info, " set server_certificate=#{dsl.server_certificate}", :green)
30
+ compare_server_certificate(dsl) do |old_data, new_data|
31
+ log(:info, " server_certificate:", :green)
32
+ log(:info, Kelbim::Utils.diff(old_data, new_data, :color => @options[:color], :indent => ' '), false)
37
33
 
38
34
  unless @options.dry_run
39
35
  ss = @options.iam.server_certificates[dsl.server_certificate]
@@ -48,9 +44,11 @@ module Kelbim
48
44
  end
49
45
  end
50
46
 
51
- def policies=(policy_list)
47
+ def update_policies(policy_list, old_policy_list)
48
+ old_data = old_policy_list.map {|i| i.name }.sort
49
+ new_data = policy_list.map {|i| i.name }.sort
52
50
  log(:info, 'Update Listener Policies', :green, log_id)
53
- log(:info, ' set policies=' + policy_list.map {|i| i.name }.join(', '), :green)
51
+ log(:info, Kelbim::Utils.diff(old_data, new_data, :color => @options[:color], :indent => ' '), false)
54
52
 
55
53
  unless @options.dry_run
56
54
  @options.elb.client.set_load_balancer_policies_of_listener({
@@ -99,7 +97,7 @@ module Kelbim
99
97
  aws_server_certificate = @listener.server_certificate
100
98
  aws_server_certificate = aws_server_certificate.name if aws_server_certificate
101
99
  same = (aws_server_certificate == dsl.server_certificate)
102
- yield if !same && block_given?
100
+ yield(aws_server_certificate, dsl.server_certificate) if !same && block_given?
103
101
  return same
104
102
  end
105
103
  end # Listener
@@ -1,8 +1,3 @@
1
- require 'ostruct'
2
- require 'kelbim/wrapper/load-balancer'
3
- require 'kelbim/wrapper/listener-collection'
4
- require 'kelbim/logger'
5
-
6
1
  module Kelbim
7
2
  class ELBWrapper
8
3
  class LoadBalancerCollection
@@ -1,7 +1,3 @@
1
- require 'forwardable'
2
- require 'kelbim/wrapper/listener-collection'
3
- require 'kelbim/logger'
4
-
5
1
  module Kelbim
6
2
  class ELBWrapper
7
3
  class LoadBalancerCollection
@@ -69,8 +65,9 @@ module Kelbim
69
65
  end
70
66
  end
71
67
 
72
- compare_health_check(dsl) do
73
- log(:info, ' set health_check=' + dsl.health_check.inspect, :green)
68
+ compare_health_check(dsl) do |old_data, new_data|
69
+ log(:info, ' health_check:', :green)
70
+ log(:info, Kelbim::Utils.diff(old_data, new_data, :color => @options[:color], :indent => ' '), false)
74
71
 
75
72
  unless @options.dry_run
76
73
  @load_balancer.configure_health_check(dsl.health_check)
@@ -78,8 +75,9 @@ module Kelbim
78
75
  end
79
76
  end
80
77
 
81
- compare_attributes(dsl) do
82
- log(:info, ' set attributes=' + dsl.attributes.inspect, :green)
78
+ compare_attributes(dsl) do |old_data, new_data|
79
+ log(:info, ' attributes:', :green)
80
+ log(:info, Kelbim::Utils.diff(old_data, new_data, :color => @options[:color], :indent => ' '), false)
83
81
 
84
82
  unless @options.dry_run
85
83
  @load_balancer.attributes = dsl.attributes
@@ -120,9 +118,12 @@ module Kelbim
120
118
  end
121
119
  end
122
120
 
123
- compare_security_groups(dsl) do |dsl_sg_ids|
121
+ compare_security_groups(dsl) do |aws_sg_ids, dsl_sg_ids|
124
122
  sg_names = @options.security_group_names[self.vpc_id] || {}
125
- log(:info, ' apply security groups=' + dsl_sg_ids.map {|i| sg_names.fetch(i, i) }.join(', '), :green)
123
+ old_data = aws_sg_ids.map {|i| sg_names.fetch(i, i) }.sort
124
+ new_data = dsl_sg_ids.map {|i| sg_names.fetch(i, i) }.sort
125
+ log(:info, ' security groups:', :green)
126
+ log(:info, Kelbim::Utils.diff(old_data, new_data, :color => @options[:color], :indent => ' '), false)
126
127
 
127
128
  unless @options.dry_run
128
129
  @options.elb.client.apply_security_groups_to_load_balancer(
@@ -183,8 +184,10 @@ module Kelbim
183
184
  end
184
185
 
185
186
  def compare_health_check(dsl)
186
- same = (@load_balancer.health_check.sort == dsl.health_check.sort)
187
- yield if !same && block_given?
187
+ old_data = @load_balancer.health_check.sort
188
+ new_data = dsl.health_check.sort
189
+ same = (old_data == new_data)
190
+ yield(old_data, new_data) if !same && block_given?
188
191
  return same
189
192
  end
190
193
 
@@ -198,8 +201,10 @@ module Kelbim
198
201
  lb_attributes[key] = @load_balancer.attributes[key]
199
202
  end
200
203
 
201
- same = (lb_attributes.sort == dsl.attributes.sort)
202
- yield if !same && block_given?
204
+ old_data = lb_attributes.sort
205
+ new_data = dsl.attributes.sort
206
+ same = (old_data == new_data)
207
+ yield(lb_attributes, dsl.attributes) if !same && block_given?
203
208
  return same
204
209
  end
205
210
 
@@ -219,7 +224,7 @@ module Kelbim
219
224
  }.sort
220
225
 
221
226
  same = (aws_sg_ids == dsl_sg_ids)
222
- yield(dsl_sg_ids) if !same && block_given?
227
+ yield(aws_sg_ids, dsl_sg_ids) if !same && block_given?
223
228
  return same
224
229
  end
225
230
 
@@ -1,9 +1,3 @@
1
- require 'ostruct'
2
- require 'kelbim/wrapper/policy'
3
- require 'kelbim/policy-types'
4
- require 'kelbim/logger'
5
- require 'uuid'
6
-
7
1
  module Kelbim
8
2
  class ELBWrapper
9
3
  class LoadBalancerCollection
@@ -1,7 +1,3 @@
1
- require 'forwardable'
2
- require 'kelbim/policy-types'
3
- require 'kelbim/logger'
4
-
5
1
  module Kelbim
6
2
  class ELBWrapper
7
3
  class LoadBalancerCollection
@@ -38,8 +34,16 @@ module Kelbim
38
34
  log(:info, 'Delete Policy', :red, "#{@listener.log_id} > #{self.name}")
39
35
 
40
36
  unless @options.dry_run
41
- @policy.delete
42
- @options.updated = true
37
+ begin
38
+ @policy.delete
39
+ @options.updated = true
40
+ rescue AWS::ELB::Errors::InvalidConfigurationRequest => e
41
+ if e.message =~ /You cannot delete policy/
42
+ # nothing to do
43
+ else
44
+ raise e
45
+ end
46
+ end
43
47
  end
44
48
  end
45
49
  end # Policy
data/lib/kelbim.rb CHANGED
@@ -1,2 +1,48 @@
1
- require 'kelbim/version'
1
+ require 'forwardable'
2
+ require 'logger'
3
+ require 'net/http'
4
+ require 'ostruct'
5
+ require 'pp'
6
+ require 'set'
7
+ require 'singleton'
8
+ require 'socket'
9
+ require 'timeout'
10
+
11
+ require 'aws-sdk-v1'
12
+ require 'diffy'
13
+ require 'rspec'
14
+ require 'rspec/core/formatters/progress_formatter'
15
+ require 'term/ansicolor'
16
+ require 'uuid'
17
+ require 'hashie'
18
+
19
+ require 'kelbim/ext/string-ext'
20
+ require 'kelbim/ext/ec2-ext'
21
+ require 'kelbim/ext/elb-listener-ext'
22
+ require 'kelbim/ext/elb-load-balancer-ext'
23
+
24
+ require 'kelbim/logger'
25
+ require 'kelbim/utils'
26
+ require 'kelbim/policy-types'
27
+ require 'kelbim/dsl/checker'
28
+ require 'kelbim/template_helper'
29
+
2
30
  require 'kelbim/client'
31
+ require 'kelbim/dsl'
32
+ require 'kelbim/dsl/attributes'
33
+ require 'kelbim/dsl/converter'
34
+ require 'kelbim/dsl/ec2'
35
+ require 'kelbim/dsl/health-check'
36
+ require 'kelbim/dsl/listener'
37
+ require 'kelbim/dsl/listeners'
38
+ require 'kelbim/dsl/load-balancer'
39
+ require 'kelbim/exporter'
40
+ require 'kelbim/tester'
41
+ require 'kelbim/version'
42
+ require 'kelbim/wrapper/elb-wrapper'
43
+ require 'kelbim/wrapper/listener'
44
+ require 'kelbim/wrapper/listener-collection'
45
+ require 'kelbim/wrapper/load-balancer'
46
+ require 'kelbim/wrapper/load-balancer-collection'
47
+ require 'kelbim/wrapper/policy'
48
+ require 'kelbim/wrapper/policy-collection'
metadata CHANGED
@@ -1,125 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelbim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.59.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.59.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: uuid
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.14.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.14.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: term-ansicolor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: diffy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hashie
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: bundler
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ~>
88
116
  - !ruby/object:Gem::Version
89
117
  version: '1.3'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - "~>"
122
+ - - ~>
95
123
  - !ruby/object:Gem::Version
96
124
  version: '1.3'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: rake
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - ">="
129
+ - - '>='
102
130
  - !ruby/object:Gem::Version
103
131
  version: '0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - ">="
136
+ - - '>='
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: rspec-instafail
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - ">="
143
+ - - '>='
116
144
  - !ruby/object:Gem::Version
117
145
  version: '0'
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - ">="
150
+ - - '>='
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
153
  description: Kelbim is a tool to manage ELB. It defines the state of ELB using DSL,
@@ -152,7 +180,9 @@ files:
152
180
  - lib/kelbim/logger.rb
153
181
  - lib/kelbim/policy-types.rb
154
182
  - lib/kelbim/rspec-formatter.rb
183
+ - lib/kelbim/template_helper.rb
155
184
  - lib/kelbim/tester.rb
185
+ - lib/kelbim/utils.rb
156
186
  - lib/kelbim/version.rb
157
187
  - lib/kelbim/wrapper/elb-wrapper.rb
158
188
  - lib/kelbim/wrapper/listener-collection.rb
@@ -171,17 +201,17 @@ require_paths:
171
201
  - lib
172
202
  required_ruby_version: !ruby/object:Gem::Requirement
173
203
  requirements:
174
- - - ">="
204
+ - - '>='
175
205
  - !ruby/object:Gem::Version
176
206
  version: '0'
177
207
  required_rubygems_version: !ruby/object:Gem::Requirement
178
208
  requirements:
179
- - - ">="
209
+ - - '>'
180
210
  - !ruby/object:Gem::Version
181
- version: '0'
211
+ version: 1.3.1
182
212
  requirements: []
183
213
  rubyforge_project:
184
- rubygems_version: 2.4.5
214
+ rubygems_version: 2.4.8
185
215
  signing_key:
186
216
  specification_version: 4
187
217
  summary: Kelbim is a tool to manage ELB.