@@ -14,13 +14,13 @@ def get_conf_setting(setting, settings_json, default_value="skip"):
14
14
try :
15
15
setting_value = os .getenv (setting .upper (), settings_json .get (setting , default_value ))
16
16
except Exception as e :
17
- print >> sys .stderr , e
18
- print >> sys . stderr , "missing " + setting + " config setting"
19
- print ("missing " + setting + " config setting" )
17
+ print ( e , file = sys .stderr )
18
+ print ( "missing " + setting + " config setting" , file = sys . stderr )
19
+ print (( "missing " + setting + " config setting" ) )
20
20
os ._exit (2 )
21
21
if setting_value == "skip" :
22
- print >> sys . stderr , "missing " + setting + " config setting"
23
- print ("missing " + setting + " config setting" )
22
+ print ( "missing " + setting + " config setting" , file = sys . stderr )
23
+ print (( "missing " + setting + " config setting" ) )
24
24
os ._exit (2 )
25
25
return setting_value
26
26
@@ -79,7 +79,7 @@ def roll_containers(app_json, force_pull=True):
79
79
port_binds [x ] = x + idx
80
80
port_list .append (x )
81
81
elif isinstance (x , dict ):
82
- for host_port , container_port in x .iteritems ():
82
+ for host_port , container_port in x .items ():
83
83
port_binds [int (container_port )] = int (host_port ) + idx
84
84
port_list .append (container_port )
85
85
else :
@@ -132,7 +132,7 @@ def start_containers(app_json, force_pull=True):
132
132
port_binds [x ] = x + container_number - 1
133
133
port_list .append (x )
134
134
elif isinstance (x , dict ):
135
- for host_port , container_port in x .iteritems ():
135
+ for host_port , container_port in x .items ():
136
136
port_binds [int (container_port )] = int (host_port ) + container_number - 1
137
137
port_list .append (container_port )
138
138
else :
@@ -153,7 +153,7 @@ def start_containers(app_json, force_pull=True):
153
153
154
154
# figure out how many containers are needed
155
155
def containers_required (app_json ):
156
- for scale_type , scale_amount in app_json ["containers_per" ].iteritems ():
156
+ for scale_type , scale_amount in app_json ["containers_per" ].items ():
157
157
if scale_type == "cpu" :
158
158
containers_needed = int (cpu_cores * scale_amount )
159
159
elif scale_type == "memory" or scale_type == "mem" :
@@ -178,7 +178,7 @@ def restart_unhealthy_containers():
178
178
if docker_socket .check_container_healthy (nebula_container ["Id" ]) is False :
179
179
docker_socket .restart_container (nebula_container ["Id" ])
180
180
except Exception as e :
181
- print >> sys .stderr , e
181
+ print ( e , file = sys .stderr )
182
182
print ("failed checking containers health" )
183
183
os ._exit (2 )
184
184
@@ -245,7 +245,7 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
245
245
print ("nebula manager initial connection check failure, dropping container" )
246
246
os ._exit (2 )
247
247
except Exception as e :
248
- print >> sys .stderr , e
248
+ print ( e , file = sys .stderr )
249
249
print ("error confirming connection to nebula manager - please check connection & authentication params and "
250
250
"that the manager is online" )
251
251
os ._exit (2 )
@@ -260,24 +260,24 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
260
260
# make sure the device_group exists in the nebula cluster
261
261
while local_device_group_info ["status_code" ] == 403 and \
262
262
local_device_group_info ["reply" ]["device_group_exists" ] is False :
263
- print ("device_group " + device_group + " doesn't exist in nebula cluster, waiting for it to be created" )
263
+ print (( "device_group " + device_group + " doesn't exist in nebula cluster, waiting for it to be created" ) )
264
264
local_device_group_info = get_device_group_info (nebula_connection , device_group )
265
265
time .sleep (nebula_manager_check_in_time )
266
266
267
267
# start all apps that are set to running on boot
268
268
for nebula_app in local_device_group_info ["reply" ]["apps" ]:
269
269
if nebula_app ["running" ] is True :
270
- print ("initial start of " + nebula_app ["app_name" ] + " app" )
270
+ print (( "initial start of " + nebula_app ["app_name" ] + " app" ) )
271
271
start_containers (nebula_app )
272
- print ("completed initial start of " + nebula_app ["app_name" ] + " app" )
272
+ print (( "completed initial start of " + nebula_app ["app_name" ] + " app" ) )
273
273
274
274
# open a thread which is in charge of restarting any containers which healthcheck shows them as unhealthy
275
275
print ("starting work container health checking thread" )
276
276
Thread (target = restart_unhealthy_containers ).start ()
277
277
278
278
# loop forever
279
- print ("starting device_group " + device_group + " /info check loop, configured to check for changes every "
280
- + str (nebula_manager_check_in_time ) + " seconds" )
279
+ print (( "starting device_group " + device_group + " /info check loop, configured to check for changes every "
280
+ + str (nebula_manager_check_in_time ) + " seconds" ))
281
281
while True :
282
282
283
283
# wait the configurable time before checking the device_group info page again
@@ -296,20 +296,20 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
296
296
if remote_nebula_app ["app_id" ] > local_device_group_info ["reply" ]["apps" ][local_app_index ]["app_id" ]:
297
297
monotonic_id_increase = True
298
298
if remote_nebula_app ["running" ] is False :
299
- print ("stopping app " + remote_nebula_app ["app_name" ] +
300
- " do to changes in the app configuration" )
299
+ print (( "stopping app " + remote_nebula_app ["app_name" ] +
300
+ " do to changes in the app configuration" ))
301
301
stop_containers (remote_nebula_app )
302
302
elif remote_nebula_app ["rolling_restart" ] is True and \
303
303
local_device_group_info ["reply" ]["apps" ][local_app_index ]["running" ] is True :
304
- print ("rolling app " + remote_nebula_app ["app_name" ] +
305
- " do to changes in the app configuration" )
304
+ print (( "rolling app " + remote_nebula_app ["app_name" ] +
305
+ " do to changes in the app configuration" ))
306
306
roll_containers (remote_nebula_app )
307
307
else :
308
- print ("restarting app " + remote_nebula_app ["app_name" ] +
309
- " do to changes in the app configuration" )
308
+ print (( "restarting app " + remote_nebula_app ["app_name" ] +
309
+ " do to changes in the app configuration" ))
310
310
restart_containers (remote_nebula_app )
311
311
else :
312
- print ("restarting app " + remote_nebula_app ["app_name" ] + " do to changes in the app configuration" )
312
+ print (( "restarting app " + remote_nebula_app ["app_name" ] + " do to changes in the app configuration" ) )
313
313
monotonic_id_increase = True
314
314
restart_containers (remote_nebula_app )
315
315
@@ -318,8 +318,8 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
318
318
monotonic_id_increase = True
319
319
for local_nebula_app in local_device_group_info ["reply" ]["apps" ]:
320
320
if local_nebula_app ["app_name" ] not in remote_device_group_info ["reply" ]["apps_list" ]:
321
- print ("removing app " + local_nebula_app ["app_name" ] +
322
- " do to changes in the app configuration" )
321
+ print (( "removing app " + local_nebula_app ["app_name" ] +
322
+ " do to changes in the app configuration" ))
323
323
stop_containers (local_nebula_app )
324
324
325
325
# logic that runs image pruning if prune_id increased
@@ -333,6 +333,6 @@ def get_device_group_info(nebula_connection_object, device_group_to_get_info):
333
333
local_device_group_info = remote_device_group_info
334
334
335
335
except Exception as e :
336
- print >> sys .stderr , e
336
+ print ( e , file = sys .stderr )
337
337
print ("failed main loop - exiting" )
338
338
os ._exit (2 )
0 commit comments