smart_proxy_salt 5.0.0 → 5.0.1
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ba18b31812c408bbbef40601e2f7279ee6f04d55a62b999b7b993f0158aede8
|
4
|
+
data.tar.gz: 82822b47407c7c5e66151627a7935d294566c6e5dc17c4bbf7c2674890653826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95ddd85199c088db57c6248d99d7a370e36c74191aeda0d74fd4f7fb7d573ee50a0b4a107092d2f8f6c3018c131e6127236cc5818f84c835eecabd0b21ef6bf
|
7
|
+
data.tar.gz: d9866d18feed738e03d0e47784ee75b41921b65bcbbd33e88aec5856cfd5160e4b0b5e5485d5c25c3a6c601d6c519bde984599b734f7f081b7adce9de53c3277
|
@@ -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
|
|
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.0.
|
4
|
+
version: 5.0.1
|
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: 2022-
|
12
|
+
date: 2022-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -124,7 +124,6 @@ files:
|
|
124
124
|
- bin/foreman-node
|
125
125
|
- bin/salt_python_wrapper
|
126
126
|
- bundler.d/salt.rb
|
127
|
-
- cron/smart_proxy_salt
|
128
127
|
- etc/foreman.conf.example
|
129
128
|
- etc/foreman.yaml.example
|
130
129
|
- lib/smart_proxy_salt.rb
|
data/cron/smart_proxy_salt
DELETED