skyed 0.1.12 → 0.1.13

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: c191f7b0605dc2e8d68779b5cd1eaf2712e43447
4
- data.tar.gz: d1daad8c34f40f89dfd6fc28d9c794465f15b564
3
+ metadata.gz: 252c06eb53f9953de17404e021ee2f3deb44fe4f
4
+ data.tar.gz: 4e920d1b31974964520910e9f71c07eed3f9a8b6
5
5
  SHA512:
6
- metadata.gz: 0ba58d81e95e50e8258abb2ff06a4c775c24eb4b17356939239f94179abf150ac750dc4fac4f97f248fe19030fd310e21c367ad5c0c6e739636eb0c952523a90
7
- data.tar.gz: 792ce1e3b5756bbfae02b31e39111ba7d7cece30f1c65cadef1656ab52c319ccb7d952e259248974a8f51ac1c351c34b496d7f354a8342cbbdba2c177df86e9d
6
+ metadata.gz: 427e9d0a29fb3f1e77f64f76d0e81f415d96600bfb7b85ccba869744d5a9e101acd149658964d9e0762496088fecf2d7c108cd043250a0f3bd3044c81fe2b346
7
+ data.tar.gz: 2a305e4db96e5029f28d35c3a64eb1fdceab0fa572ca30c67f1ce1c96b94de71b1bc250f253693f56fa34ef207d12cc8b51a280d37b86fab1a25cb6a9b34ca11
data/lib/skyed.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'skyed/list'
2
2
  require 'skyed/create'
3
+ require 'skyed/check'
3
4
  require 'skyed/utils'
4
5
  require 'skyed/git'
5
6
  require 'skyed/aws'
@@ -12,5 +13,5 @@ require 'skyed/settings'
12
13
 
13
14
  # Skyed is a set of tools for cloud computing
14
15
  module Skyed
15
- VERSION = '0.1.12'
16
+ VERSION = '0.1.13'
16
17
  end
data/lib/skyed/aws.rb CHANGED
@@ -38,6 +38,46 @@ module Skyed
38
38
  end
39
39
  end
40
40
 
41
+ # This module encapsulates all the RDS related functions.
42
+ module ELB
43
+ class << self
44
+ def instance_ok?(elb_name, ec2_instance_id, elb = nil)
45
+ elb.describe_instance_health(
46
+ load_balancer_name: elb_name,
47
+ instances: [{ instance_id: ec2_instance_id }]
48
+ ).instance_states[0].state == 'InService'
49
+ end
50
+
51
+ def set_health_check(elb_name, health_check, elb = nil)
52
+ elb.configure_health_check(
53
+ load_balancer_name: elb_name,
54
+ health_check: {
55
+ target: health_check.target,
56
+ interval: health_check.interval,
57
+ timeout: health_check.timeout,
58
+ unhealthy_threshold: health_check.unhealthy_threshold,
59
+ healthy_threshold: health_check.healthy_threshold
60
+ }
61
+ )
62
+ end
63
+
64
+ def get_health_check(elb_name, elb = nil)
65
+ elbs = elb.describe_load_balancers(load_balancer_names: [elb_name])
66
+ elbs.load_balancer_descriptions[0].health_check
67
+ end
68
+
69
+ def login(
70
+ access = Skyed::Settings.access_key,
71
+ secret = Skyed::Settings.secret_key,
72
+ region = Skyed::AWS.region)
73
+ Aws::ElasticLoadBalancing::Client.new(
74
+ access_key_id: access,
75
+ secret_access_key: secret,
76
+ region: region)
77
+ end
78
+ end
79
+ end
80
+
41
81
  # This module encapsulates all the RDS related functions.
42
82
  module RDS
43
83
  class << self
@@ -237,11 +277,15 @@ module Skyed
237
277
  ) || stack_by_id(stack_criteria, opsworks)
238
278
  end
239
279
 
240
- def layer(layer_criteria, opsworks)
241
- layer_by_name(
242
- layer_criteria,
243
- opsworks
244
- ) || layer_by_id(layer_criteria, opsworks)
280
+ def layer(layer_criteria, opsworks, stack_id = nil)
281
+ layer = layer_by_name(layer_criteria, opsworks) ||
282
+ layer_by_id(layer_criteria, opsworks)
283
+ instance = nil
284
+ instance = instance_by_name(
285
+ layer_criteria, stack_id, opsworks) unless stack_id.nil?
286
+ layer ||= layer_by_id(
287
+ instance.layer_ids[0], opsworks) unless instance.nil?
288
+ layer
245
289
  end
246
290
 
247
291
  def deploy(opts)
