stacksondeck 0.0.1 → 1.0.0

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: 7af020e0e80ad611a868b0bf7dece614221b8dda
4
- data.tar.gz: 60e0e2d83c4e68a49f538c0257496f4e2b9a36bd
3
+ metadata.gz: eaba33fcc27c4639f0795e308e59f00e995b3220
4
+ data.tar.gz: ba4961ed10eac27f86da17fbe529982006fdafff
5
5
  SHA512:
6
- metadata.gz: 8f2025725538bb800aaf0cc8995e1d61daeff06c2216927aea55a1cc1682528a41b392094c3f8e7b997e4c18f188eb92076919d9b4eb80fc30492bb26499b495
7
- data.tar.gz: c64108bb026edff7d84e93d75ebc0a187e68f96fe7af7d7fd8754305269c06cd80f5c89f4d5bcba17b195e4ddd8ebf5bdb5b0a2bf047a5049c80c3e04677299b
6
+ metadata.gz: 06056d91ffa4d8204c12a25ac40de9f95e33719b1ee78fe74b4f6b660aa035e01f72313b8bcbb5e4d30011210896983757368a7270e86913c865b9182b7812e9
7
+ data.tar.gz: 1a0ac276bd06bfc68599a7a4ccae1aec1d5fdb14c37c0a6631b1a93d3f117ccfafc5348c16c25a3ac8435e8e13572bad70aa87ea1426727f15aac2886d02bee2
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *~
2
+ *.db
2
3
  *.log
3
4
  *.out
4
5
  *.tmp
@@ -10,6 +11,7 @@
10
11
  *.lock
11
12
  doc
12
13
  pkg
14
+ tmp
13
15
  .DS_Store
14
16
  config.json
15
17
  .bundle
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
+ gem 'thin'
6
7
  gem 'pry'
7
8
  gem 'rake'
8
9
  gem 'yard'
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ Rake::TestTask.new(:test) do |test|
10
10
  test.verbose = true
11
11
  end
12
12
 
13
- task :default => :test
13
+ task default: :test
14
14
 
15
15
 
16
16
  require 'yard'
data/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
- # Stacks (on Deck)
1
+ # Stacks on Deck ![Version](https://img.shields.io/gem/v/stacksondeck.svg?style=flat-square)
2
2
 
3
- Helpful stuff for OpenStack.
3
+ Stupid simple Chef-Rundeck integration.
4
4
 
5
5
 
6
6
  ## Usage
@@ -9,6 +9,32 @@ Helpful stuff for OpenStack.
9
9
  Commands:
10
10
  sod art # View the application art
11
11
  sod help [COMMAND] # Describe available commands or one specific command
12
+ sod server # Start application web server
12
13
  sod version # Echo the application version
13
14
 
