skyed 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b27a8404cf87eb1e4afb937814581a898bd03770
4
- data.tar.gz: 60d273c48e9ae11f7e0a6a30e8fc467da703f0ad
3
+ metadata.gz: c191f7b0605dc2e8d68779b5cd1eaf2712e43447
4
+ data.tar.gz: d1daad8c34f40f89dfd6fc28d9c794465f15b564
5
5
  SHA512:
6
- metadata.gz: f6107f8e6876a9ccada9e29034fdcbde09698248ea34016fd852d062369c75610d9a85bd8651d0253e52833635ceee5a572393b036b3e6c5f820f7abfa116d61
7
- data.tar.gz: b815d6ec22244760a8f11f356e4cf58cd750ad1dbb6e5cbc8fe807f8f55c164959089ee588cabb2f5c74811b866d22b0407f3bf9069779fa4eaa7484011e9db2
6
+ metadata.gz: 0ba58d81e95e50e8258abb2ff06a4c775c24eb4b17356939239f94179abf150ac750dc4fac4f97f248fe19030fd310e21c367ad5c0c6e739636eb0c952523a90
7
+ data.tar.gz: 792ce1e3b5756bbfae02b31e39111ba7d7cece30f1c65cadef1656ab52c319ccb7d952e259248974a8f51ac1c351c34b496d7f354a8342cbbdba2c177df86e9d
@@ -4,6 +4,7 @@ require 'skyed/utils'
4
4
  require 'skyed/git'
5
5
  require 'skyed/aws'
6
6
  require 'skyed/destroy'
7
+ require 'skyed/stop'
7
8
  require 'skyed/run'
8
9
  require 'skyed/deploy'
9
10
  require 'skyed/init'
@@ -11,5 +12,5 @@ require 'skyed/settings'
11
12
 
12
13
  # Skyed is a set of tools for cloud computing
13
14
  module Skyed
14
- VERSION = '0.1.11'
15
+ VERSION = '0.1.12'
15
16
  end
@@ -158,6 +158,29 @@ module Skyed
158
158
  }
159
159
 
160
160
  class << self
161
+ def start_instance(instance_id, opsworks)
162
+ opsworks.start_instance(instance_id: instance_id)
163
+ wait_for_instance_id(instance_id, 'online', opsworks)
164
+ end
165
+
166
+ def instances_by_status(stack_id, layer_id, status, ow)
167
+ Skyed::Settings.stack_id = stack(stack_id, ow).stack_id
168
+ ow.describe_instances(
169
+ layer_id: layer(layer_id, ow).layer_id)[:instances].select do |i|
170
+ i.status == status
171
+ end
172
+ end
173
+
174
+ def stop_instance(stack_id, hostname, opsworks = nil)
175
+ opsworks = login if opsworks.nil?
176
+ instance = instance_by_name(hostname, stack_id, opsworks)
177
+ opsworks.stop_instance(instance_id: instance.instance_id)
178
+ wait_for_instance_id(
179
+ instance.instance_id,
180
+ 'stopped',
181
+ opsworks)
182
+ end
183
+
161
184
  def create_instance(stack_id, layer_id, instance_type, opsworks)