@@ -0,0 +1,64 @@
1
+ module Skyed
2
+ # This module encapsulates all the create command steps.
3
+ module Check
4
+ class << self
5
+ def execute(_global_options, options, args)
6
+ settings(options)
7
+ elb = login('elb')
8
+ original_health_check = Skyed::AWS::ELB.get_health_check(args[0], elb)
9
+ reduce_health_check(args[0], original_health_check, elb)
10
+ wait_for_backend_restart(args[0], args[1], options)
11
+ Skyed::AWS::ELB.set_health_check(args[0], original_health_check, elb)
12
+ end
13
+
14
+ def wait_for_backend_restart(elb_name, instance_name, opts)
15
+ ow = settings(opts)
16
+ instance = Skyed::AWS::OpsWorks.instance_by_name(
17
+ instance_name,
18
+ Skyed::Settings.stack_id,
19
+ ow)
20
+ elb = login('elb')
21
+ [true, false].each do |op|
22
+ wait_for_backend(
23
+ elb_name, instance.ec2_instance_id, elb, op, opts[:wait_interval])
24
+ end
25
+ end
26
+
27
+ def wait_for_backend(elb_name, ec2_instance_id, elb, ok = true, wait = 0)
28
+ until ok == Skyed::AWS::ELB.instance_ok?(
29
+ elb_name,
30
+ ec2_instance_id,
31
+ elb
32
+ )
33
+ Kernel.sleep(wait)
34
+ end
35
+ end
36
+
37
+ def reduce_health_check(elb_name, original_health_check, elb = nil)
38
+ elb = login('elb') if elb.nil?
39
+ new_health_check = original_health_check.clone
40
+ new_health_check.timeout = 2
41
+ new_health_check.interval = 5
42
+ new_health_check.unhealthy_threshold = 2
43
+ new_health_check.healthy_threshold = 2
44
+ Skyed::AWS::ELB.set_health_check(elb_name, new_health_check, elb)
45
+ end
46
+
47
+ def settings(options)
48
+ ow = login('ow')
49
+ Skyed::Settings.stack_id = Skyed::AWS::OpsWorks.stack(
50
+ options[:stack], ow)[:stack_id]
51
+ Skyed::Settings.layer_id = Skyed::AWS::OpsWorks.layer(
52
+ options[:layer], ow)[:layer_id]
53
+ ow
54
+ end
55
+
56
+ def login(kind = 'elb')
57
+ Skyed::Init.credentials if Skyed::Settings.empty?
58
+ result = Skyed::AWS::ELB.login if kind == 'elb'
59
+ result = Skyed::AWS::OpsWorks.login if kind == 'ow'
60
+ result
61
+ end
62
+ end
63
+ end
64
+ end
@@ -46,6 +46,9 @@ command :run do |cmd|
46
46
  cmd.flag [:l, :layer], default_value: nil,
47
47
  type: String,
48
48
  desc: layer_desc
49
+ cmd.flag [:i, :instance], default_value: nil,
50
+ type: String,
51
+ desc: layer_desc
49
52
  desc = 'Time to wait for AWS responses'
50
53
  cmd.flag [:w, :wait_interval, 'wait-interval'], default_value: 30,
51
54
  type: Integer,
@@ -146,3 +149,23 @@ command :list do |cmd|
146
149
  Skyed::List.execute(global_options, options, args)
147
150
  end
148
151
  end
152
+
153
+ desc 'Check ELB'
154
+ long_desc 'Check ELB'
155
+
156
+ start_desc = 'Allows check ELB health state'
157
+ command :check do |cmd|
158
+ cmd.flag [:s, :stack], default_value: nil,
159
+ type: String,
160
+ desc: stack_desc
161
+ cmd.flag [:l, :layer], default_value: nil,
162
+ type: String,
163
+ desc: layer_desc
164
+ desc = 'Time to wait for AWS responses'
165
+ cmd.flag [:w, :wait_interval, 'wait-interval'], default_value: 30,
166
+ type: Integer,
167
+ desc: desc
168
+ cmd.action do |global_options, options, args|
169
+ Skyed::Check.execute(global_options, options, args)
170
+ end
171
+ end
data/lib/skyed/run.rb CHANGED
@@ -15,14 +15,23 @@ module Skyed
15
15
  def run(_global_options, options, args)
16
16
  check_run_options(options)
17
17
  ow = settings(options)
18
- instances = Skyed::AWS::OpsWorks.running_instances(
19
- { layer_id: Skyed::Settings.layer_id },
20
- ow)
18
+ instances = select_instances(options, ow)
21
19
  update_custom_cookbooks(ow, Skyed::Settings.stack_id, instances,
22
20
  options[:wait_interval])
23
21
  execute_recipes(ow, args, instances, options)
24
22
  end
25
23
 
24
+ def select_instances(options, ow)
25
+ instances = nil
26
+ instances = Skyed::AWS::OpsWorks.running_instances(
27
+ { layer_id: Skyed::Settings.layer_id },
28
+ ow) unless options[:layer].nil?
29
+ instances = [Skyed::AWS::OpsWorks.instance_by_name(
30
+ options[:instance], Skyed::Settings.stack_id,
31
+ ow).instance_id] unless options[:instance].nil?
32
+ instances
33
+ end
34
+
26
35
  def settings(options)
27
36
  ow = login
28
37
  Skyed::Settings.stack_id = stack(ow, options)
@@ -42,7 +51,10 @@ module Skyed
42
51
 
43
52
  def layer(ow, options)
44
53
  layer = Skyed::AWS::OpsWorks.layer(options[:layer], ow)
54
+ layer = Skyed::AWS::OpsWorks.layer(
55
+ options[:instance], ow, Skyed::Settings.stack_id) unless layer
45
56
  msg = "There's no such layer with id #{options[:layer]}"
57
+ msg += " or for instance #{options[:instance]}"
46
58
  fail msg unless layer
47
59
  layer[:layer_id]
48
60
  end
@@ -61,7 +73,8 @@ module Skyed
61
73
 
62
74
  def check_run_options(options)
63
75
  msg = 'Specify stack and layer or initialize for local management'
64
- fail msg unless options[:stack] && options[:layer]
76
+ required = options[:stack] && (options[:layer] || options[:instance])
77
+ fail msg unless required
65
78
  end
66
79
 
67
80
  def check_vagrant
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skyed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignasi Fosch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -76,6 +76,7 @@ files:
76
76
  - bin/skyed
77
77
  - lib/skyed.rb
78
78
  - lib/skyed/aws.rb
79
+ - lib/skyed/check.rb
79
80
  - lib/skyed/commands.rb
80
81
  - lib/skyed/create.rb
81
82
  - lib/skyed/deploy.rb