14
- Functionality coming soon!
15
+ You're most likely inteterested in `server`:
16
+
17
+ $ sod help server
18
+ Usage:
19
+ sod server
20
+
21
+ Options:
22
+ -b, [--bind=BIND] # Set Sinatra interface
23
+ # Default: 0.0.0.0
24
+ -p, [--port=N] # Set Sinatra port
25
+ # Default: 4567
26
+ -e, [--environment=ENVIRONMENT] # Set Sinatra environment
27
+ # Default: development
28
+ -c, [--config=CONFIG] # Location of Chef configuration
29
+ # Default: /etc/chef/knife.rb
30
+ -d, [--database=DATABASE] # Location of state database
31
+ # Default: /etc/sod.db
32
+ -u, [--username=USERNAME] # Username value for Rundeck node
33
+ # Default: ${job.username}
34
+ -r, [--refresh=N] # Refresh interval in seconds
35
+ # Default: 900
36
+ -l, [--log=LOG] # Log to file instead of STDOUT
37
+ -v, [--debug], [--no-debug] # Enable DEBUG-level logging
38
+ -z, [--trace], [--no-trace] # Enable TRACE-level logging
39
+
40
+ Start application web server
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 1.0.0
@@ -0,0 +1,141 @@
1
+ require 'pathname'
2
+ require 'thread'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ require 'ridley'
7
+ require 'daybreak'
8
+ require 'sinatra/base'
9
+
10
+
11
+
12
+ module StacksOnDeck
13
+ class App < Sinatra::Application
14
+
15
+ def self.run!
16
+ open!
17
+ at_exit { close! }
18
+ Thread.new do
19
+ loop do
20
+ refresh!
21
+ sleep settings.refresh
22
+ end
23
+ end
24
+ super
25
+ end
26
+
27
+
28
+ get '/' do
29
+ content_type :yaml
30
+ @@db_dump
31
+ end
32
+
33
+
34
+
35
+ private
36
+
37
+
38
+ def self.log ; settings.log end
39
+
40
+ def log ; settings.log end
41
+
42
+
43
+ def self.db_copy
44
+ @@db.lock do
45
+ @@db.map { |_,v| v }
46
+ end
47
+ end
48
+
49
+
50
+ def self.open!
51
+ reopen!
52
+ log.debug event: 'open!', db: settings.database
53
+ @@db_dump = YAML.dump db_copy
54
+ end
55
+
56
+
57
+ def self.reopen!
58
+ old_db = @@db if defined? @@db
59
+ @@db = Daybreak::DB.new settings.database
60
+ old_db.close if old_db
61
+ end
62
+
63
+
64
+ def self.close!
65
+ log.debug event: 'close!', db: settings.database
66
+ @@db.close
67
+ end
68
+
69
+
70
+ def self.refresh!
71
+ log.debug event: 'refresh!', config: settings.config
72
+
73
+ started = Time.now
74
+
75
+ ridley = Ridley.from_chef_config settings.config
76
+
77
+ chef_server_url = ridley.server_url
78
+
79
+ nodes = ridley.partial_search :node, 'name:*', %w[
80
+ name
81
+ hostname
82
+ fqdn
83
+ roles
84
+ chef_environment
85
+ tags
86
+ kernel.machine
87
+ platform_version
88
+ platform_family
89
+ platform
90
+ ]
91
+
92
+ node_resources = {}
93
+
94
+ nodes.each do |n|
95
+ name = n.name
96
+ n = n.automatic
97
+ username = settings.username
98
+ remoteUrl = File.join chef_server_url, 'nodes', name
99
+ editUrl = File.join remoteUrl, 'edit'
100
+
101
+ tags = n.tags || []
102
+ tags += n.roles || []
103
+ tags << n.chef_environment
104
+ tags.compact!
105
+
106
+ node_resources[name] = {
107
+ 'nodename' => name,
108
+ 'hostname' => n.hostname,
109
+ 'description' => n.fqdn,
110
+ 'osArch' => n.kernel.machine,
111
+ 'osVersion' => n.platform_version,
112
+ 'osFamily' => n.platform_family,
113
+ 'osName' => n.platform,
114
+ 'username' => username,
115
+ 'remoteUrl' => remoteUrl,
116
+ 'editUrl' => editUrl,
117
+ 'tags' => tags
118
+ }
119
+ end
120
+
121
+ @@db.lock do
122
+ @@db.clear
123
+ @@db.update! node_resources
124
+ end
125
+
126
+ reopen!
127
+
128
+ @@db_dump = YAML.dump node_resources.values
129
+
130
+ log.debug event: 'refreshed!', elapsed: (Time.now - started)
131
+
132
+ return node_resources
133
+
134
+
135
+ rescue Celluloid::Task::TerminatedError
136
+ # nop
137
+ end
138
+
139
+
140
+ end
141
+ end
@@ -1,15 +1,15 @@
1
- require 'thor'
2
- require 'slog'
1
+ require 'logger'
2
+ require 'rack'
3
3
 
4
- require_relative 'helpers'
4
+ require_relative 'app'
5
+ require_relative 'mjolnir'
5
6
  require_relative 'metadata'
6
7
 
7
8
 
8
9
  module StacksOnDeck
9
10
 
10
11
  # StacksOnDeck's entrypoint.
11
- class Main < Thor
12
- include StacksOnDeck::Helpers
12
+ class Main < Mjolnir
13
13
 
