summaryrefslogtreecommitdiffstats
path: root/roleproxy.py
diff options
context:
space:
mode:
authorGeorg Pfuetzenreuter2023-02-05 00:42:41 +0100
committerGeorg Pfuetzenreuter2023-02-05 00:42:41 +0100
commit5a698dfbad584fe28a73dbb35983a57bed671404 (patch)
tree7fe229e557c13da4baaad62adf0af96ab4b552b9 /roleproxy.py
parent6ac3e6c3003f9b44f509165dd3f4f33dc4493898 (diff)
downloadsalt-netbox-roleproxy-5a698dfbad584fe28a73dbb35983a57bed671404.tar.gz
salt-netbox-roleproxy-5a698dfbad584fe28a73dbb35983a57bed671404.tar.bz2
salt-netbox-roleproxy-5a698dfbad584fe28a73dbb35983a57bed671404.zip
Add master query endpointHEAD1.1main
New /master endpoint serving the name of the Salt master for the specified machine. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'roleproxy.py')
-rwxr-xr-xroleproxy.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/roleproxy.py b/roleproxy.py
index b4f0e1d..4e671b8 100755
--- a/roleproxy.py
+++ b/roleproxy.py
@@ -43,8 +43,16 @@ def get_roles(netbox, name):
if len(vm) == 0:
return(404, None)
+def get_master(netbox, name):
+ vm = netbox.virtualization.virtual_machines.filter(name=name)
+ if len(vm) > 0:
+ vmmaster = vm[0].config_context.salt_master
+ return(200, vmmaster)
+ if len(vm) == 0:
+ return(404, None)
+
@app.route('/roles')
-def query():
+def query_roles():
name = flask.request.args.get('machine')
query = get_roles(connect(host, token), name)
response = query[0]
@@ -55,6 +63,17 @@ def query():
roledict = {'roles': query[1]}
return(flask.jsonify(roledict))
+@app.route('/master')
+def query_master():
+ name = flask.request.args.get('machine')
+ query = get_master(connect(host, token), name)
+ response = query[0]
+ logger.info(' %s requested master for %s and received %i', flask.request.remote_addr, name, response)
+ if response == 404:
+ flask.abort(404)
+ elif response == 200:
+ return(query[1])
+
if __name__ == '__main__':
#app.run(debug=False)
logger = logging.getLogger('roleproxy')