<s> import argparse <EOL> import os <EOL> import os . path <EOL> import re <EOL> import subprocess <EOL> import yaml <EOL> STORM_HOME = os . environ [ "<STR_LIT>" ] <EOL> stormSetupConfig = None <EOL> with open ( os . environ [ "<STR_LIT>" ] ) as f : <EOL> stormSetupConfig = yaml . load ( f . read ( ) ) <EOL> parser = argparse . ArgumentParser ( <EOL> description = "<STR_LIT>" <EOL> ) <EOL> parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> dest = "<STR_LIT>" , <EOL> help = re . sub ( r"""<STR_LIT>""" , "<STR_LIT:U+0020>" , <EOL> """<STR_LIT>""" <EOL> ) . strip ( ) <EOL> ) <EOL> parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = str , <EOL> help = re . sub ( r"""<STR_LIT>""" , "<STR_LIT:U+0020>" , <EOL> """<STR_LIT>""" <EOL> ) . strip ( ) <EOL> ) <EOL> parsedArgs = parser . parse_args ( ) <EOL> myIpAddresses = parsedArgs . my_ip_addresses <EOL> if parsedArgs . is_storm_supervisor : <EOL> with open ( "<STR_LIT>" , "<STR_LIT:w>" ) as f : <EOL> stormSupervisorHosts = stormSetupConfig [ "<STR_LIT>" ] <EOL> for supervisor_host in stormSupervisorHosts : <EOL> ip_address = stormSetupConfig [ "<STR_LIT>" ] [ supervisor_host ] <EOL> alias = "<STR_LIT>" . format ( supervisor_host ) <EOL> if ip_address not in myIpAddresses : <EOL> f . write ( "<STR_LIT>" . format ( ip_address , alias ) ) <EOL> stormYamlConfig = stormSetupConfig [ "<STR_LIT>" ] <EOL> storm_yaml_zk_servers_section = [ <EOL> stormSetupConfig [ "<STR_LIT>" ] [ zk_server ] for <EOL> zk_server in stormYamlConfig [ "<STR_LIT>" ] <EOL> ] <EOL> zk_server_ip_to_replace = None <EOL> for zk_server_ip in storm_yaml_zk_servers_section : <EOL> if zk_server_ip in myIpAddresses : <EOL> zk_server_ip_to_replace = zk_server_ip <EOL> break <EOL> if zk_server_ip_to_replace is not None : <EOL> idx = storm_yaml_zk_servers_section . index ( zk_server_ip_to_replace ) <EOL> zk_port_env_var = "<STR_LIT>" . format ( <EOL> stormYamlConfig [ "<STR_LIT>" ] <EOL> ) <EOL> storm_yaml_zk_servers_section . remove ( zk_server_ip_to_replace ) <EOL> storm_yaml_zk_servers_section . insert ( idx , os . environ [ zk_port_env_var ] ) <EOL> stormYamlConfig [ "<STR_LIT>" ] = storm_yaml_zk_servers_section <EOL> if stormSetupConfig [ "<STR_LIT>" ] [ stormYamlConfig [ "<STR_LIT>" ] ] in myIpAddresses : <EOL> try : <EOL> nimbusEnvVar = "<STR_LIT>" . format ( <EOL> stormYamlConfig [ "<STR_LIT>" ] <EOL> ) <EOL> stormYamlConfig [ "<STR_LIT>" ] = os . environ [ nimbusEnvVar ] <EOL> except KeyError : <EOL> p = subprocess . Popen ( [ "<STR_LIT>" , "<STR_LIT>" ] , stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE <EOL> ) <EOL> out , _ = p . communicate ( ) <EOL> stormYamlConfig [ "<STR_LIT>" ] = out . strip ( ) <EOL> else : <EOL> stormYamlConfig [ "<STR_LIT>" ] = stormSetupConfig [ "<STR_LIT>" ] [ stormYamlConfig [ "<STR_LIT>" ] ] <EOL> with open ( os . path . join ( STORM_HOME , "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( yaml . dump ( stormYamlConfig , default_flow_style = False ) ) <EOL> os . system ( "<STR_LIT>" ) </s>
