skyed 0.1.16 → 0.2.0.dev

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.
@@ -1,22 +0,0 @@
1
- module Skyed
2
- # This module encapsulates all the list command steps.
3
- module List
4
- class << self
5
- def execute(global_options, options, args)
6
- db_snapshots(global_options, options, args[1..args.length])
7
- end
8
-
9
- def db_snapshots(_global_options, options, args)
10
- Skyed::Init.credentials if Skyed::Settings.empty?
11
- snapshots = Skyed::AWS::RDS.list_snapshots(
12
- options,
13
- args)
14
- snapshots.each do |snapshot|
15
- msg = "#{snapshot.db_snapshot_identifier}"
16
- msg += " #{snapshot.db_instance_identifier} #{snapshot.snapshot_type}"
17
- puts msg
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,133 +0,0 @@
1
- module Skyed
2
- # This module encapsulates all the run command steps.
3
- module Run
4
- class << self
5
- def execute(global_options, options, args)
6
- recipes = check_recipes_exist(options, args)
7
- if !options.nil? && options.key?(:stack) && !options[:stack].nil?
8
- run(global_options, options, recipes)
9
- else
10
- check_vagrant
11
- execute_recipes(Skyed::AWS::OpsWorks.login, recipes)
12
- end
13
- end
14
-
15
- def run(_global_options, options, args)
16
- check_run_options(options)
17
- ow = settings(options)
18
- instances = select_instances(options, ow)
19
- update_custom_cookbooks(ow, Skyed::Settings.stack_id, instances,
20
- options[:wait_interval])
21
- execute_recipes(ow, args, instances, options)
22
- end
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
-
35
- def settings(options)
36
- ow = login
37
- Skyed::Settings.stack_id = stack(ow, options)
38
- Skyed::Settings.layer_id = layer(ow, options)
39
- ow
40
- end
41
-
42
- def update_custom_cookbooks(ow, stack_id, instances, wait = 0)
43
- status = Skyed::AWS::OpsWorks.deploy(
44
- stack_id: stack_id,
45
- command: { name: 'update_custom_cookbooks' },
46
- instance_ids: instances,
47
- client: ow,
48
- wait_interval: wait)
49
- fail 'Deployment failed' unless status[0] == 'successful'
50
- end
51
-
52
- def layer(ow, options)
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
56
- msg = "There's no such layer with id #{options[:layer]}"
57
- msg += " or for instance #{options[:instance]}"
58
- fail msg unless layer
59
- layer[:layer_id]
60
- end
61
-
62
- def stack(ow, options)
63
- stack = Skyed::AWS::OpsWorks.stack(options[:stack], ow)
64
- msg = "There's no such stack with id #{options[:stack]}"
65
- fail msg unless stack
66
- stack[:stack_id]
67
- end
68
-
69
- def login
70
- Skyed::Init.credentials if Skyed::Settings.empty?
71
- Skyed::AWS::OpsWorks.login
72
- end
73
-
74
- def check_run_options(options)
75
- msg = 'Specify stack and layer or initialize for local management'
76
- required = options[:stack] && (options[:layer] || options[:instance])
77
- fail msg unless required
78
- end
79
-
80
- def check_vagrant
81
- output = `cd #{Skyed::Settings.repo} && vagrant status`
82
- msg = 'Vagrant failed'
83
- fail msg unless $CHILD_STATUS.success?
84
- msg = 'Vagrant machine is not running'
85
- fail msg unless output =~ /running/
86
- end
87
-
88
- def check_recipes_exist(options, args)
89
- settings(options)
90
- if !options.nil? && options.key?(:stack) && !options[:stack].nil?
91
- recipes = args.select { |recipe| recipe_in_remote(options, recipe) }
92
- else
93
- recipes = args.select { |recipe| recipe_in_cookbook(recipe) }
94
- end
95
- msg = "Couldn't find #{args - recipes} recipes in repository"
96
- fail msg unless recipes == args
97
- recipes
98
- end
99
-
100
- def execute_recipes(ow, recipes, instances = nil, opts = {})
101
- args = {
102
- stack_id: Skyed::Settings.stack_id,
103
- command: { name: 'execute_recipes', recipes: recipes },
104
- instance_ids: instances,
105
- client: ow,
106
- wait_interval: opts[:wait_interval] || 0
107
- }
108
- args[:custom_json] = opts[:custom_json] if opts.key? :custom_json
109
- status = Skyed::AWS::OpsWorks.deploy(args)
110
- fail 'Deployment failed' unless status[0] == 'successful'
111
- end
112
-
113
- def recipe_in_cookbook(recipe, path = nil)
114
- path ||= Skyed::Settings.repo
115
- cookbook, recipe = recipe.split('::')
116
- recipe = 'default' if recipe.nil?
117
- File.exist?(
118
- File.join(
119
- path,
120
- cookbook,
121
- 'recipes',
122
- "#{recipe}.rb"))
123
- end
124
-
125
- def recipe_in_remote(options, recipe)
126
- clone = Skyed::Git.clone_stack_remote(
127
- Skyed::AWS::OpsWorks.stack(options[:stack], login),
128
- options)
129
- recipe_in_cookbook(recipe, clone)
130
- end
131
- end
132
- end
133
- end
@@ -1,14 +0,0 @@
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
@@ -1,30 +0,0 @@
1
- require 'erb'
2
-
3
- module Skyed
4
- # This module encapsulates some generic utility functions.
5
- module Utils
6
- class << self
7
- def export_credentials
8
- ENV['AWS_ACCESS_KEY'] = Skyed::Settings.access_key
9
- ENV['AWS_SECRET_KEY'] = Skyed::Settings.secret_key
10
- end
11
-
12
- def create_template(base, subpath, template_file, mode = 0644)
13
- b = binding
14
- folders = subpath.split('/')
15
- template = ERB.new(File.read(File.join(
16
- File.dirname(File.dirname(File.dirname(__FILE__))),
17
- 'templates',
18
- template_file)))
19
- File.open(File.join(base, folders), 'w') do |f|
20
- f.write(template.result b)
21
- end
22
- File.chmod(mode, File.join(base, folders))
23
- end
24
-
25
- def read_key_file(key_file)
26
- File.open(key_file, 'rb').read
27
- end
28
- end
29
- end
30
- end