smart_proxy_salt 3.0.0 → 3.1.0

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: 978fe04cd0b2ee65be99fc84f20599f295d51498b8aa1ba0541cc9569f56ee9a
4
- data.tar.gz: 732c3b575790b37ec8570816f76d10af534b10cf3fb7ea217b7378f645c951f9
3
+ metadata.gz: f3ac4ad731748d62d1ec922520aa60ce1a7db4b001b2aeaabfe9c2e0709e3f9e
4
+ data.tar.gz: b345c0ae059918e924a6ec771664a38e687d3b8a288559cd48274e271f69c551
5
5
  SHA512:
6
- metadata.gz: d291974d5e815bb0a8d84f46d8f4e8509d0c70dc8dc76fa9d35d0f836ff7e55f3fe7f67c3cd0d5fc1452d2747b528ccca05c0de7d881042468b652a30824dd5e
7
- data.tar.gz: e41c156691bb2c1c86381658104a4fb54fb4d6a22a8e1778b7dc6ce9f39d40183d649699c49b8c835815c16b073886d68d0988bf0a019c79d8fbb001cdc7133c
6
+ metadata.gz: 20b39c0f2ef2a6ea13cf94d996141ee1e28ff542fd8def32275560085b8f6c31e57d0d834e6179744c98a4eccfcb3efa4dc8ce74e178b0751103933253d1c465
7
+ data.tar.gz: d1dd34e0c168829fe049c8db0bb751782b3548a39566c530d148a00485fcf0c96c2fd52b96a7bb71b7a0ac3b9e5ea74629ab39e7b4ef166b1f0ba1163aa6fbd7
@@ -60,38 +60,9 @@ end
60
60
  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
- #
64
- # salt-run doesn't support directly outputting to json,
65
- # so we have resort to python to extract the grains.
66
- # Based on https://github.com/saltstack/salt/issues/9444
67
-
68
- script = <<-EOF
69
- #!/usr/bin/env python
70
- import json
71
- import os
72
- import sys
73
-
74
- import salt.config
75
- import salt.runner
76
-
77
- if __name__ == '__main__':
78
- __opts__ = salt.config.master_config(
79
- os.environ.get('SALT_MASTER_CONFIG', '/etc/salt/master'))
80
- runner = salt.runner.Runner(__opts__)
81
-
82
- stdout_bak = sys.stdout
83
- with open(os.devnull, 'wb') as f:
84
- sys.stdout = f
85
- ret = runner.cmd('cache.grains', ['#{minion}'])
86
- sys.stdout = stdout_bak
87
-
88
- print json.dumps(ret)
89
- EOF
90
-
91
- result = IO.popen('python 2>/dev/null', 'r+') do |python|
92
- python.write script
93
- python.close_write
94
- result = python.read
63
+
64
+ result = IO.popen(['salt-run', '--output=json', 'cache.grains', minion]) do |io|
65
+ io.read
95
66
  end
96
67
 
97
68
  grains = JSON.parse(result)
@@ -3,6 +3,6 @@
3
3
  module Proxy
4
4
  # Salt module
5
5
  module Salt
6
- VERSION = '3.0.0'
6
+ VERSION = '3.1.0'
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module SmartProxySaltCore
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -1,14 +1,20 @@
1
1
  #!/usr/bin/env python
2
2
  # Uploads reports from the Salt job cache to Foreman
3
3
 
4
+ from __future__ import print_function
5
+
4
6
  LAST_UPLOADED = '/etc/salt/last_uploaded'
5
7
  FOREMAN_CONFIG = '/etc/salt/foreman.yaml'
6
8
  LOCK_FILE = '/var/lock/salt-report-upload.lock'
7
9
 
8
- import httplib
10
+ try:
11
+ from http.client import HTTPConnection, HTTPSConnection
12
+ except ImportError:
13
+ from httplib import HTTPSConnection, HTTPSConnection
9
14
  import ssl
10
15
  import json
11
16
  import yaml
17
+ import io
12
18
  import os
13
19
  import sys
14
20
  import base64
@@ -20,7 +26,7 @@ import salt.runner
20
26
 
21
27
 
22
28
  def salt_config():
23
- with open(FOREMAN_CONFIG, 'r') as f:
29
+ with io.open(FOREMAN_CONFIG, 'r') as f:
24
30
  config = yaml.load(f.read())
