shelter 0.0.3 → 0.0.4

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: c6e01fa6f3c4c557007039ec6a00801fe964e56e
4
- data.tar.gz: e836545cd87009fcc5c14c4a2f5051df4430a244
3
+ metadata.gz: a4af3e0a261fda7eac0a113a58b69e2584709775
4
+ data.tar.gz: 231b3b5e68efab28aced80863dde26ce4325f8ed
5
5
  SHA512:
6
- metadata.gz: 3623a12c17917629240e4afc16f1bbd5b6377346bfe3f34c1c0ae867a76d782c79b0e06cc81528016a88d1039f6ea9abc84cc02c5492efd33498acbabda19555
7
- data.tar.gz: 6f935734fdabcc64abb92e1eac449cdcefc58e1a1e55cd3a6ba2fd4ae9e291f5e9cda0ab6937e431e8c99f05373e1372604861180cddd7b9a15fe08e65cc7e64
6
+ metadata.gz: 3b202c423bd81af7ea1a143d7ee790b3c615809ff1b1a159f28a2bf1cacc9e319ac7da0a404952e7d87934607ccbad5bae80866594a6c9c762b556dfd58dc281
7
+ data.tar.gz: d680464d08151bb0e0c8c6d2f65d45cdf5b438a6925b5cce6971212712557f8ded5d6e63ff63980b92c521f8958f4a9a22d43afe670f91be627a1e724447ba2b
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2017 by Balazs Nadasdi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md CHANGED
@@ -17,6 +17,7 @@ end
17
17
  Create a ruby file under your inventory directory:
18
18
 
19
19
  ```
20
+ # inventory/my_inventory.rb
20
21
  module Inventory
21
22
  class MyInventory
22
23
  def load(inventory)
@@ -32,9 +33,8 @@ end
32
33
  Create a directory under your `stack` directory (eg: `random`)
33
34
  and create your template there. `cli.rb` will be loaded.
34
35
 
35
-
36
- cli.rb:
37
36
  ```
37
+ # stack/random_stack/cli.rb:
38
38
  module Stack
39
39
  class RandomStack < Shelter::CLI::Stack::CloudFormation
40
40
  set_attr :stack_name, 'random'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
4
5
  require 'shelter'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
4
5
 
@@ -9,16 +10,16 @@ inventory = Shelter::Ansible::Inventory.new
9
10
  Shelter::CLI::App.config.inventory.each do |script|
10
11
  begin
11
12
  require File.join(Shelter::CLI::App.config.project_root, script)
12
- class_name = "Inventory::#{File.basename(script, File.extname(script)).camelize}"
13
- inv = Object.const_get(class_name).new()
13
+ class_name = File.basename(script, File.extname(script)).camelize
14
+ class_name = "Inventory::#{class_name}"
15
+ inv = Object.const_get(class_name).new
14
16
  inv.load(inventory)
15
17
  rescue Exception => e
16
- $stderr.puts "[x] Error with #{script}"
17
- $stderr.puts e.message
18
+ warn "[x] Error with #{script}"
19
+ warn e.message
18
20
  end
19
21
  end
20
22
 
21
23
  puts inventory.to_json
22
24
 
23
25
  # vim: set filetype=ruby:
24
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shelter
2
4
  module Ansible
3
5
  # Ansible Inventory representation
@@ -15,7 +17,7 @@ module Shelter
15
17
  @inv[group] ||= { hosts: [], vars: {} }
16
18
 
17
19
  @inv[group][:hosts] << ip
18
- #@inv[group][:vars] = { ansible_host: ip }.merge(vars)
20
+ @inv[group][:vars].merge!(vars)
19
21
  end
20
22
 
21
23
  def to_json
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shelter
2
4
  module CLI
3
5
  # Mixin module for Ansible
@@ -42,11 +44,9 @@ module Shelter
42
44
  command += optional_params(tags: tags, skip: skip, limit: limit)
43
45
  command << "#{App.config.ansible_directory}/#{playbook}.yaml"
44
46
 
45
- full_command = "#{command.join(' ')}"
46
- $stdout.puts full_command
47
+ full_command = command.join(' ')
47
48
  system full_command
48
49
  end
49
50
  end
50
51
  end
51
52
  end
52
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
 
3
5
  require_all(File.join(File.dirname(__FILE__), 'command'))
@@ -25,9 +27,9 @@ module Shelter
25
27
  )
