skyed 0.1.10 → 0.1.11

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: e4940c6e2a8a3df68f9e3f68acd1aa8fdae2b12f
4
- data.tar.gz: 869c118fc70c08c7af21923620e858f5a7c35ffc
3
+ metadata.gz: b27a8404cf87eb1e4afb937814581a898bd03770
4
+ data.tar.gz: 60d273c48e9ae11f7e0a6a30e8fc467da703f0ad
5
5
  SHA512:
6
- metadata.gz: 6ebb691ec6afb34527190e04ec6fc967faf76ae8cbc712746f5d1b2c9b67ea82ca6045265abbcbaedf0f7e3f0d22ae41012bc4e2399357a713a743ec331f2a43
7
- data.tar.gz: f81af1bd091b21664c915e84a8ddd8b41e1629f7f572cf97168983a327baf5800249b8cc6c0c718ac51ac09573402f8cf44a2bb0c66d01a94ad03c65369b919f
6
+ metadata.gz: f6107f8e6876a9ccada9e29034fdcbde09698248ea34016fd852d062369c75610d9a85bd8651d0253e52833635ceee5a572393b036b3e6c5f820f7abfa116d61
7
+ data.tar.gz: b815d6ec22244760a8f11f356e4cf58cd750ad1dbb6e5cbc8fe807f8f55c164959089ee588cabb2f5c74811b866d22b0407f3bf9069779fa4eaa7484011e9db2
@@ -11,5 +11,5 @@ require 'skyed/settings'
11
11
 
12
12
  # Skyed is a set of tools for cloud computing
13
13
  module Skyed
14
- VERSION = '0.1.9'
14
+ VERSION = '0.1.11'
15
15
  end
@@ -42,15 +42,13 @@ module Skyed
42
42
  module RDS
43
43
  class << self
44
44
  def create_instance_from_snapshot(
45
- instance_name,
46
- snapshot,
47
- _options,
48
- rds = nil)
45
+ instance_name, snapshot, options, rds = nil)
49
46
  rds = login if rds.nil?
50
47
  rds.restore_db_instance_from_db_snapshot(
51
48
  db_instance_identifier: instance_name,
52
49
  db_snapshot_identifier: snapshot)[:db_instance]
53
- db_instance = wait_for_instance(instance_name, 'available', 0, rds)
50
+ db_instance = wait_for_instance(
51
+ instance_name, 'available', options[:wait_interval], rds)
54
52
  "#{db_instance[:endpoint][:address]}:#{db_instance[:endpoint][:port]}"
55
53
  end
56
54
 
@@ -160,6 +158,28 @@ module Skyed
160
158
  }
161
159
 
162
160
  class << self
161
+ def create_instance(stack_id, layer_id, instance_type, opsworks)
162
+ instance = opsworks.create_instance(
163
+ stack_id: stack_id,
164
+ layer_ids: [layer_id],
165
+ instance_type: instance_type)
166
+ opsworks.start_instance(instance_id: instance.instance_id)
167
+ wait_for_instance_id(
168
+ instance.instance_id,
169
+ 'online',
170
+ opsworks)
171
+ end
172
+
173
+ def wait_for_instance_id(instance_id, status, opsworks)
174
+ instance = opsworks.describe_instances(
175
+ instance_ids: [instance_id]).instances.first
176
+ until instance.nil? || instance.status == status
177
+ sleep(0)
178
+ instance = opsworks.describe_instances(
179
+ instance_ids: [instance_id]).instances.first
180
+ end
181
+ end
182
+
163
183
  def deregister_instance(hostname, opsworks)
164
184
  instance = instance_by_name(
165
185
  hostname, Skyed::Settings.stack_id, opsworks)
@@ -1,3 +1,5 @@
1
+ version Skyed::VERSION
2
+
1
3
  desc 'Initialize skyed'
2
4
  long_desc 'Sets up skyed configuration for a repository'
3
5
 
@@ -89,12 +91,22 @@ command :create do |cmd|
89
91
  cmd.flag [:password], default_value: 'password',
90
92
  type: String,
91
93
  desc: 'Master password of the RDS instance'