25
31
  return config
26
32
 
@@ -30,7 +36,7 @@ def get_job(job_id):
30
36
 
31
37
  # If any minion's results are strings, they're exceptions
32
38
  # and should be wrapped in a list like other errors
33
- for minion, value in result.iteritems():
39
+ for minion, value in result.items():
34
40
  if type(value) == str:
35
41
  result[minion] = [value]
36
42
 
@@ -47,7 +53,7 @@ def read_last_uploaded():
47
53
  if not os.path.isfile(LAST_UPLOADED):
48
54
  return 0
49
55
  else:
50
- with open(LAST_UPLOADED, 'r') as f:
56
+ with io.open(LAST_UPLOADED, 'r') as f:
51
57
  result = f.read().strip()
52
58
  if len(result) == 20:
53
59
  try:
@@ -59,7 +65,7 @@ def read_last_uploaded():
59
65
 
60
66
 
61
67
  def write_last_uploaded(last_uploaded):
62
- with open(LAST_UPLOADED, 'w+') as f:
68
+ with io.open(LAST_UPLOADED, 'w+') as f:
63
69
  f.write(last_uploaded)
64
70
 
65
71
 
@@ -68,7 +74,7 @@ def run(*args, **kwargs):
68
74
  os.environ.get('SALT_MASTER_CONFIG', '/etc/salt/master'))
69
75
 
70
76
  runner = salt.runner.Runner(__opts__)
71
- with open(os.devnull, 'wb') as f:
77
+ with io.open(os.devnull, 'w') as f:
72
78
  stdout_bak, sys.stdout = sys.stdout, f
73
79
  try:
74
80
  ret = runner.cmd(*args, **kwargs)
@@ -83,7 +89,7 @@ def jobs_to_upload():
83
89
  })
84
90
  last_uploaded = read_last_uploaded()
85
91
 
86
- job_ids = [jid for (jid, value) in jobs.iteritems()
92
+ job_ids = [jid for (jid, value) in jobs.items()
87
93
  if int(jid) > last_uploaded]
88
94
 
89
95
  for job_id in sorted(job_ids):
@@ -99,12 +105,12 @@ def upload(jobs):
99
105
  ctx = ssl.create_default_context()
100
106
  ctx.load_cert_chain(certfile=config[':ssl_cert'], keyfile=config[':ssl_key'])
101
107
  if config[':ssl_ca']:
102
- ctx.load_verify_locations(cafile=config[':ssl_ca'])
103
- connection = httplib.HTTPSConnection(config[':host'],
104
- port=config[':port'], context=ctx)
108
+ ctx.load_verify_locations(cafile=config[':ssl_ca'])
109
+ connection = HTTPSConnection(config[':host'],
110
+ port=config[':port'], context=ctx)
105
111
  else:
106
- connection = httplib.HTTPConnection(config[':host'],
107
- port=config[':port'])
112
+ connection = HTTPConnection(config[':host'],
113
+ port=config[':port'])
108
114
  if ':username' in config and ':password' in config:
109
115
  token = base64.b64encode('{}:{}'.format(config[':username'],
110
116
  config[':password']))
@@ -121,23 +127,24 @@ def upload(jobs):
121
127
 
122
128
  if response.status == 200:
123
129
  write_last_uploaded(job_id)
124
- print "Success %s: %s" % (job_id, response.read())
130
+ print("Success %s: %s" % (job_id, response.read()))
125
131
  else:
126
- print "Unable to upload job - aborting report upload"
127
- print response.read()
132
+ print("Unable to upload job - aborting report upload")
133
+ print(response.read())
128
134
 
129
135
 
130
136
  def get_lock():
131
137
  if os.path.isfile(LOCK_FILE):
132
138
  raise Exception("Unable to obtain lock.")
133
139
  else:
134
- open(LOCK_FILE, 'w+').close()
140
+ io.open(LOCK_FILE, 'w+').close()
135
141
 
136
142
 
137
143
  def release_lock():
138
144
  if os.path.isfile(LOCK_FILE):
139
145
  os.remove(LOCK_FILE)
140
146
 
147
+
141
148
  if __name__ == '__main__':
142
149
  try:
143
150
  get_lock()
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.0.0
4
+ version: 3.1.0
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: 2019-08-02 00:00:00.000000000 Z
12
+ date: 2019-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json