26
28
 
27
29
  # Register server managers
28
- path = File.join(App.config.stack_directory, '*')
29
- Dir.glob(path).each do |path|
30
- next unless File.exists? "#{path}/cli.rb"
30
+ base_path = File.join(App.config.stack_directory, '*')
31
+ Dir.glob(base_path).each do |path|
32
+ next unless File.exist? "#{path}/cli.rb"
31
33
  require File.join(App.config.project_root, path, 'cli.rb')
32
34
 
33
35
  stack_name = File.basename(path)
@@ -40,12 +42,11 @@ module Shelter
40
42
  end
41
43
 
42
44
  # Register server managers
43
- path = File.join(App.config.plugin_directory, '*')
44
- Dir.glob(path).each do |path|
45
- next unless File.exists? "#{path}/main.rb"
45
+ base_path = File.join(App.config.plugin_directory, '*')
46
+ Dir.glob(base_path).each do |path|
47
+ next unless File.exist? "#{path}/main.rb"
46
48
  require File.join(App.config.project_root, path, 'main.rb')
47
49
  end
48
50
  end
49
51
  end
50
52
  end
51
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
 
3
5
  module Shelter
@@ -36,4 +38,3 @@ module Shelter
36
38
  end
37
39
  end
38
40
  end
39
-
@@ -1,13 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'aws-sdk'
3
5
 
4
6
  module Shelter
5
7
  module CLI
6
8
  module Stack
9
+ # CloudFormation based stack base
7
10
  class CloudFormation < Thor
8
11
  desc 'status', 'Stack status'
9
12
  def status
10
- target_stack = cf_client.describe_stacks(stack_name: get_attr(:stack_name)).stacks.first
13
+ target_stack = cf_client.describe_stacks(
14
+ stack_name: get_attr(:stack_name)
15
+ ).stacks.first
11
16
 
12
17
  puts "#{target_stack.stack_name} exists..."
13
18
  puts "Created: #{target_stack.creation_time}"
@@ -16,13 +21,13 @@ module Shelter
16
21
  stack_name: target_stack.stack_name
17
22
  )
18
23
  resources.stack_resources.each do |r|
19
- puts ' __________________________________________________________________________________________'
20
- puts '| Stack Name | Resource ID | Resource Type | Resource Status |'
21
- puts "| #{r.stack_name} | #{r.physical_resource_id} | #{r.resource_type} | #{r.resource_status} |"
22
- puts ' ------------------------------------------------------------------------------------------'
24
+ puts "Stack Name: #{r.stack_name}"
25
+ puts "Resource ID: #{r.physical_resource_id}"
26
+ puts "Resource Type: #{r.resource_type}"
27
+ puts "Resource Status: #{r.resource_status}"
23
28
  end
24
29
  rescue Exception => e
25
- fail Thor::Error, e.message
30
+ raise Thor::Error, e.message
26
31
  end
27
32
 
28
33
  desc 'create', 'Create stack'
@@ -38,14 +43,17 @@ module Shelter
38
43
  ]
39
44
  )
40
45
  i = 0
41
- cf_client.wait_until(:stack_create_complete, stack_name: get_attr(:stack_name)) do |w|
46
+ cf_client.wait_until(
47
+ :stack_create_complete,
48
+ stack_name: get_attr(:stack_name)
49
+ ) do |w|
42
50
  w.before_attempt do
43
51
  i = (i + 1) % SPINNER.size
44
52
  print "\r#{SPINNER[i]}"
45
53
  end
46
54
  end
47
55
  rescue Exception => e
48
- fail Thor::Error, e.message
56
+ raise Thor::Error, e.message
49
57
  end
50
58
 
51
59
  desc 'update', 'Update stack'
@@ -56,18 +64,19 @@ module Shelter
56
64
  capabilities: ['CAPABILITY_IAM']
57
65
  )
58
66
  i = 0
59
- cf_client.wait_until(:stack_update_complete, stack_name: get_attr(:stack_name)) do |w|
67
+ cf_client.wait_until(
68
+ :stack_update_complete,
69
+ stack_name: get_attr(:stack_name)
70
+ ) do |w|
60
71
  w.before_attempt do
61
72
  i = (i + 1) % SPINNER.size
62
73
  print "\r#{SPINNER[i]}"
63
74
  end
64
75
  end
65
76
  rescue Exception => e
66
- fail Thor::Error, e.message
77
+ raise Thor::Error, e.message
67
78
  end