162
185
  instance = opsworks.create_instance(
163
186
  stack_id: stack_id,
@@ -37,8 +37,8 @@ end
37
37
  desc 'Run specific recipes on instance'
38
38
  long_desc 'Runs specified recipes on all running instances'
39
39
 
40
- stack_desc = 'Stack to which the run affects.'
41
- layer_desc = 'Layer to which the run affects.'
40
+ stack_desc = 'Stack to which the command affects.'
41
+ layer_desc = 'Layer to which the command affects.'
42
42
  command :run do |cmd|
43
43
  cmd.flag [:s, :stack], default_value: nil,
44
44
  type: String,
@@ -73,9 +73,26 @@ command :destroy do |cmd|
73
73
  end
74
74
  end
75
75
 
76
+ desc 'Stop instance'
77
+ long_desc 'Stop instance'
78
+
79
+ command :stop do |cmd|
80
+ cmd.flag [:s, :stack], default_value: nil,
81
+ type: String,
82
+ desc: stack_desc
83
+ desc = 'Time to wait for AWS responses'
84
+ cmd.flag [:w, :wait_interval, 'wait-interval'], default_value: 30,
85
+ type: Integer,
86
+ desc: desc
87
+ cmd.action do |global_options, options, args|
88
+ Skyed::Stop.execute(global_options, options, args)
89
+ end
90
+ end
91
+
76
92
  desc 'Create instance'
77
93
  long_desc 'Create instance'
78
94
 
95
+ start_desc = 'Avoids creation if stopped OW instance already exists'
79
96
  command :create do |cmd|
80
97
  cmd.switch [:rds], default_value: false,
81
98
  desc: 'Creates RDS instance'
@@ -97,6 +114,8 @@ command :create do |cmd|
97
114
  cmd.flag [:l, :layer], default_value: nil,
98
115
  type: String,
99
116
  desc: layer_desc
117
+ cmd.switch [:start], default_value: false,
118
+ desc: start_desc
100
119
  desc = 'Time to wait for AWS responses'
101
120
  cmd.flag [:w, :wait_interval, 'wait-interval'], default_value: 30,
102
121
  type: Integer,
@@ -1,7 +1,7 @@
1
1
  module Skyed
2
2
  # This module encapsulates all the create command steps.
3
3
  module Create
4
- @non_rds_options = [:rds, :stack, :layer]
4
+ @non_rds_options = [:rds, :start, :stack, :layer]
5
5
  class << self
6
6
  def execute(_global_options, options, args)
7
7
  Skyed::Init.credentials if Skyed::Settings.empty?
@@ -9,6 +9,16 @@ module Skyed
9
9
  create_opsworks(options, args) unless options[:rds]
10
10
  end
11
11
 
12
+ def start_opsworks(options, ow)
13
+ stopped_instances = Skyed::AWS::OpsWorks.instances_by_status(
14
+ options[:stack], options[:layer], 'stopped', ow)
15
+ return false if stopped_instances.empty?
16
+ Skyed::AWS::OpsWorks.start_instance(
17
+ stopped_instances.first.instance_id,
18
+ ow)
19
+ true
20
+ end
21
+
12
22
  def check_create_options(options)
13
23
  msg = 'Specify stack and layer or initialize for local management'
14
24
  fail msg unless options[:stack] && options[:layer]
@@ -17,11 +27,12 @@ module Skyed
17
27
  def create_opsworks(options, _args)
18
28
  check_create_options(options)
19
29
  ow = settings(options)
30
+ options[:start] = start_opsworks(options, ow) if options[:start]
20
31
  Skyed::AWS::OpsWorks.create_instance(
21
32
  Skyed::Settings.stack_id,
22
33
  Skyed::Settings.layer_id,
23
34
  options[:type],
24
- ow)
35
+ ow) unless options[:start]
25
36
  end
26
37
 
27
38
  def stack(ow, options)
@@ -0,0 +1,14 @@
1
+ module Skyed
2
+ # This module encapsulates all the destroy command steps.
3
+ module Stop
4
+ class << self
5
+ def execute(_global_options, options, args)
6
+ Skyed::Init.credentials if Skyed::Settings.empty?
7
+ ow = Skyed::AWS::OpsWorks.login
8
+ stack_id = Skyed::AWS::OpsWorks.stack(
9
+ options[:stack], ow)[:stack_id]
10
+ Skyed::AWS::OpsWorks.stop_instance(stack_id, args[0], ow)
11
+ end
12
+ end
13
+ end
14
+ end
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.11
4
+ version: 0.1.12
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-09-30 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -85,6 +85,7 @@ files:
85
85
  - lib/skyed/list.rb
86
86
  - lib/skyed/run.rb
87
87
  - lib/skyed/settings.rb
88
+ - lib/skyed/stop.rb
88
89
  - lib/skyed/utils.rb
89
90
  - templates/Vagrantfile.erb
90
91
  - templates/config.j2.erb