kelbim 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWNlZWFhMDllMjU2ZjBjMGMzNWQ0ZjliMDdlODY1MmVjMDVmY2JhZA==
5
- data.tar.gz: !binary |-
6
- YTkzNTdjZjk4NzIzMDg0YTdhMGUzOTVmNjZlYzhlMmM0NDk0ZmM5ZA==
2
+ SHA1:
3
+ metadata.gz: 9bbb3197d476ccd10329c48a3edff97441e40f9f
4
+ data.tar.gz: dc3d13a4887646050d975d9cf27b266d2a048e22
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZGM5MzBhOGQ0ZDFmMjUyOTVkMTBkZjJmMjcwMmY3NTY2MGZiM2IwNGJmZTYx
10
- OWMxMjczYjlmNzgwYjI3NWQ2OTY0ZDY3YTk1MDVlMjZlYjVjNGY5N2YzYzFj
11
- Mzg5ZDcyOGE1MDk4NzMxNTMwMWRmMmE3ODA3YjQzYWIyZWJiYmU=
12
- data.tar.gz: !binary |-
13
- YzU1M2I2ZDMwYWMyZjExMTViYjliMmIzYWQ2NjUyOWNhYTZkNzg4ZWZlYzRi
14
- NTdlZjllYzQ4NzRmMTkxYzg2NTZmMmM1ZWY4ZTIwMDc0ZWY3NjA2ZTA3MTk2
15
- MzE4ZjQwNDQxMjMxZTlhMGJlMGZkNzIzN2NiOTI3MDZmZjk5MWU=
6
+ metadata.gz: f3a19d3148899e4d0776081456311d5f26be4c669ade5b6a0278c4ec4ab484d9baf5aeb5cbfa912bc7be41cb651b9bd742f03c1a71827c783df452ab0ec44bbb
7
+ data.tar.gz: 0eec8ae9e258df9d86cb51e4a1102bb4912cb9d44359110e5b91b21e0fa955bc8c41b6b6009ccbfd780b51ced7f62fce681f0dcf4cc151f38d58b2ffaf50c971
data/README.md CHANGED
@@ -65,6 +65,10 @@ ec2 do
65
65
  unhealthy_threshold 2
66
66
  end
67
67
 
68
+ attributes do
69
+ cross_zone_load_balancing :enabled => false
70
+ end
71
+
68
72
  availability_zones(
69
73
  "ap-northeast-1a",
70
74
  "ap-northeast-1b"
@@ -97,6 +101,10 @@ ec2 "vpc-XXXXXXXXX" do
97
101
  unhealthy_threshold 2
98
102
  end
99
103
 
104
+ attributes do
105
+ cross_zone_load_balancing :enabled => true
106
+ end
107
+
100
108
  subnets(
101
109
  "subnet-XXXXXXXX"
102
110
  )
@@ -114,14 +122,9 @@ end
114
122
  ec2 "vpc-XXXXXXXXX" do
115
123
  load_balancer "my-load-balancer" do
116
124
  spec do
117
- host = "my-load-balancer-XXXXXXXXXX.ap-northeast-1.elb.amazonaws.com"
118
-
119
- expect {
120
- timeout(3) do
121
- socket = TCPSocket.open(host, 8080)
122
- socket.close if socket
123
- end
124
- }.not_to raise_error
125
+ url = URI.parse('http://www.example.com/')
126
+ res = Net::HTTP.start(url.host, url.port) {|http| http.get(url.path) }
127
+ expect(res).to be_a(Net::HTTPOK)
125
128
  end
126
129
  ...
127
130
  ```
@@ -0,0 +1,32 @@
1
+ require 'ostruct'
2
+ require 'kelbim/dsl/checker'
3
+
4
+ module Kelbim
5
+ class DSL
6
+ class EC2
7
+ class LoadBalancer
8
+ class Attributes
9
+ include Checker
10
+
11
+ def initialize(load_balancer, &block)
12
+ @error_identifier = "LoadBalancer `#{load_balancer}`"
13
+ @result = {}
14
+ instance_eval(&block)
15
+ end
16
+
17
+ def result
18
+ required(:cross_zone_load_balancing, @result[:cross_zone_load_balancing])
19
+ @result
20
+ end
21
+
22
+ def cross_zone_load_balancing(value)
23
+ call_once(:cross_zone_load_balancing)
24
+ expected_type(value, Hash)
25
+ expected_length(value, 1)
26
+ @result[:cross_zone_load_balancing] = value
27
+ end
28
+ end # Attributes
29
+ end # LoadBalancer
30
+ end # EC2
31
+ end # DSL
32
+ end # Kelbim
@@ -41,6 +41,7 @@ end
41
41
  instances = output_instances(load_balancer[:instances], vpc).strip
42
42
  listeners = output_listeners(load_balancer[:listeners]).strip
43
43
  health_check = output_health_check(load_balancer[:health_check]).strip
44
+ attributes = output_attributes(load_balancer[:attributes]).strip
44
45
  testcase = is_internal ? '' : ("\n " + output_testcase(load_balancer[:dns_name]).strip + "\n")
45
46
 
46
47
  out = <<-EOS
@@ -51,6 +52,8 @@ end
51
52
  #{listeners}
52
53
 
53
54
  #{health_check}
55
+
56
+ #{attributes}
54
57
  EOS
55
58
 
56
59
  if vpc
@@ -178,6 +181,17 @@ end
178
181
  interval #{interval}
179
182
  healthy_threshold #{healthy_threshold}
180
183
  unhealthy_threshold #{unhealthy_threshold}
184
+ end
185
+ EOS
186
+ end
187
+
188
+ def output_attributes(attributes)
189
+ cross_zone_load_balancing = attributes[:cross_zone_load_balancing].inspect
190
+ cross_zone_load_balancing.sub!(/\A\s*{\s*/, '').sub!(/\s*}\s*\Z/, '')
191
+
192
+ <<-EOS
193
+ attributes do
194
+ cross_zone_load_balancing #{cross_zone_load_balancing}
181
195
  end
182
196
  EOS
183
197
  end
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'kelbim/dsl/checker'
3
3
  require 'kelbim/dsl/health-check'
4
+ require 'kelbim/dsl/attributes'
4
5
  require 'kelbim/dsl/listeners'
5
6
 
6
7
  module Kelbim
@@ -27,6 +28,7 @@ module Kelbim
27
28
  def result
28
29
  required(:listeners, @result.listeners)
29
30
  required(:health_check, @result.health_check)
31
+ #required(:attributes, @result.attributes)
30
32
 
31
33
  if @vpc
32
34
  required(:subnets, @result.subnets)
@@ -63,6 +65,11 @@ module Kelbim
63
65
  @result.health_check = HealthCheck.new(@name, &block).result
64
66
  end
65
67
 
68
+ def attributes(&block)
69
+ call_once(:attributes)
70
+ @result.attributes = Attributes.new(@name, &block).result
71
+ end
72
+
66
73
  def subnets(*values)
67
74
  call_once(:subnets)
68
75
  raise "#{@error_identifier}: Subnet cannot be specified in EC2-Classic" unless @vpc
@@ -33,6 +33,7 @@ module Kelbim
33
33
  :health_check => load_balancer.health_check,
34
34
  :scheme => load_balancer.scheme,
35
35
  :dns_name => load_balancer.dns_name,
36
+ :attributes => load_balancer.attributes,
36
37
  }
