-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmesos-dns-option.py
62 lines (51 loc) · 2.08 KB
/
mesos-dns-option.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import traceback
import sys
import json
import argparse
import requests
from requests.api import request
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
def getIpPortDns(mesosDnsAddr, serviceMesosDns):
'''[
{
"service": "_auth-db-auth._tcp.marathon.mesos.",
"ip": "10.0.0.13",
"port": "31332"
}
]'''
response = requests.get(mesosDnsAddr + "/v1/services/" + serviceMesosDns, timeout = 20)
if response.status_code == requests.codes.ok:
#print(response.text)
responseJson = json.loads(response.text)
ip = responseJson[0]["ip"]
port = responseJson[0]["port"]
if not ip:
print("No ip for " + serviceMesosDns)
if not port:
print("No port for " + serviceMesosDns)
else:
print("Error getting ip/port for " + serviceMesosDns)
ip = ""
port = ""
return (ip, port)
if __name__ == "__main__":
print("Running the Mesos DNS ip/port extractor")
parser = argparse.ArgumentParser(description="Get the ip/port for various services from Mesos DNS")
parser.add_argument('--mesosdns', required=True, help='Mesos DNS full address e.g. http://127.0.0.1:8123')
parser.add_argument('--mesosdns_db', required=True, help="Mesos DNS full name for the DB e.g. '_auth-db-auth._tcp.marathon.mesos.'")
parser.add_argument('--vars', required=True, help="The full path of the file which will be generated by this script. It will contain the new values for various env variables that are needed by the web-app e.g. './config.txt'")
args = parser.parse_args()
varsFName = args.vars
mesosDnsAddr = args.mesosdns
mesosDnsDb = args.mesosdns_db
with open(varsFName, "w") as varsF:
ipPort = getIpPortDns(mesosDnsAddr, mesosDnsDb)
print("AUTH_DB_HOST IP: " + ipPort[0])
print("AUTH_DB_HOST PORT: " + ipPort[1])
varsF.write("AUTH_DB_HOST=" + ipPort[0] + "\n")
varsF.write("AUTH_DB_PORT=" + ipPort[1] + "\n")