smart_proxy_salt 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/foreman-node +6 -3
- data/lib/smart_proxy_salt/cli.rb +5 -7
- data/lib/smart_proxy_salt/rest.rb +1 -0
- data/lib/smart_proxy_salt/salt.rb +5 -5
- data/lib/smart_proxy_salt/salt_runner.rb +2 -0
- data/lib/smart_proxy_salt/salt_task_launcher.rb +2 -0
- data/lib/smart_proxy_salt/version.rb +1 -1
- data/salt/report_upload/README.md +3 -3
- data/salt/report_upload/srv/salt/_runners/foreman_report_upload.py +29 -1
- data/sbin/upload-salt-reports +1 -1
- metadata +13 -92
- data/bin/salt_python_wrapper +0 -16
- data/cron/smart_proxy_salt +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea43480d38aa6f8d3694e61899d0b5dadeacaacc775a82d8ab2a456810bb8bcd
|
4
|
+
data.tar.gz: 6101554d6bf03679d29399f4ad92fbc51c4bfe1250e928433eca682ad015bac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de7cddee069d666c6cc4a7400c2df16d647c4e244286a0376e8c1416555c85e1d295975017b28041305be31e2cbe02343c9da5e9688c8666b8141c0d1a8fbb1
|
7
|
+
data.tar.gz: 30464b1b58712d5a022c49b4e104fe29e5b82ad44d356cd50d59fb3b54dca0ce6b8fc7ead55e93f6ecf193c24a04782a924fbc650129c570b4606bf04f5b4408
|
data/bin/foreman-node
CHANGED
@@ -45,7 +45,7 @@ end
|
|
45
45
|
|
46
46
|
def get_grains(minion)
|
47
47
|
grains = {
|
48
|
-
:name
|
48
|
+
:name => minion,
|
49
49
|
:facts => plain_grains(minion).merge(:_timestamp => Time.now, :_type => 'foreman_salt')
|
50
50
|
}
|
51
51
|
|
@@ -94,9 +94,10 @@ end
|
|
94
94
|
def plainify(hash, prefix = nil)
|
95
95
|
result = []
|
96
96
|
hash.each_pair do |key, value|
|
97
|
-
|
97
|
+
case value
|
98
|
+
when Hash
|
98
99
|
result.push plainify(value, get_key(key, prefix))
|
99
|
-
|
100
|
+
when Array
|
100
101
|
result.push plainify(array_to_hash(value), get_key(key, prefix))
|
101
102
|
else
|
102
103
|
new = {}
|
@@ -169,12 +170,14 @@ def enc(minion)
|
|
169
170
|
res = http.start { |conn| conn.request(req) }
|
170
171
|
|
171
172
|
raise "Error retrieving node #{minion}: #{res.class}\nCheck Foreman's /var/log/foreman/production.log for more information." unless res.code == '200'
|
173
|
+
|
172
174
|
res.body
|
173
175
|
end
|
174
176
|
|
175
177
|
minion = ARGV[0] || raise('Must provide minion as an argument')
|
176
178
|
|
177
179
|
raise 'Invalid hostname' unless valid_hostname? minion
|
180
|
+
|
178
181
|
begin
|
179
182
|
result = ''
|
180
183
|
|
data/lib/smart_proxy_salt/cli.rb
CHANGED
@@ -56,16 +56,15 @@ module Proxy
|
|
56
56
|
|
57
57
|
def autosign_list
|
58
58
|
return [] unless File.exist?(autosign_file)
|
59
|
+
|
59
60
|
File.read(autosign_file).split("\n").reject do |v|
|
60
61
|
v =~ /^\s*#.*|^$/ ## Remove comments and empty lines
|
61
62
|
end.map(&:chomp)
|
62
63
|
end
|
63
64
|
|
64
65
|
def append_value_to_file(filepath, value)
|
65
|
-
File.open(filepath, File::CREAT|File::RDWR) do |file|
|
66
|
-
unless file.any? { |line| line.chomp == value}
|
67
|
-
file.puts value
|
68
|
-
end
|
66
|
+
File.open(filepath, File::CREAT | File::RDWR) do |file|
|
67
|
+
file.puts value unless file.any? { |line| line.chomp == value }
|
69
68
|
end
|
70
69
|
logger.info "Added an entry to '#{filepath}' successfully."
|
71
70
|
true
|
@@ -75,7 +74,6 @@ module Proxy
|
|
75
74
|
end
|
76
75
|
|
77
76
|
def remove_value_from_file(filepath, value)
|
78
|
-
|
79
77
|
return true unless File.exist?(filepath)
|
80
78
|
|
81
79
|
found = false
|
@@ -84,14 +82,14 @@ module Proxy
|
|
84
82
|
if entry == value
|
85
83
|
found = true
|
86
84
|
nil
|
87
|
-
elsif entry ==
|
85
|
+
elsif entry == ''
|
88
86
|
nil
|
89
87
|
else
|
90
88
|
line
|
91
89
|
end
|
92
90
|
end.uniq.compact
|
93
91
|
if found
|
94
|
-
File.write(filepath, entries.join
|
92
|
+
File.write(filepath, entries.join)
|
95
93
|
logger.info "Removed an entry from '#{filepath}' successfully."
|
96
94
|
end
|
97
95
|
true
|
@@ -12,11 +12,11 @@ module Proxy
|
|
12
12
|
class Plugin < ::Proxy::Plugin
|
13
13
|
plugin 'salt', Proxy::Salt::VERSION
|
14
14
|
|
15
|
-
default_settings :autosign_file
|
16
|
-
:autosign_key_file
|
17
|
-
:salt_command_user
|
18
|
-
:use_api
|
19
|
-
:saltfile
|
15
|
+
default_settings :autosign_file => '/etc/salt/autosign.conf',
|
16
|
+
:autosign_key_file => '/var/lib/foreman-proxy/salt/grains/autosign_key',
|
17
|
+
:salt_command_user => 'root',
|
18
|
+
:use_api => false,
|
19
|
+
:saltfile => '/etc/foreman-proxy/settings.d/salt.saltfile'
|
20
20
|
|
21
21
|
requires :dynflow, '>= 0.5.0'
|
22
22
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# Foreman Salt Report Upload
|
2
2
|
|
3
3
|
Currently, there are two possibilites to upload the salt report to Foreman:
|
4
|
-
1.
|
5
|
-
2.
|
4
|
+
1. Upload the report immediately by using a Salt Reactor (recommended).
|
5
|
+
2. Use /usr/sbin/upload-salt-reports manually (or set up a cronjob, see `/cron/smart_proxy_salt`).
|
6
6
|
|
7
|
-
This README
|
7
|
+
This README handles the first option and how to configure it
|
8
8
|
|
9
9
|
## Setup
|
10
10
|
Add the content of 'master.snippet' to '/etc/salt/master' which configures a reactor.
|
@@ -4,13 +4,16 @@ Uploads reports from the Salt job cache to Foreman
|
|
4
4
|
'''
|
5
5
|
from __future__ import absolute_import, print_function, unicode_literals
|
6
6
|
|
7
|
+
LAST_UPLOADED = '/etc/salt/last_uploaded'
|
7
8
|
FOREMAN_CONFIG = '/etc/salt/foreman.yaml'
|
9
|
+
LOCK_FILE = '/var/lock/salt-report-upload.lock'
|
8
10
|
|
9
11
|
try:
|
10
12
|
from http.client import HTTPConnection, HTTPSConnection
|
11
13
|
except ImportError:
|
12
14
|
from httplib import HTTPSConnection, HTTPSConnection
|
13
15
|
|
16
|
+
import io
|
14
17
|
import ssl
|
15
18
|
import json
|
16
19
|
import yaml
|
@@ -24,12 +27,21 @@ import logging
|
|
24
27
|
log = logging.getLogger(__name__)
|
25
28
|
|
26
29
|
|
30
|
+
if sys.version_info.major == 3:
|
31
|
+
unicode = str
|
32
|
+
|
33
|
+
|
27
34
|
def salt_config():
|
28
35
|
with open(FOREMAN_CONFIG, 'r') as f:
|
29
36
|
config = yaml.load(f.read())
|
30
37
|
return config
|
31
38
|
|
32
39
|
|
40
|
+
def write_last_uploaded(last_uploaded):
|
41
|
+
with io.open(LAST_UPLOADED, 'w+') as f:
|
42
|
+
f.write(unicode(last_uploaded))
|
43
|
+
|
44
|
+
|
33
45
|
def upload(report):
|
34
46
|
config = salt_config()
|
35
47
|
headers = {'Accept': 'application/json',
|
@@ -55,6 +67,7 @@ def upload(report):
|
|
55
67
|
response = connection.getresponse()
|
56
68
|
|
57
69
|
if response.status == 200:
|
70
|
+
write_last_uploaded(report['job']['job_id'])
|
58
71
|
info_msg = 'Success {0}: {1}'.format(report['job']['job_id'], response.read())
|
59
72
|
log.info(info_msg)
|
60
73
|
else:
|
@@ -81,7 +94,7 @@ def create_report(json_str):
|
|
81
94
|
return {'job':
|
82
95
|
{
|
83
96
|
'result': {
|
84
|
-
msg['id']: entry['changes']
|
97
|
+
msg['id']: next(iter(entry['changes'].values())),
|
85
98
|
},
|
86
99
|
'function': 'state.highstate',
|
87
100
|
'job_id': msg['jid']
|
@@ -90,6 +103,18 @@ def create_report(json_str):
|
|
90
103
|
raise Exception('No state.highstate found')
|
91
104
|
|
92
105
|
|
106
|
+
def get_lock():
|
107
|
+
if os.path.isfile(LOCK_FILE):
|
108
|
+
raise Exception("Unable to obtain lock.")
|
109
|
+
else:
|
110
|
+
io.open(LOCK_FILE, 'w+').close()
|
111
|
+
|
112
|
+
|
113
|
+
def release_lock():
|
114
|
+
if os.path.isfile(LOCK_FILE):
|
115
|
+
os.remove(LOCK_FILE)
|
116
|
+
|
117
|
+
|
93
118
|
def now(highstate):
|
94
119
|
'''
|
95
120
|
Upload a highstate to Foreman
|
@@ -100,7 +125,10 @@ def now(highstate):
|
|
100
125
|
|
101
126
|
try:
|
102
127
|
report = create_report(base64.b64decode(highstate))
|
128
|
+
get_lock()
|
103
129
|
upload(report)
|
104
130
|
except Exception as exc:
|
105
131
|
log.error('Exception encountered: %s', exc)
|
132
|
+
finally:
|
133
|
+
release_lock()
|
106
134
|
|
data/sbin/upload-salt-reports
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_salt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Moll
|
@@ -9,96 +9,15 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '2'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '2'
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: mocha
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '1'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '1'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: webmock
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '1'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '1'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rake
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '13'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '13'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: rubocop
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - '='
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 0.50.0
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - '='
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 0.50.0
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: rack-test
|
15
|
+
name: smart_proxy_dynflow
|
86
16
|
requirement: !ruby/object:Gem::Requirement
|
87
17
|
requirements:
|
88
18
|
- - "~>"
|
89
19
|
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: smart_proxy_dynflow
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
20
|
+
version: '0.5'
|
102
21
|
- - ">="
|
103
22
|
- !ruby/object:Gem::Version
|
104
23
|
version: 0.5.0
|
@@ -106,14 +25,16 @@ dependencies:
|
|
106
25
|
prerelease: false
|
107
26
|
version_requirements: !ruby/object:Gem::Requirement
|
108
27
|
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0.5'
|
109
31
|
- - ">="
|
110
32
|
- !ruby/object:Gem::Version
|
111
33
|
version: 0.5.0
|
112
|
-
description:
|
34
|
+
description: This plug-in adds support for Salt to Foreman's Smart Proxy
|
113
35
|
email: foreman-dev@googlegroups.com
|
114
36
|
executables:
|
115
37
|
- foreman-node
|
116
|
-
- salt_python_wrapper
|
117
38
|
extensions: []
|
118
39
|
extra_rdoc_files:
|
119
40
|
- README.md
|
@@ -122,9 +43,7 @@ files:
|
|
122
43
|
- LICENSE
|
123
44
|
- README.md
|
124
45
|
- bin/foreman-node
|
125
|
-
- bin/salt_python_wrapper
|
126
46
|
- bundler.d/salt.rb
|
127
|
-
- cron/smart_proxy_salt
|
128
47
|
- etc/foreman.conf.example
|
129
48
|
- etc/foreman.yaml.example
|
130
49
|
- lib/smart_proxy_salt.rb
|
@@ -161,15 +80,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
80
|
requirements:
|
162
81
|
- - ">="
|
163
82
|
- !ruby/object:Gem::Version
|
164
|
-
version: '
|
83
|
+
version: '2.7'
|
84
|
+
- - "<"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '4'
|
165
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
88
|
requirements:
|
167
89
|
- - ">="
|
168
90
|
- !ruby/object:Gem::Version
|
169
91
|
version: '0'
|
170
92
|
requirements: []
|
171
|
-
|
172
|
-
rubygems_version: 2.7.6
|
93
|
+
rubygems_version: 3.3.26
|
173
94
|
signing_key:
|
174
95
|
specification_version: 4
|
175
96
|
summary: SaltStack Plug-In for Foreman's Smart Proxy
|
data/bin/salt_python_wrapper
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
set -u
|
4
|
-
|
5
|
-
for py in 'python3' 'python'; do
|
6
|
-
exe=$(type -p ${py})
|
7
|
-
if [ -n "${exe}" ]; then
|
8
|
-
if ${exe} -c 'import salt.config'; then
|
9
|
-
${exe} "$@"
|
10
|
-
exit $?
|
11
|
-
fi
|
12
|
-
fi
|
13
|
-
done
|
14
|
-
|
15
|
-
echo "No usable python version found, check if python or python3 can import salt.config!" 1>&2
|
16
|
-
exit 1
|
data/cron/smart_proxy_salt
DELETED