92
- defval = 'rds-launch-wizard'
94
+ cmd.flag [:s, :stack], default_value: nil,
95
+ type: String,
96
+ desc: stack_desc
97
+ cmd.flag [:l, :layer], default_value: nil,
98
+ type: String,
99
+ desc: layer_desc
100
+ desc = 'Time to wait for AWS responses'
101
+ cmd.flag [:w, :wait_interval, 'wait-interval'], default_value: 30,
102
+ type: Integer,
103
+ desc: desc
104
+ defval = 'default'
93
105
  desc = 'Name of the DB Security Group'
94
106
  cmd.flag [:db_security_group, 'db-security-group'], default_value: defval,
95
107
  type: String,
96
108
  desc: desc
97
- defval = 'default'
109
+ defval = 'default.postgres9.4'
98
110
  desc = 'Name of the DB Parameter Group'
99
111
  cmd.flag [:db_parameters_group, 'db-parameters-group'], default_value: defval,
100
112
  type: String,
@@ -1,9 +1,44 @@
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
5
  class << self
5
6
  def execute(_global_options, options, args)
6
7
  Skyed::Init.credentials if Skyed::Settings.empty?
8
+ execute_rds(options, args) if options[:rds]
9
+ create_opsworks(options, args) unless options[:rds]
10
+ end
11
+
12
+ def check_create_options(options)
13
+ msg = 'Specify stack and layer or initialize for local management'
14
+ fail msg unless options[:stack] && options[:layer]
15
+ end
16
+
17
+ def create_opsworks(options, _args)
18
+ check_create_options(options)
19
+ ow = settings(options)
20
+ Skyed::AWS::OpsWorks.create_instance(
21
+ Skyed::Settings.stack_id,
22
+ Skyed::Settings.layer_id,
23
+ options[:type],
24
+ ow)
25
+ end
26
+
27
+ def stack(ow, options)
28
+ stack = Skyed::AWS::OpsWorks.stack(options[:stack], ow)
29
+ msg = "There's no such stack with id #{options[:stack]}"
30
+ fail msg unless stack
31
+ stack[:stack_id]
32
+ end
33
+
34
+ def layer(ow, options)
35
+ layer = Skyed::AWS::OpsWorks.layer(options[:layer], ow)
36
+ msg = "There's no such layer with id #{options[:layer]}"
37
+ fail msg unless layer
38
+ layer[:layer_id]
39
+ end
40
+
41
+ def execute_rds(options, args)
7
42
  endpoint = create_new(options, args) if args.length == 1
8
43
  endpoint = restore_new(options, args) if args.length == 2
9
44
  puts endpoint
@@ -13,13 +48,25 @@ module Skyed
13
48
  Skyed::AWS::RDS.create_instance_from_snapshot(
14
49
  args[0],
15
50
  args[1],
16
- options.select { |k| k != :rds })
51
+ options.select { |k| ! @non_rds_options.include? k })
17
52
  end
18
53
 
19
54
  def create_new(options, args)
20
55
  Skyed::AWS::RDS.create_instance(
21
56
  args[0],
22
- options.select { |k| k != :rds })
57
+ options.select { |k| ! @non_rds_options.include? k })
58
+ end
59
+
60
+ def settings(options)
61
+ ow = login
62
+ Skyed::Settings.stack_id = stack(ow, options)
63
+ Skyed::Settings.layer_id = layer(ow, options)
64
+ ow
65
+ end
66
+
67
+ def login
68
+ Skyed::Init.credentials if Skyed::Settings.empty?
69
+ Skyed::AWS::OpsWorks.login
23
70
  end
24
71
  end
25
72
  end
@@ -28,11 +28,14 @@ module Skyed
28
28
  end
29
29
 
30
30
  def method_missing(name, *args)
31
+ msg = "unknown configuration root #{name}."
32
+ msg += ' Initialize skyed or export PKEY'
31
33
  if name.match(/.*=/)
32
34
  @_settings[name.to_s.split('=')[0]] = args[0]
33
35
  else
34
36
  @_settings[name.to_s] ||
35
- fail(NoMethodError, "unknown configuration root #{name}", caller)
37
+ fail(
38
+ NoMethodError, msg, caller)
36
39
  end
37
40
  end
38
41
 
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.10
4
+ version: 0.1.11
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-10 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git