<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> import uuid <EOL> import logging <EOL> from ovs . extensions . storage . persistentfactory import PersistentFactory <EOL> from ovs . log . logHandler import LogHandler <EOL> logger = LogHandler . get ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> def _log ( log_target , entry , level ) : <EOL> """<STR_LIT>""" <EOL> if level > <NUM_LIT:0> : <EOL> logger . debug ( '<STR_LIT>' . format ( log_target , entry ) ) <EOL> def services_running ( target ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> key = '<STR_LIT>' . format ( str ( uuid . uuid4 ( ) ) ) <EOL> value = str ( time . time ( ) ) <EOL> if target == '<STR_LIT>' : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> max_tries = <NUM_LIT:5> <EOL> tries = <NUM_LIT:0> <EOL> while tries < max_tries : <EOL> try : <EOL> try : <EOL> logging . disable ( logging . WARNING ) <EOL> from ovs . extensions . storage . volatilefactory import VolatileFactory <EOL> VolatileFactory . store = None <EOL> volatile = VolatileFactory . get_client ( ) <EOL> volatile . set ( key , value ) <EOL> if volatile . get ( key ) == value : <EOL> volatile . delete ( key ) <EOL> break <EOL> volatile . delete ( key ) <EOL> finally : <EOL> logging . disable ( logging . NOTSET ) <EOL> except Exception as message : <EOL> _log ( target , '<STR_LIT>' . format ( message ) , <NUM_LIT:2> ) <EOL> key = '<STR_LIT>' . format ( str ( uuid . uuid4 ( ) ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> tries += <NUM_LIT:1> <EOL> if tries == max_tries : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> return False <EOL> _log ( target , '<STR_LIT>' . format ( tries ) , <NUM_LIT:0> ) <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> max_tries = <NUM_LIT:5> <EOL> tries = <NUM_LIT:0> <EOL> while tries < max_tries : <EOL> try : <EOL> try : <EOL> logging . disable ( logging . WARNING ) <EOL> persistent = PersistentFactory . get_client ( ) <EOL> persistent . set ( key , value ) <EOL> if persistent . get ( key ) == value : <EOL> persistent . delete ( key ) <EOL> break <EOL> persistent . delete ( key ) <EOL> finally : <EOL> logging . disable ( logging . NOTSET ) <EOL> except Exception as message : <EOL> _log ( target , '<STR_LIT>' . format ( message ) , <NUM_LIT:2> ) <EOL> key = '<STR_LIT>' . format ( str ( uuid . uuid4 ( ) ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> tries += <NUM_LIT:1> <EOL> if tries == max_tries : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> return False <EOL> _log ( target , '<STR_LIT>' . format ( tries ) , <NUM_LIT:0> ) <EOL> if target == '<STR_LIT>' : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> max_tries = <NUM_LIT:5> <EOL> tries = <NUM_LIT:0> <EOL> while tries < max_tries : <EOL> try : <EOL> from ovs . extensions . db . etcd . configuration import EtcdConfiguration <EOL> from ovs . extensions . storage . persistent . pyrakoonstore import PyrakoonStore <EOL> cluster_name = str ( EtcdConfiguration . get ( '<STR_LIT>' ) ) <EOL> client = PyrakoonStore ( cluster = cluster_name ) <EOL> client . set ( key , value ) <EOL> if client . get ( key ) == value : <EOL> client . delete ( key ) <EOL> break <EOL> client . delete ( key ) <EOL> except Exception as message : <EOL> _log ( target , '<STR_LIT>' . format ( message ) , <NUM_LIT:2> ) <EOL> key = '<STR_LIT>' . format ( str ( uuid . uuid4 ( ) ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> tries += <NUM_LIT:1> <EOL> if tries == max_tries : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> return False <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> if target in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> import pika <EOL> from ovs . extensions . db . etcd . configuration import EtcdConfiguration <EOL> rmq_servers = EtcdConfiguration . get ( '<STR_LIT>' ) <EOL> good_node = False <EOL> for server in rmq_servers : <EOL> try : <EOL> connection_string = '<STR_LIT>' . format ( EtcdConfiguration . get ( '<STR_LIT>' ) , <EOL> EtcdConfiguration . get ( '<STR_LIT>' ) , <EOL> EtcdConfiguration . get ( '<STR_LIT>' ) , <EOL> server ) <EOL> connection = pika . BlockingConnection ( pika . URLParameters ( connection_string ) ) <EOL> channel = connection . channel ( ) <EOL> channel . basic_publish ( '<STR_LIT>' , '<STR_LIT>' , str ( time . time ( ) ) , <EOL> pika . BasicProperties ( content_type = '<STR_LIT>' , delivery_mode = <NUM_LIT:1> ) ) <EOL> connection . close ( ) <EOL> good_node = True <EOL> except Exception as message : <EOL> _log ( target , '<STR_LIT>' . format ( server , message ) , <NUM_LIT:2> ) <EOL> if good_node is False : <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> return False <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> _log ( target , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> return True <EOL> except Exception as ex : <EOL> _log ( target , '<STR_LIT>' . format ( ex ) , <NUM_LIT:2> ) <EOL> return False <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> given_target = sys . argv [ <NUM_LIT:1> ] <EOL> mode = sys . argv [ <NUM_LIT:2> ] <EOL> _log ( given_target , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> if mode == '<STR_LIT>' : <EOL> _log ( given_target , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> while True : <EOL> if services_running ( given_target ) : <EOL> _log ( given_target , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> if mode == '<STR_LIT>' : <EOL> _log ( given_target , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> while True : <EOL> if not services_running ( given_target ) : <EOL> _log ( given_target , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> _log ( given_target , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