37
38
 
38
39
  if @fetch_policies and load_balancer.policies.first
@@ -0,0 +1,43 @@
1
+ require 'aws-sdk'
2
+
3
+ proc {
4
+ define_client_method = proc do |operation|
5
+ operation[:outputs] ||= {}
6
+ builder = AWS::Core::QueryRequestBuilder.new('2012-06-01', operation)
7
+ parser = AWS::Core::QueryResponseParser.new(operation[:outputs])
8
+ AWS::ELB::Client::V20120601.send(:define_client_method, operation[:method], builder, parser)
9
+ end
10
+
11
+ define_client_method.call({
12
+ :name => 'DescribeLoadBalancerAttributes',
13
+ :method => :describe_load_balancer_attributes,
14
+ :inputs => {'LoadBalancerName' => [:string, :required]},
15
+ :outputs => {
16
+ :children => {
17
+ 'ResponseMetadata' => {
18
+ :ignore => true,
19
+ :children => {'RequestId' => {:ignore => true}}},
20
+ 'DescribeLoadBalancerAttributesResult' => {
21
+ :ignore => true,
22
+ :children => {
23
+ 'LoadBalancerAttributes' => {
24
+ :ignore => true,
25
+ :children => {
26
+ 'CrossZoneLoadBalancing' => {
27
+ :children => {
28
+ 'Enabled' => {:type => :boolean}}}}}}}}}
29
+ })
30
+
31
+ define_client_method.call({
32
+ :name => 'ModifyLoadBalancerAttributes',
33
+ :method => :modify_load_balancer_attributes,
34
+ :inputs => {
35
+ 'LoadBalancerName' => [:string, :required],
36
+ 'LoadBalancerAttributes' => [{
37
+ :structure => {
38
+ 'CrossZoneLoadBalancing' => [{
39
+ :structure => {'Enabled' => [:boolean]}}]}},
40
+ :required]
41
+ },
42
+ })
43
+ }.call
@@ -10,6 +10,29 @@ module AWS
10
10
  lb[:load_balancer_name] == name
11
11
  end
12
12
  end
13
+
14
+ def attributes
15
+ unless @attributes
16
+ credentials = AWS.config.credential_provider.credentials
17
+ elb = AWS::ELB.new(credentials)
18
+ @attributes = elb.client.describe_load_balancer_attributes(
19
+ :load_balancer_name => self.name).data
20
+ end
21
+
22
+ return @attributes.dup
23
+ end
24
+
25
+ def attributes=(attrs)
26
+ credentials = AWS.config.credential_provider.credentials
27
+ elb = AWS::ELB.new(credentials)
28
+
29
+ elb.client.modify_load_balancer_attributes({
30
+ :load_balancer_name => self.name,
31
+ :load_balancer_attributes => attrs,
32
+ })
33
+
34
+ (@attributes = attrs).dup
35
+ end
13
36
  end # LoadBalancer