68
79
 
69
-
70
-
71
80
  no_commands do
72
81
  class << self
73
82
  def set_attr(name, value)
@@ -89,16 +98,18 @@ module Shelter
89
98
  )
90
99
  end
91
100
 
92
- def get_public_ip
93
- target_stack = cf_client.describe_stacks(stack_name: get_attr(:stack_name)).stacks.first
101
+ def public_ip
102
+ target_stack = cf_client.describe_stacks(
103
+ stack_name: get_attr(:stack_name)
104
+ ).stacks.first
94
105
 
95
106
  resources = cf_client.describe_stack_resources(
96
107
  stack_name: target_stack.stack_name
97
108
  )
98
109
 
99
- eip = resources.stack_resources.select { |r|
110
+ eip = resources.stack_resources.select do |r|
100
111
  r.resource_type == 'AWS::EC2::EIP'
101
- }.first
112
+ end.first
102
113
 
103
114
  eip.physical_resource_id
104
115
  end
@@ -107,5 +118,3 @@ module Shelter
107
118
  end
108
119
  end
109
120
  end
110
-
111
-
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shelter
4
+ # Read and manage configuration
2
5
  class Configuration
3
6
  attr_accessor :ansible_directory,
4
7
  :stack_directory,
@@ -13,7 +16,10 @@ module Shelter
13
16
  @ansible_directory = 'ansible'
14
17
  @stack_directory = 'stacks'
15
18
  @secure_root = ENV.fetch('SECURE', 'secure')
16
- @inventory_script = File.join(File.dirname($PROGRAM_NAME), 'shelter-inventory')
19
+ @inventory_script = File.join(
20
+ File.dirname($PROGRAM_NAME),
21
+ 'shelter-inventory'
22
+ )
17
23
  @inventory_directory = 'inventory'
18
24
  @plugin_directory = 'plugin'
19
25
  end
@@ -28,6 +34,7 @@ module Shelter
28
34
  end
29
35
 
30
36
  private
37
+
31
38
  def shelterfile
32
39
  @shelterfile ||= File.join(find_project_root, 'Shelterfile.rb')
33
40
  end
@@ -38,7 +45,7 @@ module Shelter
38
45
  dir = Dir.pwd
39
46
  loop do
40
47
  break if File.exist?('Shelterfile.rb')
41
- fail 'No Shelterfile.rb found' if Dir.pwd == '/'
48
+ raise 'No Shelterfile.rb found' if Dir.pwd == '/'
42
49
  Dir.chdir('..')
43
50
  end
44
51
  @project_root = Dir.pwd
@@ -47,4 +54,3 @@ module Shelter
47
54
  end
48
55
  end
49
56
  end
50
-
@@ -1,20 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'version'
2
4
  require 'configuration'
3
5
 
4
- directories = %w(
6
+ directories = %w[
5
7
  ansible
6
8
  cli
7
- )
9
+ ]
8
10
 
11
+ # Extend String class with camelize
9
12
  class String
10
13
  def camelize(uppercase_first_letter = true)
11
14
  string = self
12
- if uppercase_first_letter
13
- string = string.sub(/^[a-z\d]*/) { $&.capitalize }
14
- else
15
- string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
16
- end
17
- string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
15
+ string = if uppercase_first_letter
16
+ string.sub(/^[a-z\d]*/) { $&.capitalize }
17
+ else
18
+ string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
19
+ end
20
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }.gsub('/', '::')
18
21
  end
19
22
  end
20
23
 
@@ -31,4 +34,3 @@ end
31
34
  directories.each do |dir|
32
35
  require_all(File.join(File.dirname(__FILE__), dir))
33
36
  end
34
-
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shelter
2
4
  # Current version to publish
3
5
  # Gemspec also uses this constant
4
- VERSION = '0.0.3'.freeze
6
+ VERSION = '0.0.4'
5
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balazs Nadasdi
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.20.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '5.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '5.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0.48'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0.48'
41
83
  description: Shelter tries to be a framework to manage internal infrastructure
42
84
  email: balazs.nadasdi@cheppers.com
43
85
  executables:
@@ -46,6 +88,7 @@ executables:
46
88
  extensions: []
47
89
  extra_rdoc_files: []
48
90
  files:
91
+ - LICENSE
49
92
  - README.md
50
93
  - bin/shelter
51
94
  - bin/shelter-inventory