forked from d2iq-archive/marathon-lb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
71 lines (53 loc) · 2.15 KB
/
common.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
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
from logging.handlers import SysLogHandler
import sys
import logging
def setup_logging(logger, syslog_socket, log_format):
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(log_format)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(formatter)
logger.addHandler(consoleHandler)
if syslog_socket != '/dev/null':
syslogHandler = SysLogHandler(syslog_socket)
syslogHandler.setFormatter(formatter)
logger.addHandler(syslogHandler)
def set_marathon_auth_args(parser):
parser.add_argument("--marathon-auth-credential-file",
help="Path to file containing a user/pass for "
"the Marathon HTTP API in the format of 'user:pass'."
)
parser.add_argument("--auth-credentials",
help="user/pass for the Marathon HTTP API in the "
"format of 'user:pass'.")
return parser
def get_marathon_auth_params(args):
marathon_auth = None
if args.marathon_auth_credential_file:
with open(args.marathon_auth_credential_file, 'r') as f:
line = f.readline().rstrip('\r\n')
if line:
marathon_auth = tuple(line.split(':'))
elif args.auth_credentials:
marathon_auth = \
tuple(args.auth_credentials.split(':'))
if marathon_auth and len(marathon_auth) != 2:
print(
"Please provide marathon credentials in user:pass format"
)
sys.exit(1)
return marathon_auth
def set_logging_args(parser):
default_log_socket = "/dev/log"
if sys.platform == "darwin":
default_log_socket = "/var/run/syslog"
parser.add_argument("--syslog-socket",
help="Socket to write syslog messages to. "
"Use '/dev/null' to disable logging to syslog",
default=default_log_socket
)
parser.add_argument("--log-format",
help="Set log message format",
default="%(name)s: %(message)s"
)
return parser