14
37
  end # ELB
15
38
  end # AWS
@@ -1,5 +1,5 @@
1
1
  module Kelbim
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
4
4
 
5
5
  Version = Kelbim::VERSION
@@ -32,6 +32,7 @@ module Kelbim
32
32
  :instances => [], # instancesはLoadBalancerの処理で更新
33
33
  :scheme => dsl.scheme,
34
34
  :health_check => {}, # health_checkはLoadBalancerの処理で更新
35
+ :attributes => {}, # attributesはLoadBalancerの処理で更新
35
36
  })
36
37
 
37
38
  lb.listeners = dsl.listeners.map do |lstnr|
@@ -69,7 +70,7 @@ module Kelbim
69
70
  opts[:availability_zones] = dsl.availability_zones.map {|i| AWS::EC2::AvailabilityZone.new(i) }
70
71
  end
71
72
 
72
- # health_checkはLoadBalancerの処理で更新
73
+ # health_check、attributesはLoadBalancerの処理で更新
73
74
  lb = @load_balancers.create(dsl.name, opts)
74
75
  @options.updated = true
75
76
  end
@@ -28,6 +28,7 @@ module Kelbim
28
28
  end
29
29
 
30
30
  compare_health_check(dsl) or return false
31
+ compare_attributes(dsl) or return false
31
32
 
32
33
  if self.vpc_id
33
34
  compare_subnet_ids(dsl) or return false
@@ -77,6 +78,15 @@ module Kelbim
77
78
  end
78
79
  end
79
80
 
81
+ compare_attributes(dsl) do
82
+ log(:info, ' set attributes=' + dsl.attributes.inspect, :green)
83
+
84
+ unless @options.dry_run
85
+ @load_balancer.attributes = dsl.attributes
86
+ @options.updated = true
87
+ end
88
+ end
89
+
80
90
  if self.vpc_id
81
91
  compare_subnet_ids(dsl) do |aws_subnet_ids, dsl_subnet_ids|
82
92
  add_ids = (dsl_subnet_ids - aws_subnet_ids)
@@ -178,6 +188,13 @@ module Kelbim
178
188
  return same
179
189
  end
180
190
 
191
+ def compare_attributes(dsl)
192
+ return true unless dsl.attributes
193
+ same = (@load_balancer.attributes.sort == dsl.attributes.sort)
194
+ yield if !same && block_given?
195
+ return same
196
+ end
197
+
181
198
  def compare_subnet_ids(dsl)
182
199
  subnet_ids = @load_balancer.subnets.map {|i| i.id }
183
200
  same = (subnet_ids.sort == dsl.subnets.sort )
data/lib/kelbim.rb CHANGED
@@ -1,2 +1,3 @@
1
+ require 'kelbim/ext/elb-load-balancer-attributes-ext'
1
2
  require 'kelbim/version'
2
3
  require 'kelbim/client'
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelbim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.24.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.24.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
@@ -56,28 +56,28 @@ dependencies:
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
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
@@ -98,14 +98,14 @@ dependencies:
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
@@ -134,6 +134,7 @@ files:
134
134
  - README.md
135
135
  - bin/kelbim
136
136
  - lib/kelbim/client.rb
137
+ - lib/kelbim/dsl/attributes.rb
137
138
  - lib/kelbim/dsl/checker.rb
138
139
  - lib/kelbim/dsl/converter.rb
139
140
  - lib/kelbim/dsl/ec2.rb
@@ -145,6 +146,7 @@ files:
145
146
  - lib/kelbim/exporter.rb
146
147
  - lib/kelbim/ext/ec2-ext.rb
147
148
  - lib/kelbim/ext/elb-listener-ext.rb
149
+ - lib/kelbim/ext/elb-load-balancer-attributes-ext.rb
148
150
  - lib/kelbim/ext/elb-load-balancer-ext.rb
149
151
  - lib/kelbim/ext/string-ext.rb
150
152
  - lib/kelbim/logger.rb
@@ -170,17 +172,17 @@ require_paths:
170
172
  - lib
171
173
  required_ruby_version: !ruby/object:Gem::Requirement
172
174
  requirements:
173
- - - ! '>='
175
+ - - '>='
174
176
  - !ruby/object:Gem::Version
175
177
  version: '0'
176
178
  required_rubygems_version: !ruby/object:Gem::Requirement
177
179
  requirements:
178
- - - ! '>='
180
+ - - '>='
179
181
  - !ruby/object:Gem::Version
180
182
  version: '0'
181
183
  requirements: []
182
184
  rubyforge_project:
183
- rubygems_version: 2.1.5
185
+ rubygems_version: 2.1.8
184
186
  signing_key:
185
187
  specification_version: 4
186
188
  summary: Kelbim is a tool to manage ELB.