blender-salt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d57b4ae61c37e5646f55c00477aa87caccb4d2b4
4
+ data.tar.gz: 6a3e929838d57cb1462f767cd01407f370dbe5a1
5
+ SHA512:
6
+ metadata.gz: fa1f2c3c72d62cb22ec7a811ac091ca62367899a0804bba1d3cd9cd91a03f260e2911d07046eefcde4eb96bee69150320ade0f547761fc5d00d699e965773193
7
+ data.tar.gz: c55f7c8496bd533704501ecf903cb6bb6523a60251eb75b66f7ab204f58208b8c19dd07909b658941f2a7d1ec553b083c0071579908673545787ba0e123ab282
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,13 @@
1
+ Metrics/AbcSize:
2
+ Description: >-
3
+ A calculated magnitude based on number of assignments,
4
+ branches, and conditions.
5
+ Reference: 'http://c2.com/cgi/wiki?AbcMetric'
6
+ Enabled: true
7
+ Max: 24
8
+
9
+ Metrics/MethodLength:
10
+ Description: 'Avoid methods longer than 10 lines of code.'
11
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#short-methods'
12
+ Enabled: true
13
+ Max: 16
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
5
+ cache: bundler
6
+ branches:
7
+ only:
8
+ - master
@@ -0,0 +1,7 @@
1
+ blender-salt gem CHANGELOG
2
+ ======================
3
+ This file is used to list changes made in each version of the blender-salt gem.
4
+
5
+ v0.1.0 (2016-01-08)
6
+ -------------------
7
+ - Initial gem publish
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blender-salt.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ Copyright:: Copyright (c) 2015 Grant Ridder
2
+ License:: Apache License, Version 2.0
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
@@ -0,0 +1,79 @@
1
+ # Blender::Salt
2
+
3
+ [![Build Status](https://travis-ci.org/shortdudey123/blender-salt.svg?branch=master)](https://travis-ci.org/shortdudey123/blender-salt)
4
+ [![Gem Version](http://img.shields.io/gem/v/blender-salt.svg)](https://rubygems.org/gems/blender-salt)
5
+ [![Coverage Status](https://img.shields.io/coveralls/shortdudey123/blender-salt/master.svg)](https://coveralls.io/r/shortdudey123/blender-salt?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/shortdudey123/blender-salt/badges/gpa.svg)](https://codeclimate.com/github/shortdudey123/blender-salt)
7
+ [![Dependency Status](https://img.shields.io/gemnasium/shortdudey123/blender-salt.svg)](https://gemnasium.com/shortdudey123/blender-salt)
8
+
9
+ Provides [Salt](https://saltstack.com/) command execution for [Blender](https://github.com/PagerDuty/blender)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'blender-salt'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install blender-salt
26
+
27
+ ## Usage
28
+
29
+ ### Config
30
+
31
+ Blender-salt uses the salt-api interface to remotely execute salt commands. This requires that salt-api be installed and running on the salt master.
32
+
33
+ - host (salt master)
34
+ - port (port that salt-api is listening on)
35
+ - username (PAM user that can execute salt commands)
36
+ - password (password for specified user)
37
+ - ssl (connect to the salt-api via ssl)
38
+
39
+ Example
40
+ ```ruby
41
+ config(:salt, host: 'localhost', port: 12345, username: 'foo', password: 'bar')
42
+ ```
43
+
44
+ ### Using Salt for command execution
45
+
46
+ ```ruby
47
+ require 'blender/salt'
48
+ extend Blender::SaltDSL
49
+ config(:salt, host: 'localhost', port: 12345, username: 'foo', password: 'bar')
50
+ members(['node1', 'node2', 'node3'])
51
+ salt_task 'test.ping'
52
+ ```
53
+
54
+ ```ruby
55
+ require 'blender/salt'
56
+ extend Blender::SaltDSL
57
+ config(:salt, host: 'localhost', port: 12345, username: 'foo', password: 'bar')
58
+
59
+ salt_task 'system.shutdown' do
60
+ arguments 5
61
+ members ['node1', 'node2', 'node3']
62
+ end
63
+ ```
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shortdudey123/blender-salt.
74
+
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [Apache 2 License](http://opensource.org/licenses/Apache-2.0).
79
+
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc 'rubocop compliancy checks'
8
+ RuboCop::RakeTask.new(:rubocop) do |t|
9
+ t.patterns = %w(
10
+ lib/**/*.rb
11
+ lib/*.rb
12
+ spec/*.rb
13
+ spec/**/.rb
14
+ Rakefile
15
+ *.gemspec
16
+ )
17
+ end
18
+
19
+ task default: [:rubocop, :spec]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "blender/salt"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blender/salt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'blender-salt'
8
+ spec.version = Blender::Salt::VERSION
9
+ spec.authors = ['Grant Ridder']
10
+ spec.email = ['shortdudey123@gmail.com']
11
+ spec.summary = 'Salt backend for blender'
12
+ spec.description = 'Execute tasks using Salt'
13
+ spec.homepage = ''
14
+ spec.license = 'Apache 2'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'pd-blender'
25
+ spec.add_dependency 'salt_client'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.10'
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'rubocop'
33
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Author:: Grant Ridder (<shortdudey123@gail.com>)
3
+ # Copyright:: Copyright (c) 2015 Grant Ridder
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'salt_client'
19
+ require 'blender/exceptions'
20
+ require 'blender/log'
21
+ require 'blender/drivers/base'
22
+
23
+ module Blender
24
+ module Driver
25
+ # Salt driver for Blender
26
+ class Salt < Base
27
+ attr_reader :concurrency, :ssl
28
+
29
+ def initialize(config = {})
30
+ cfg = config.dup
31
+ @concurrency = cfg.delete(:concurrency) || 1
32
+ @ssl = cfg.delete(:ssl) || false
33
+ super(cfg)
34
+ end
35
+
36
+ def salt_call(command, host)
37
+ responses = []
38
+ http_scheme = @ssl ? 'https' : 'http'
39
+ salt_server_url = "#{http_scheme}://#{config[:host]}:#{config[:port]}"
40
+ Log.debug("Invoking sall call '#{command.function}' with arguments "\
41
+ "'#{command.arguments}' against #{host}")
42
+ Log.debug("Salt server address #{salt_server_url}")
43
+ client = SaltClient::Client.new salt_server_url,
44
+ config[:username],
45
+ config[:password]
46
+
47
+ host.each do |h|
48
+ event = client.call(h, command.function, command.arguments)
49
+ responses << event
50
+ stdout.puts event.inspect
51
+ Log.info("Results for #{command.inspect}: #{event}")
52
+ end
53
+ responses
54
+ end
55
+
56
+ def run_command(command, nodes)
57
+ responses = salt_call(command, nodes)
58
+ command.process.call(responses) if command.process
59
+ exit_status(responses, nodes)
60
+ rescue StandardError => e
61
+ ExecOutput.new(-1, '', e.message)
62
+ end
63
+
64
+ def exit_status(responses, nodes)
65
+ if responses.size == nodes.size
66
+ ExecOutput.new(0, responses.inspect, '')
67
+ else
68
+ ExecOutput.new(-1, '', 'Insufficient number of responses. '\
69
+ "Expected:#{nodes.size}, Got:#{responses.size}")
70
+ end
71
+ end
72
+
73
+ def execute(tasks, hosts)
74
+ Log.debug("Salt call on [#{hosts.inspect}]")
75
+ tasks.each do |task|
76
+ hosts.each_slice(concurrency) do |nodes|
77
+ cmd = run_command(task.command, nodes)
78
+ if cmd.exitstatus != 0 && !task.metadata[:ignore_failure]
79
+ fail ExecutionFailed, cmd.stderr
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Author:: Grant Ridder (<shortdudey123@gail.com>)
3
+ # Copyright:: Copyright (c) 2015 Grant Ridder
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'blender/drivers/salt'
19
+ require 'blender/tasks/salt'
20
+ require 'blender/salt_dsl'
@@ -0,0 +1,23 @@
1
+ #
2
+ # Author:: Grant Ridder (<shortdudey123@gail.com>)
3
+ # Copyright:: Copyright (c) 2015 Grant Ridder
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Blender
19
+ # Salt Blender integration
20
+ module Salt
21
+ VERSION = '0.1.0'
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Author:: Grant Ridder (<shortdudey123@gail.com>)
3
+ # Copyright:: Copyright (c) 2015 Grant Ridder
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Blender
19
+ # DSL for Salt Blender integration
20
+ module SaltDSL
21
+ def salt_task(name, &block)
22
+ task = build_task(name, :salt)
23
+ task.instance_eval(&block) if block_given?
24
+ append_task(:salt, task)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Grant Ridder (<shortdudey123@gail.com>)
3
+ # Copyright:: Copyright (c) 2015 Grant Ridder
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'blender/tasks/base'
19
+
20
+ module Blender
21
+ module Task
22
+ # Salt blender task
23
+ class Salt < Blender::Task::Base
24
+ SaltCall = Struct.new(:target, :function, :arguments, :process)
25
+
26
+ attr_reader :command
27
+
28
+ def initialize(name, metadata = {})
29
+ super
30
+ @command = SaltCall.new
31
+ @command.function = name
32
+ end
33
+
34
+ def target(t)
35
+ @command.target = t
36
+ end
37
+
38
+ def function(f)
39
+ @command.function = f
40
+ end
41
+
42
+ def arguments(a)
43
+ @command.arguments = a
44
+ end
45
+
46
+ def process(&block)
47
+ @command.process = block if block
48
+ end
49
+
50
+ def execute(&block)
51
+ @command.instance_eval(&block)
52
+ end
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blender-salt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Grant Ridder
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pd-blender
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: salt_client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Execute tasks using Salt
126
+ email:
127
+ - shortdudey123@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".travis.yml"
137
+ - CHANGELOG.md
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - blender-salt.gemspec
145
+ - lib/blender/drivers/salt.rb
146
+ - lib/blender/salt.rb
147
+ - lib/blender/salt/version.rb
148
+ - lib/blender/salt_dsl.rb
149
+ - lib/blender/tasks/salt.rb
150
+ homepage: ''
151
+ licenses:
152
+ - Apache 2
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.4.5
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Salt backend for blender
174
+ test_files: []