smart_proxy_salt 3.1.1 → 3.1.2
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 +1 -1
- data/lib/smart_proxy_salt/version.rb +1 -1
- data/salt/report_upload/srv/salt/_runners/foreman_report_upload.py +16 -2
- data/salt/report_upload/srv/salt/foreman_report_upload.sls +8 -4
- data/sbin/upload-salt-reports +11 -6
- metadata +2 -6
- data/lib/smart_proxy_salt_core.rb +0 -17
- data/lib/smart_proxy_salt_core/salt_runner.rb +0 -51
- data/lib/smart_proxy_salt_core/salt_task_launcher.rb +0 -21
- data/lib/smart_proxy_salt_core/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c5e6d0a2348b06d27789269578966ec1b2ae1413341ca1dc5bb318630653c44
|
4
|
+
data.tar.gz: 8238c8469d73c893ead9a9cba3692652b9227a5aa6bdc400cc53e1c83e28e7db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2873b74a8f42b9e979c38da137674d92e3d0cccdfea62924d27b89ca3c76f4ffc3a5ed961c3e9935311ca1ca51868e44f4315d3cd4d86752d315de0434955b62
|
7
|
+
data.tar.gz: '091bdeb081d90458404ad84baba32db5830b170a28678f554174030722563935186e7fd9abcb52fa743edf5148aae76b65177e7e13e5b2113f48fb0f8f1c8b75'
|
data/bin/foreman-node
CHANGED
@@ -61,7 +61,7 @@ def plain_grains(minion)
|
|
61
61
|
# We have to get the grains from the cache, because the client
|
62
62
|
# is probably running 'state.highstate' right now.
|
63
63
|
|
64
|
-
result = IO.popen(['salt-run', '--output=json', 'cache.grains', minion]) do |io|
|
64
|
+
result = IO.popen(['salt-run', '-l', 'quiet', '--output=json', 'cache.grains', minion]) do |io|
|
65
65
|
io.read
|
66
66
|
end
|
67
67
|
|
@@ -65,7 +65,8 @@ def upload(report):
|
|
65
65
|
def create_report(json_str):
|
66
66
|
msg = json.loads(json_str)
|
67
67
|
|
68
|
-
|
68
|
+
if msg['fun'] == 'state.highstate':
|
69
|
+
return {'job':
|
69
70
|
{
|
70
71
|
'result': {
|
71
72
|
msg['id']: msg['return'],
|
@@ -74,6 +75,19 @@ def create_report(json_str):
|
|
74
75
|
'job_id': msg['jid']
|
75
76
|
}
|
76
77
|
}
|
78
|
+
elif msg['fun'] == 'state.template_str':
|
79
|
+
for key, entry in msg['return'].items():
|
80
|
+
if key.startswith('module_') and entry['__id__'] == 'state.highstate':
|
81
|
+
return {'job':
|
82
|
+
{
|
83
|
+
'result': {
|
84
|
+
msg['id']: entry['changes']['ret'],
|
85
|
+
},
|
86
|
+
'function': 'state.highstate',
|
87
|
+
'job_id': msg['jid']
|
88
|
+
}
|
89
|
+
}
|
90
|
+
raise Exception('No state.highstate found')
|
77
91
|
|
78
92
|
|
79
93
|
def now(highstate):
|
@@ -85,7 +99,7 @@ def now(highstate):
|
|
85
99
|
log.debug('Upload highstate to Foreman')
|
86
100
|
|
87
101
|
try:
|
88
|
-
report = create_report(highstate)
|
102
|
+
report = create_report(base64.decodestring(highstate))
|
89
103
|
upload(report)
|
90
104
|
except Exception as exc:
|
91
105
|
log.error('Exception encountered: %s', exc)
|
@@ -1,6 +1,10 @@
|
|
1
|
-
{% if 'cmd' in data and data['cmd'] == '_return' and 'fun' in data and
|
2
|
-
|
1
|
+
{% if 'cmd' in data and data['cmd'] == '_return' and 'fun' in data and (
|
2
|
+
data['fun'] == 'state.highstate' or (data['fun'] == 'state.template_str' and
|
3
|
+
'fun_args' in data and
|
4
|
+
data['fun_args'][0].startswith('state.highstate:')
|
5
|
+
)) %}
|
6
|
+
foreman_report_upload:
|
3
7
|
runner.foreman_report_upload.now:
|
4
|
-
- args:
|
5
|
-
- highstate: '{{data|json}}'
|
8
|
+
- args:
|
9
|
+
- highstate: '{{data|json|base64_encode}}'
|
6
10
|
{% endif %}
|
data/sbin/upload-salt-reports
CHANGED
@@ -18,12 +18,13 @@ import io
|
|
18
18
|
import os
|
19
19
|
import sys
|
20
20
|
import base64
|
21
|
-
|
22
21
|
import traceback
|
23
|
-
|
24
22
|
import salt.config
|
25
23
|
import salt.runner
|
26
24
|
|
25
|
+
if sys.version_info.major == 3:
|
26
|
+
unicode = str
|
27
|
+
|
27
28
|
|
28
29
|
def salt_config():
|
29
30
|
with io.open(FOREMAN_CONFIG, 'r') as f:
|
@@ -39,6 +40,11 @@ def get_job(job_id):
|
|
39
40
|
for minion, value in result.items():
|
40
41
|
if type(value) == str:
|
41
42
|
result[minion] = [value]
|
43
|
+
else:
|
44
|
+
for key, entry in value.items():
|
45
|
+
if key.startswith('module_') and entry['__id__'] == 'state.highstate':
|
46
|
+
result[minion] = entry['changes']['ret']
|
47
|
+
break
|
42
48
|
|
43
49
|
return {'job':
|
44
50
|
{
|
@@ -66,7 +72,7 @@ def read_last_uploaded():
|
|
66
72
|
|
67
73
|
def write_last_uploaded(last_uploaded):
|
68
74
|
with io.open(LAST_UPLOADED, 'w+') as f:
|
69
|
-
f.write(last_uploaded)
|
75
|
+
f.write(unicode(last_uploaded))
|
70
76
|
|
71
77
|
|
72
78
|
def run(*args, **kwargs):
|
@@ -85,12 +91,11 @@ def run(*args, **kwargs):
|
|
85
91
|
|
86
92
|
def jobs_to_upload():
|
87
93
|
jobs = run('jobs.list_jobs', kwarg={
|
88
|
-
"search_function": "state.highstate",
|
94
|
+
"search_function": ["state.highstate","state.template_str"],
|
89
95
|
})
|
90
96
|
last_uploaded = read_last_uploaded()
|
91
97
|
|
92
|
-
job_ids = [jid for
|
93
|
-
if int(jid) > last_uploaded]
|
98
|
+
job_ids = [jid for jid in jobs.keys() if int(jid) > last_uploaded]
|
94
99
|
|
95
100
|
for job_id in sorted(job_ids):
|
96
101
|
yield job_id, get_job(job_id)
|
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: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Moll
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -118,10 +118,6 @@ files:
|
|
118
118
|
- lib/smart_proxy_salt/salt_api.rb
|
119
119
|
- lib/smart_proxy_salt/salt_http_config.ru
|
120
120
|
- lib/smart_proxy_salt/version.rb
|
121
|
-
- lib/smart_proxy_salt_core.rb
|
122
|
-
- lib/smart_proxy_salt_core/salt_runner.rb
|
123
|
-
- lib/smart_proxy_salt_core/salt_task_launcher.rb
|
124
|
-
- lib/smart_proxy_salt_core/version.rb
|
125
121
|
- salt/report_upload/README.md
|
126
122
|
- salt/report_upload/master.snippet
|
127
123
|
- salt/report_upload/srv/salt/_runners/foreman_report_upload.py
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_core'
|
2
|
-
require 'foreman_remote_execution_core'
|
3
|
-
|
4
|
-
module SmartProxySaltCore
|
5
|
-
extend ForemanTasksCore::SettingsLoader
|
6
|
-
register_settings(:salt,
|
7
|
-
:saltfile => '/etc/foreman-proxy/settings.d/salt.saltfile')
|
8
|
-
|
9
|
-
if ForemanTasksCore.dynflow_present?
|
10
|
-
require 'smart_proxy_salt_core/salt_runner'
|
11
|
-
require 'smart_proxy_salt_core/salt_task_launcher'
|
12
|
-
|
13
|
-
if defined?(SmartProxyDynflowCore)
|
14
|
-
SmartProxyDynflowCore::TaskLauncherRegistry.register('salt', SaltTaskLauncher)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_core/runner/command_runner'
|
2
|
-
|
3
|
-
module SmartProxySaltCore
|
4
|
-
class SaltRunner < ForemanTasksCore::Runner::CommandRunner
|
5
|
-
DEFAULT_REFRESH_INTERVAL = 1
|
6
|
-
|
7
|
-
attr_reader :jid
|
8
|
-
|
9
|
-
def initialize(options, suspended_action:)
|
10
|
-
super(options, :suspended_action => suspended_action)
|
11
|
-
@options = options
|
12
|
-
end
|
13
|
-
|
14
|
-
def start
|
15
|
-
command = generate_command
|
16
|
-
logger.debug("Running command '#{command.join(' ')}'")
|
17
|
-
initialize_command(*command)
|
18
|
-
end
|
19
|
-
|
20
|
-
def kill
|
21
|
-
publish_data('== TASK ABORTED BY USER ==', 'stdout')
|
22
|
-
publish_exit_status(1)
|
23
|
-
::Process.kill('SIGTERM', @command_pid)
|
24
|
-
end
|
25
|
-
|
26
|
-
def publish_data(data, type)
|
27
|
-
if @jid.nil? && (match = data.match(/jid: ([0-9]+)/))
|
28
|
-
@jid = match[1]
|
29
|
-
end
|
30
|
-
super
|
31
|
-
end
|
32
|
-
|
33
|
-
def publish_exit_status(status)
|
34
|
-
# If there was no salt job associated with this run, mark the job as failed
|
35
|
-
status = 1 if @jid.nil?
|
36
|
-
super status
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def generate_command
|
42
|
-
saltfile_path = SmartProxySaltCore.settings[:saltfile]
|
43
|
-
command = %w(salt --show-jid)
|
44
|
-
command << "--saltfile=#{saltfile_path}" if File.file?(saltfile_path)
|
45
|
-
command << @options['name']
|
46
|
-
command << 'state.template_str'
|
47
|
-
command << @options['script']
|
48
|
-
command
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module SmartProxySaltCore
|
2
|
-
class SaltTaskLauncher < ForemanTasksCore::TaskLauncher::Batch
|
3
|
-
class SaltRunnerAction < ForemanTasksCore::Runner::Action
|
4
|
-
def initiate_runner
|
5
|
-
additional_options = {
|
6
|
-
:step_id => run_step_id,
|
7
|
-
:uuid => execution_plan_id
|
8
|
-
}
|
9
|
-
::SmartProxySaltCore::SaltRunner.new(
|
10
|
-
input.merge(additional_options),
|
11
|
-
:suspended_action => suspended_action
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def child_launcher(parent)
|
17
|
-
ForemanTasksCore::TaskLauncher::Single.new(world, callback, :parent => parent,
|
18
|
-
:action_class_override => SaltRunnerAction)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|