vscripts 0.1.0 → 0.1.2

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.
Files changed (40) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +8 -1
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +3 -1
  5. data/Rakefile +1 -3
  6. data/VERSION +1 -1
  7. data/lib/vscripts.rb +1 -1
  8. data/lib/vscripts/aws.rb +5 -0
  9. data/lib/vscripts/aws/ec2.rb +11 -16
  10. data/lib/vscripts/command_line.rb +3 -3
  11. data/lib/vscripts/{command.rb → commands.rb} +1 -1
  12. data/lib/vscripts/commands/identify.rb +9 -19
  13. data/lib/vscripts/commands/tags2facts.rb +7 -25
  14. data/lib/vscripts/util.rb +12 -0
  15. data/lib/vscripts/util/local_system.rb +1 -29
  16. data/spec/aws_spec_helper.rb +10 -0
  17. data/spec/spec_helper.rb +27 -2
  18. data/spec/unit/vscripts/aws/ec2_spec.rb +98 -0
  19. data/spec/unit/vscripts/aws/metadata_spec.rb +62 -0
  20. data/spec/{vscripts → unit/vscripts}/aws_spec.rb +3 -1
  21. data/spec/unit/vscripts/command_line_spec.rb +43 -0
  22. data/spec/unit/vscripts/commands/identify_spec.rb +178 -0
  23. data/spec/unit/vscripts/commands/tags2facts_spec.rb +52 -0
  24. data/spec/unit/vscripts/commands_spec.rb +10 -0
  25. data/spec/unit/vscripts/util/local_system_spec.rb +82 -0
  26. data/spec/{vscripts → unit/vscripts}/version_spec.rb +1 -0
  27. data/spec/unit/vscripts_spec.rb +27 -0
  28. data/tasks/deploy.rake +6 -1
  29. data/tasks/lint.rake +1 -1
  30. data/vscripts.gemspec +3 -1
  31. metadata +86 -56
  32. data/.rspec +0 -2
  33. data/spec/vscripts/aws/ec2_spec.rb +0 -90
  34. data/spec/vscripts/aws/metadata_spec.rb +0 -48
  35. data/spec/vscripts/command_line_spec.rb +0 -34
  36. data/spec/vscripts/command_spec.rb +0 -9
  37. data/spec/vscripts/commands/identify_spec.rb +0 -111
  38. data/spec/vscripts/commands/tags2facts_spec.rb +0 -35
  39. data/spec/vscripts/util/local_system_spec.rb +0 -80
  40. data/spec/vscripts_spec.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f136dbab318d66e5849bc3fd0c919f705f3f4628
4
- data.tar.gz: 1a8fc5ec87de153df9422c606b8bcb92e10a1d42
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDkyZjJmNjdiNjYxNzNmYWM1Njc1M2U4OWJhMWIyMDEzMjJiMjVhOQ==
5
+ data.tar.gz: !binary |-
6
+ ZTI5MjVkZmUzZmEyMDc4ZjQ3YTE0NWJlNGJlNjcwZjQyYWQ1YzIxMg==
5
7
  SHA512:
