-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdocker-entrypoint.py
executable file
·142 lines (114 loc) · 3.25 KB
/
docker-entrypoint.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
# Single entry point / dispatcher for simplified running of
#
## pman
## pfioh
## purl
#
import argparse
import os
str_desc = """
NAME
docker-entrypoint.py
SYNOPSIS
docker-entrypoint.py --msg '{}' [optional cmd args for each]
DESCRIPTION
'docker-entrypoint.py' is the main entrypoint for running pfurl.
"""
def http_construct(args, unknown):
"""
Construct the --http <arg> from the args/unknown space -- relevant only for 'purl'.
:param args:
:param unknown:
:return:
"""
str_http = ''
b_httpSpecd = False
if '--http' in unknown:
try:
str_httpArg = unknown[unknown.index('--http')+1]
unknown.remove('--http')
unknown.remove(str_httpArg)
except:
str_httpArg = ""
str_http = '--http %s' % str_httpArg
b_httpSpecd = True
if not b_httpSpecd:
str_serverIP = "172.17.0.2"
str_serverPort = '5010'
try:
if args.b_pman:
str_serverIP = os.environ['PMAN_PORT_5010_TCP_ADDR']
str_serverPort = os.environ['PMAN_PORT_5010_TCP_PORT']
if args.b_pfioh:
str_serverIP = os.environ['PFIOH_PORT_5055_TCP_ADDR']
str_serverPort = os.environ['PFIOH_PORT_5055_TCP_PORT']
except:
pass
str_http = '--http %s:%s/api/v1/cmd/' % (str_serverIP, str_serverPort)
return str_http
def pfurl_do(args, unknown):
str_http = http_construct(args, unknown)
str_otherArgs = ' '.join(unknown)
str_raw = ''
if args.b_raw: str_raw = "--raw"
str_CMD = "/usr/local/bin/pfurl --verb %s %s %s --jsonwrapper '%s' --msg '%s' %s" % (args.verb, str_raw, str_http, args.jsonwrapper, args.msg, str_otherArgs)
return str_CMD
parser = argparse.ArgumentParser(description = str_desc)
#parser.add_argument(
#'app',
#nargs = '?',
#default = 'pman'
#)
#parser.add_argument(
#'--pman',
#action = 'store_true',
#dest = 'b_pman',
#default = False,
#help = 'if specified, indicates transmission to a linked <pman> container.',
#)
#parser.add_argument(
#'--pfioh',
#action = 'store_true',
#dest = 'b_pfioh',
#default = False,
#help = 'if specified, indicates transmission to a linked <pfioh> container.',
#)
parser.add_argument(
'--msg',
action = 'store',
dest = 'msg',
default = '',
help = 'JSON msg payload'
)
# Pattern of minimum required purl args
parser.add_argument(
'--verb',
action = 'store',
dest = 'verb',
default = 'POST',
help = 'REST verb.'
)
parser.add_argument(
'--jsonwrapper',
action = 'store',
dest = 'jsonwrapper',
default = '',
help = 'wrap msg in optional field'
)
parser.add_argument(
'--raw',
help = 'if specified, do not wrap return data from remote call in json field',
dest = 'b_raw',
action = 'store_true',
default = False
)
args, unknown = parser.parse_known_args()
if __name__ == '__main__':
try:
fname = 'pfurl_do(args, unknown)'
str_cmd = eval(fname)
# print(str_cmd)
os.system(str_cmd)
except:
print("Misunderstood container app... exiting.")