14
14
 
15
15
  desc 'version', 'Echo the application version'
@@ -23,5 +23,72 @@ module StacksOnDeck
23
23
  puts "\n%s\n" % ART
24
24
  end
25
25
 
26
+
27
+ desc 'server', 'Start application web server'
28
+ option :bind, \
29
+ type: :string,
30
+ aliases: %w[ -b ],
31
+ desc: 'Set Sinatra interface',
32
+ default: '0.0.0.0'
33
+ option :port, \
34
+ type: :numeric,
35
+ aliases: %w[ -p ],
36
+ desc: 'Set Sinatra port',
37
+ default: 4567
38
+ option :environment, \
39
+ type: :string,
40
+ aliases: %w[ -e ],
41
+ desc: 'Set Sinatra environment',
42
+ default: 'development'
43
+ option :config, \
44
+ type: :string,
45
+ aliases: %w[ -c ],
46
+ desc: 'Location of Chef configuration',
47
+ default: '/etc/chef/knife.rb'
48
+ option :database, \
49
+ type: :string,
50
+ aliases: %w[ -d ],
51
+ desc: 'Location of state database',
52
+ default: '/etc/sod.db'
53
+ option :username, \
54
+ type: :string,
55
+ aliases: %w[ -u ],
56
+ desc: 'Username value for Rundeck node',
57
+ default: '${job.username}'
58
+ option :refresh, \
59
+ type: :numeric,
60
+ aliases: %w[ -r ],
61
+ desc: 'Refresh interval in seconds',
62
+ default: 900
63
+ include_common_options
64
+ def server
65
+ App.set :log, log
66
+ App.set :bind, options.bind
67
+ App.set :port, options.port
68
+ App.set :config, options.config
69
+ App.set :refresh, options.refresh
70
+ App.set :database, options.database
71
+ App.set :username, options.username
72
+ App.set :environment, options.environment
73
+
74
+ if options.debug?
75
+ App.set :raise_errors, true
76
+ App.set :dump_errors, true
77
+ App.set :show_exceptions, true
78
+ App.set :logging, ::Logger::DEBUG
79
+ end
80
+
81
+ Celluloid.logger = nil
82
+ Thread.abort_on_exception = false
83
+
84
+ if options.trace?
85
+ Celluloid.logger = log
86
+ Thread.abort_on_exception = true
87
+ end
88
+
89
+ log.debug event: 'server starting', options: options
90
+ App.run!
91
+ end
92
+
26
93
  end
27
94
  end
@@ -4,7 +4,7 @@ module StacksOnDeck
4
4
  NAME = 'stacksondeck'
5
5
 
6
6
  # A quick summary for use in the command-line interface
7
- SUMMARY = %q.Helpful stuff for OpenStack.
7
+ SUMMARY = %q.Stupid simple Chef-Rundeck integration.
8
8
 
9
9
  # Take credit for your work
10
10
  AUTHOR = 'Sean Clemmer'