6
- metadata.gz: 6102d72f4aaed7bf46c3bda322ec5f9d8a41b631c402da8572adde1ebde9b0e63ea51bf07971951a2bfc55b9ac7f0b90cb57d14f2a0e6c0375d9b5df25de3b58
7
- data.tar.gz: e9d7926d647076d643f8d3f898d990298eb5f268d287335f0dfae69db2703ca3c030f2ba1a05669107355fac20f73e5740d9e5673330702b0159d682873928f6
8
+ metadata.gz: !binary |-
9
+ NzZmNjc5NTY3M2IwMzgxYjMxNDM1YWFjZjg0NjkxNmJiYjFjN2EwNDZmNGFk
10
+ NWZmMjkzNWM5OWMxM2QzZDQ3MTY5ODZiNjQ0NDkxNDVhNzBiMzBlOTdhYTBk
11
+ YWQ5ZDQ2MjM0ZDU3ZmExNjNkNjBiMzVkYjhlYzU2MDk4OWJmMDI=
12
+ data.tar.gz: !binary |-
13
+ MzI0Yzg4M2IwZmM3M2Y4NDdlZGYzMzM3MmQyZTE2YjQ2ZDE4NzI1YmI5NWQw
14
+ NDczN2Y2ZmRmZTk5YzE4NWJlMDQ5MzlmNmM5YWJjNGJhNzVjNTNkOWVjM2I5
15
+ ZTNlYjMxODhkZDlmY2E2YmIxZTA5ZWRlYmFmYzIzNWFhYzkxN2M=
data/.travis.yml CHANGED
@@ -2,4 +2,11 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.1.2
5
- script: bundle exec rake spec
5
+ deploy:
6
+ provider: rubygems
7
+ api_key:
8
+ secure: fBDuhk/Ip0Cu/rgBxyKaFsVXkPy21pLqckbKm72n7fN1vDg36r468GPPMPzT85szZOZACpVHVk8L9xZ5aWG0So+n5Swt8S5vjEP4wRU024WCCv0Z1FATT+HwrF3cYxW1PKH/VpFEL0UbAsW+7xpM0q4/nmkLk9FSYmXLahXCGqc=
9
+ gem: vscripts
10
+ on:
11
+ tags: true
12
+ branch: master
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ Version 0.1.2
2
+ ---
3
+ * Revert "Lock gem versions" ([Vlad - 5881199](https://github.com/vghn/vscripts/commit/5881199dd0dd846667c27a4619c01934c66f2c7b))
4
+
5
+ Version 0.1.1
6
+ ---
7
+ * Upgrade to RSpec 3 and clean up deprecations ([Vlad Ghinea - c2cf66e](https://github.com/vghn/vscripts/commit/c2cf66efbed7de6e436a74cc4fed46007ef07d5e))
8
+ * Minor updates ([Vlad Ghinea - e045a5f](https://github.com/vghn/vscripts/commit/e045a5fc6f7cd292d17247af92c580810ed98a26))
9
+ * Add code coverage ([Vlad Ghinea - 1c0d9dd](https://github.com/vghn/vscripts/commit/1c0d9dddb9ab5cb2090ef1bad84654cc4ab72f28))
10
+ * Add local code coverage files for development ([Vlad Ghinea - 8a52a9b](https://github.com/vghn/vscripts/commit/8a52a9b800d06374c9ee5ee4872b055af6f9a3be))
11
+ * Run test by default in Rake ([Vlad Ghinea - 3141ec2](https://github.com/vghn/vscripts/commit/3141ec2e4c5befc8ea83dcdd0198ec7fcc1f06e5))
12
+ * Fix tags exclude list ([Vlad Ghinea - 98ffe4e](https://github.com/vghn/vscripts/commit/98ffe4e6926be6b91230c31cc7ad64c6cdcfab7d))
13
+ * Fix file creation ([Vlad - b93cf89](https://github.com/vghn/vscripts/commit/b93cf89b3e35eecc0f52f7399065cab4aeff2377))
14
+ * More tests ([Vlad - 8e8254c](https://github.com/vghn/vscripts/commit/8e8254c74d1fb667ed5cf672fec256c61762d75d))
15
+ * Better RSpec ([Vlad - 3c4bd75](https://github.com/vghn/vscripts/commit/3c4bd753de4f324aac29ed1d94fdd1ed3a19b6bc))
16
+ * Reorganize code and better tests ([Vlad - 11b3029](https://github.com/vghn/vscripts/commit/11b30294c6ced697db6c6f9785d0018a47cb7c5c))
17
+ * Lock gem versions ([Vlad - 6cb0e58](https://github.com/vghn/vscripts/commit/6cb0e58426cc6b2246b8348652aa89366a43ca7d))
18
+ * Fix identify command ([Vlad - bc173e7](https://github.com/vghn/vscripts/commit/bc173e7bb7da099beea98fbbe008ce8eaf882e87))
19
+ * Add RubyGems Deployment ([Vlad - 5e004a0](https://github.com/vghn/vscripts/commit/5e004a0b7d099b2399996672a1e13e9df1b91131))
20
+ * Delegate RubyGems release to Travis ([Vlad - a2d9178](https://github.com/vghn/vscripts/commit/a2d917857f0e03d36a7fc1281bec1be0f3cc1b98))
21
+ * Extra space ([Vlad - afbd453](https://github.com/vghn/vscripts/commit/afbd4535e462ccb0c2c4db34d10d224fd2007dc4))
22
+ * Remove Gemfile.lock ([Vlad - aa8c327](https://github.com/vghn/vscripts/commit/aa8c3278d069e69edc8dbefa468d37afbe0c163f))
23
+
1
24
  Version 0.1.0
2
25
  ---
3
26
  * Domain fallback to local ([Vlad Ghinea - c0d176f](https://github.com/vghn/vscripts/commit/c0d176fe244c10dd8d2b394075d5d6ef1c0ef332))
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Build Status](https://travis-ci.org/vghn/vscripts.svg?branch=master)](https://travis-ci.org/vghn/vscripts)
3
3
  [![Code Climate](https://codeclimate.com/github/vghn/vscripts.png)](https://codeclimate.com/github/vghn/vscripts)
4
4
  [![Gem Version](https://badge.fury.io/rb/vscripts.svg)](http://badge.fury.io/rb/vscripts)
5
+ [![Coverage Status](https://coveralls.io/repos/vghn/vscripts/badge.png)](https://coveralls.io/r/vghn/vscripts)
5
6
 
6
7
  Automation daemon.
7
8
 
@@ -56,7 +57,7 @@ can be overridden by adding `[-a|--all]` command line option.
56
57
  $ vscripts tags2facts --file /tmp/my_tags.json --all
57
58
  ```
58
59
 
59
- 2. **identify**
60
+ 2. **Identify**
60
61
  This command creates a themed host name and fully qualified domain name for
61
62
  the server, using AWS EC2 tags. The default theme is `Group-Role-#` which means
62
63
  that the command collects the value of the `Group` and the `Role` AWS EC2 tags
@@ -72,6 +73,7 @@ associated with the current instance.
72
73
 
73
74
  If a ***--host*** argument is provided it will override the default theme.
74
75
  *DOMAIN* is still looked up.
76
+
75
77
  If a ***--domain*** argument is provided it will override the default
76
78
  domain.
77
79
 
data/Rakefile CHANGED
@@ -14,6 +14,4 @@ require 'rspec/core/rake_task'
14
14
  RSpec::Core::RakeTask.new
15
15
 
16
16
  # Default task
17
- task :default do
18
- puts `rake -T`
19
- end
17
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
data/lib/vscripts.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'vscripts/command'
1
+ require 'vscripts/commands'
2
2
  require 'vscripts/command_line'
3
3
 
4
4
  # Main VScripts module
data/lib/vscripts/aws.rb CHANGED
@@ -2,9 +2,14 @@ require 'aws-sdk'
2
2
  require 'logger'
3
3
  require 'yaml'
4
4
 
5
+ require 'vscripts/aws/ec2'
6
+ require 'vscripts/aws/metadata'
7
+
5
8
  module VScripts
6
9
  # Amazon Web Services Module
7
10
  module AWS
8
11
  ::AWS.config
12
+ include VScripts::AWS::EC2
13
+ include VScripts::AWS::Metadata
9
14
  end # module AWS
10
15
  end # module VScripts
@@ -1,23 +1,16 @@
1
- require 'vscripts/aws'
2
- require 'vscripts/aws/metadata'
3
-
4
1
  module VScripts
5
2
  module AWS
6
- # EC2 Class smells of :reek:UncommunicativeModuleName
3
+ # EC2 Module smells of :reek:UncommunicativeModuleName
7
4
  # @ec2 smells of :reek:UncommunicativeVariableName
5
+ # ec2 smells of :reek:UncommunicativeMethodName
8
6
 
9
7
  # AWS Elastic Compute Cloud
10
- class EC2
11
- include VScripts::AWS::Metadata
12
-
8
+ module EC2
13
9
  # Load AWS SDK for EC2
14
- def initialize
15
- @ec2 ||= ::AWS::EC2.new(region: region)
10
+ def ec2
11
+ ::AWS::EC2.new(region: region)
16
12
  end
17
13
 
18
- # @return [AWS::EC2]
19
- attr_reader :ec2
20
-
21
14
  # Get instance object
22
15
  def instance
23
16
  check_instance
@@ -41,9 +34,11 @@ module VScripts
41
34
 
42
35
  # Get a list of tags
43
36
  def tags_without(list = [])
44
- all = all_tags
45
- list.each { |excluded| all.delete(excluded) }
46
- all
37
+ all_tags.each_with_object({}) do |tag, hash|
38
+ key, value = tag[0], tag[1]
39
+ hash[key] = value unless list.include? key
40
+ hash
41
+ end
47
42
  end
48
43
 
49
44
  # Looks for the value of the 'Name' tag for the given instance
@@ -73,6 +68,6 @@ module VScripts
73
68
  functional_instance.tags['Name']
74
69
  end
75
70
  end
76
- end # class EC2
71
+ end # module EC2
77
72
  end # module Amazon
78
73
  end # module VScripts
@@ -1,6 +1,6 @@
1
1
  require 'trollop'
2
2
  require 'vscripts/version'
3
- require 'vscripts/command'
3
+ require 'vscripts/commands'
4
4
 
5
5
  module VScripts
6
6
  # Global Command Line
@@ -23,7 +23,7 @@ module VScripts
23
23
  # This method smells of :reek:NestedIterators but ignores them
24
24
  # This method smells of :reek:TooManyStatements but ignores them
25
25
  def parser # rubocop:disable MethodLength
26
- available = Command.list.map { |cmd| cmd.to_s.downcase }
26
+ available = Commands.list.map { |cmd| cmd.to_s.downcase }
27
27
  @parser ||= Trollop::Parser.new do
28
28
  version VScripts::VERSION_C
29
29
  banner <<-EOS
@@ -57,7 +57,7 @@ EOS
57
57
  def verify_command
58
58
  command_cli = arguments.shift
59
59
  command_cls = command_cli.capitalize.to_sym
60
- if Command.list.include?(command_cls)
60
+ if Commands.list.include?(command_cls)
61
61
  return command_cls
62
62
  else
63
63
  abort "Error: Unknown subcommand '#{command_cli}'\nTry --help."
@@ -3,7 +3,7 @@ require 'vscripts/commands/identify'
3
3
 
4
4
  module VScripts
5
5
  # Main Command class
6
- class Command
6
+ module Commands
7
7
  # Lists the available commands
8
8
  # @return [Array]
9
9
  def self.list
@@ -1,15 +1,13 @@
1
- require 'trollop'
2
- require 'vscripts/aws/ec2'
3
- require 'vscripts/util/local_system'
1
+ require 'vscripts/aws'
2
+ require 'vscripts/util'
4
3
 
5
4
  module VScripts
6
5
  # Commands module
7
6
  module Commands
8
- # @ec2 smells of :reek:UncommunicativeVariableName
9
-
10
7
  # Identify Class
11
8
  class Identify # rubocop:disable ClassLength
12
- include VScripts::Util::LocalSystem
9
+ include VScripts::AWS
10
+ include VScripts::Util
13
11
 
14
12
  # HELP
15
13
  USAGE = <<-EOS
@@ -42,8 +40,6 @@ associated with the current instance.
42
40
  Options:
43
41
  EOS
44
42
 
45
- # @return [AWS::EC2] EC2 SDK
46
- attr_reader :ec2
47
43
  # @return [String] Theme string
48
44
  attr_reader :theme
49
45
  # @return [String] Host name
@@ -80,12 +76,6 @@ associated with the current instance.
80
76
  end
81
77
  end
82
78
 
83
- # Loads AWS::EC2
84
- # This method smells of :reek:UncommunicativeMethodName but ignores it
85
- def ec2
86
- @ec2 ||= VScripts::AWS::EC2.new
87
- end
88
-
89
79
  # @return [Array] Splits theme into elements
90
80
  def theme_elements
91
81
  theme.split('-')
@@ -94,7 +84,7 @@ associated with the current instance.
94
84
  # @return [Array] An array of values for each tag specified in the theme
95
85
  def map2tags
96
86
  theme_elements.map do |element|
97
- element == '#' ? element : ec2.tag(element)
87
+ element == '#' ? element : tag(element)
98
88
  end
99
89
  end
100
90
 
@@ -106,7 +96,7 @@ associated with the current instance.
106
96
  # @return [String] The incremented host name
107
97
  def incremented_hostname
108
98
  number = 1
109
- while ec2.similar_instances.include? "#{themed_host_name}.#{domain}"
99
+ while similar_instances.include? "#{themed_host_name}.#{domain}"
110
100
  .sub(/#/, "#{number}")
111
101
  number += 1
112
102
  end
@@ -121,7 +111,7 @@ associated with the current instance.
121
111
  # @return [String] The value of the command line --domain argument, or the
122
112
  # value of the 'Domain' EC2 tag or the local domain name.
123
113
  def new_domain
124
- domain || ec2.tag('Domain') || local_domain_name
114
+ domain || tag('Domain') || local_domain_name
125
115
  end
126
116
 
127
117
  # @return [String] The fully qualified domain name
@@ -131,9 +121,9 @@ associated with the current instance.
131
121
 
132
122
  # Modify the 'Name' tag
133
123
  def set_name_tag
134
- return if ec2.tag('Name') == new_fqdn
124
+ return if tag('Name') == new_fqdn
135
125
  puts "Setting name tag to \"#{new_fqdn}\"..."
136
- ec2.create_tag(ec2.instance, 'Name', value: new_fqdn)
126
+ create_tag(instance, 'Name', value: new_fqdn)
137
127
  end
138
128
 
139
129
  # Modify the host name
@@ -1,15 +1,13 @@
1
- require 'trollop'
2
- require 'vscripts/aws/ec2'
3
- require 'vscripts/util/local_system'
1
+ require 'vscripts/aws'
2
+ require 'vscripts/util'
4
3
 
5
4
  module VScripts
6
5
  # Commands module
7
6
  module Commands
8
- # @ec2 smells of :reek:UncommunicativeVariableName
9
-
10
7
  # Tags2Facts Class
11
8
  class Tags2facts
12
- include VScripts::Util::LocalSystem
9
+ include VScripts::AWS
10
+ include VScripts::Util
13
11
 
14
12
  # HELP
15
13
  USAGE = <<-EOS
@@ -31,8 +29,6 @@ module VScripts
31
29
 
32
30
  # @return [Array] Command specific arguments
33
31
  attr_reader :arguments
34
- # @return [AWS::EC2] EC2 SDK
35
- attr_reader :ec2
36
32
 
37
33
  def initialize(argv = [])
38
34
  @arguments ||= argv
@@ -49,12 +45,6 @@ module VScripts
49
45
  end
50
46
  end
51
47
 
52
- # Loads AWS EC2
53
- # This method smells of :reek:UncommunicativeMethodName but ignores it
54
- def ec2
55
- @ec2 ||= VScripts::AWS::EC2.new
56
- end
57
-
58
48
  # Parses command line arguments
59
49
  def cli
60
50
  @cli ||= Trollop.with_standard_exception_handling parser do
@@ -67,21 +57,13 @@ module VScripts
67
57
  cli.all ? [] : %w(Name Domain)
68
58
  end
69
59
 
70
- # @return [Hash] Filtered tags
71
- def filtered_tags
72
- ec2.tags_without(exclude_list).each_with_object({}) do |tag, hash|
73
- hash[tag[0]] = tag[1]
74
- hash
75
- end
76
- end
77
-
78
60
  # @return [JSON] Formatted JSON
79
61
  def tags_json
80
- tags_hash = filtered_tags
81
- if tags_hash.empty?
62
+ filtered = tags_without(exclude_list)
63
+ if filtered.empty?
82
64
  abort 'No tags were found!'
83
65
  else
84
- JSON.pretty_generate(tags_hash)
66
+ JSON.pretty_generate(filtered)
85
67
  end
86
68
  end
87
69
 
@@ -0,0 +1,12 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+ require 'English'
4
+
5
+ require 'vscripts/util/local_system'
6
+
7
+ module VScripts
8
+ # Amazon Web Services Module
9
+ module Util
10
+ include VScripts::Util::LocalSystem
11
+ end # module AWS
12
+ end # module VScripts
@@ -1,7 +1,3 @@
1
- require 'fileutils'
2
- require 'yaml'
3
- require 'English'
4
-
5
1
  module VScripts
6
2
  module Util
7
3
  # Local system functions library
@@ -60,7 +56,7 @@ module VScripts
60
56
  newfile.write(body)
61
57
  end
62
58
  rescue Errno::EACCES
63
- puts "FATAL: You need to be root in order to write to #{file}"
59
+ abort "FATAL: You need to be root in order to write to #{file}"
64
60
  end
65
61
 
66
62
  # Ensures the specified file has the specified content
@@ -68,30 +64,6 @@ module VScripts
68
64
  write = write_file(file, body)
69
65
  read = IO.read(file)
70
66
  read == body || write
71
- rescue
72
- write
73
- end
74
-
75
- # Gets system checks from environment variables
76
- def checks
77
- config['SystemChecks']
78
- rescue
79
- {}
80
- end
81
-
82
- # Runs each command specified and returns the name and exit status
83
- def process_checks
84
- codes = {}
85
- checks.each do |name, command|
86
- system("#{command} > /dev/null 2>&1")
87
- codes[name] = $CHILD_STATUS.exitstatus
88
- end
89
- codes
90
- end
91
-
92
- # Extract the codes for each check
93
- def status_codes
94
- process_checks.values.compact
95
67
  end
96
68
  end # module LocalSystem
97
69
  end # module Util
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'aws-sdk'
3
+
4
+ ::AWS.config({
5
+ :access_key_id => '1234',
6
+ :secret_access_key => '5678',
7
+ :region => 'us-east-1',
8
+ :logger => nil,
9
+ :stub_requests => true
10
+ })
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,27 @@
1
- class DummyClass
2
- end
1
+ # Track your code coverage
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ # Development code coverage
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ Coveralls::SimpleCov::Formatter,
8
+ SimpleCov::Formatter::HTMLFormatter
9
+ ]
10
+
11
+ # RSpec Configuration
12
+ RSpec.configure {|config|
13
+ # Abort the run on first failure.
14
+ config.fail_fast = true
15
+
16
+ # Use color in STDOUT
17
+ config.color = true
18
+
19
+ # Use color not only in STDOUT but also in pagers and files
20
+ config.tty = true
21
+
22
+ # Use the specified formatter
23
+ config.formatter = :documentation # :progress, :html, :textmate
24
+
25
+ # Clean up
26
+ config.after(:suite) { `ls /tmp/vscripts-test-* &> /dev/null && rm -r /tmp/vscripts-test-*` }
27
+ }