@@ -0,0 +1,77 @@
1
+ require 'slog'
2
+ require 'thor'
3
+
4
+
5
+ module StacksOnDeck
6
+
7
+ # Thor's hammer! Like Thor with better logging
8
+ class Mjolnir < Thor
9
+
10
+ # Common options for Thor commands
11
+ COMMON_OPTIONS = {
12
+ log: {
13
+ type: :string,
14
+ aliases: %w[ -l ],
15
+ desc: 'Log to file instead of STDOUT',
16
+ default: ENV['SOD_LOG'] || nil
17
+ },
18
+ debug: {
19
+ type: :boolean,
20
+ aliases: %w[ -v ],
21
+ desc: 'Enable DEBUG-level logging',
22
+ default: ENV['SOD_DEBUG'] || false
23
+ },
24
+ trace: {
25
+ type: :boolean,
26
+ aliases: %w[ -z ],
27
+ desc: 'Enable TRACE-level logging',
28
+ default: ENV['SOD_TRACE'] || false
29
+ }
30
+ }
31
+
32
+ # Decorate Thor commands with the options above
33
+ def self.include_common_options
34
+ COMMON_OPTIONS.each do |name, spec|
35
+ option name, spec
36
+ end
37
+ end
38
+
39
+
40
+ no_commands do
41
+
42
+ # Return a connection to the given OpenStack service
43
+ def os service
44
+ @os ||= {}
45
+ return @os[service] if @os.has_key? service
46
+ @os[service] = OpenStack::Connection.create \
47
+ auth_url: options.auth_url,
48
+ auth_method: options.auth_method,
49
+ authtenant_id: options.auth_tenant,
50
+ username: options.auth_user,
51
+ api_key: options.auth_pass,
52
+ service_type: service
53
+ log.trace \
54
+ event: 'OpenStack connection',
55
+ service: service
56
+ return @os[service]
57
+ end
58
+
59
+
60
+ # Construct a Logger given the command-line options
61
+ def log
62
+ return @logger if defined? @logger
63
+ level = :info
64
+ level = :debug if options.debug?
65
+ level = :trace if options.trace?
66
+ device = options.log || $stderr
67
+ pretty = device.tty? rescue false
68
+ @logger = Slog.new \
69
+ out: device,
70
+ level: level,
71
+ colorize: pretty,
72
+ prettify: pretty
73
+ end
74
+
75
+ end
76
+ end
77
+ end
data/stacksondeck.gemspec CHANGED
@@ -15,6 +15,10 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_runtime_dependency 'thor', '~> 0'
17
17
  s.add_runtime_dependency 'slog', '~> 1'
18
+ s.add_runtime_dependency 'hashie', '~> 2'
19
+ s.add_runtime_dependency 'sinatra', '~> 1.4'
20
+ s.add_runtime_dependency 'daybreak', '~> 0.3'
21
+ s.add_runtime_dependency 'ridley', '~> 4.1'
18
22
 
19
23
  s.files = `git ls-files`.split("\n")
20
24
  s.test_files = `git ls-files -- test/*`.split("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stacksondeck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -38,7 +38,63 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1'
41
- description: Helpful stuff for OpenStack.
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: daybreak
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ridley
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.1'
97
+ description: Stupid simple Chef-Rundeck integration.
42
98
  email: sczizzo@gmail.com
43
99
  executables:
44
100
  - sod
@@ -53,9 +109,10 @@ files:
53
109
  - VERSION
54
110
  - bin/sod
55
111
  - lib/stacksondeck.rb
56
- - lib/stacksondeck/helpers.rb
112
+ - lib/stacksondeck/app.rb
57
113
  - lib/stacksondeck/main.rb
58
114
  - lib/stacksondeck/metadata.rb
115
+ - lib/stacksondeck/mjolnir.rb
59
116
  - stacksondeck.gemspec
60
117
  - test/test_stacksondeck.rb
61
118
  homepage: https://github.com/sczizzo/stacksondeck
@@ -81,6 +138,6 @@ rubyforge_project:
81
138
  rubygems_version: 2.2.2
82
139
  signing_key:
83
140
  specification_version: 4
84
- summary: Helpful stuff for OpenStack
141
+ summary: Stupid simple Chef-Rundeck integration
85
142
  test_files:
86
143
  - test/test_stacksondeck.rb
@@ -1,28 +0,0 @@
1
- require 'thor/util'
2
- require 'thor/actions'
3
-
4
-
5
- module StacksOnDeck
6
-
7
- # Mixins for StacksOnDeck's Thor subclasses.
8
- module Helpers
9
-
10
- # Save the canonical implementation of "puts"
11
- alias_method :old_puts, :puts
12
-
13
- # Monkeypatch puts to support Thor::Shell::Color.
14
- def puts *args
15
- return old_puts if args.empty?
16
- old_puts shell.set_color(*args)
17
- end
18
-
19
-
20
- # Shortcut for Thor::Util.
21
- def util ; Thor::Util end
22
-
23
-
24
- # Shortcut for Thor::Actions.
25
- def actions ; Thor::Actions end
26
-
27
- end
28
- end