<s> import sys <EOL> from os . path import exists <EOL> from os . path import join <EOL> from paasta_tools . cli . fsm . questions import _yamlize <EOL> from paasta_tools . cli . fsm . questions import get_marathon_stanza <EOL> from paasta_tools . cli . fsm . questions import get_monitoring_stanza <EOL> from paasta_tools . cli . fsm . questions import get_service_stanza <EOL> from paasta_tools . cli . fsm . questions import get_smartstack_stanza <EOL> from paasta_tools . cli . fsm . questions import get_srvname <EOL> from paasta_tools . cli . fsm . service import Service <EOL> from paasta_tools . cli . utils import lazy_choices_completer <EOL> from paasta_tools . cli . utils import list_teams <EOL> from paasta_tools . utils import DEFAULT_SOA_DIR <EOL> from paasta_tools . utils import load_system_paasta_config <EOL> from paasta_tools . utils import PaastaColors <EOL> def add_subparser ( subparsers ) : <EOL> fsm_parser = subparsers . add_parser ( <EOL> "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> description = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) , <EOL> ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = DEFAULT_SOA_DIR , <EOL> required = True , <EOL> help = "<STR_LIT>" ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = None , <EOL> help = "<STR_LIT>" ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> dest = "<STR_LIT:description>" , <EOL> default = None , <EOL> help = "<STR_LIT>" ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = None , <EOL> help = "<STR_LIT>" ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT:port>" , <EOL> default = None , <EOL> help = "<STR_LIT>" ) <EOL> fsm_parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = None , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) . completer = lazy_choices_completer ( list_teams ) <EOL> fsm_parser . set_defaults ( command = paasta_fsm ) <EOL> def validate_args ( args ) : <EOL> """<STR_LIT>""" <EOL> if not exists ( args . yelpsoa_config_root ) : <EOL> sys . exit ( <EOL> "<STR_LIT>" % args . yelpsoa_config_root <EOL> ) <EOL> if args . auto and not args . srvname : <EOL> sys . exit ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def get_paasta_config ( yelpsoa_config_root , srvname , auto , port , team , description , external_link ) : <EOL> paasta_config = load_system_paasta_config ( ) <EOL> srvname = get_srvname ( srvname , auto ) <EOL> smartstack_stanza = get_smartstack_stanza ( yelpsoa_config_root , auto , port ) <EOL> monitoring_stanza = get_monitoring_stanza ( auto , team ) <EOL> marathon_stanza = get_marathon_stanza ( ) <EOL> deploy_stanza = paasta_config . get_fsm_deploy_pipeline ( ) <EOL> service_stanza = get_service_stanza ( description , external_link , auto ) <EOL> cluster_stanza = paasta_config . get_fsm_cluster_map ( ) <EOL> return ( srvname , service_stanza , smartstack_stanza , monitoring_stanza , <EOL> deploy_stanza , marathon_stanza , cluster_stanza , team ) <EOL> def write_paasta_config ( <EOL> srv , <EOL> service_stanza , <EOL> smartstack_stanza , <EOL> monitoring_stanza , <EOL> deploy_stanza , <EOL> marathon_stanza , <EOL> cluster_map , <EOL> ) : <EOL> srv . io . write_file ( "<STR_LIT>" , _yamlize ( service_stanza ) ) <EOL> srv . io . write_file ( "<STR_LIT>" , _yamlize ( smartstack_stanza ) ) <EOL> srv . io . write_file ( "<STR_LIT>" , _yamlize ( monitoring_stanza ) ) <EOL> srv . io . write_file ( "<STR_LIT>" , _yamlize ( deploy_stanza ) ) <EOL> for ( filename , marathon_config_stanza ) in marathon_stanza : <EOL> srv . io . write_file ( "<STR_LIT>" % filename , _yamlize ( marathon_config_stanza ) ) <EOL> for ( clustername , filename ) in cluster_map . items ( ) : <EOL> srv . io . symlink_file_relative ( "<STR_LIT>" % filename , "<STR_LIT>" % clustername ) <EOL> def paasta_fsm ( args ) : <EOL> validate_args ( args ) <EOL> ( srvname , service_stanza , smartstack_stanza , monitoring_stanza , <EOL> deploy_stanza , marathon_stanza , cluster_stanza , team ) = ( <EOL> get_paasta_config ( <EOL> args . yelpsoa_config_root , <EOL> args . srvname , <EOL> args . auto , <EOL> args . port , <EOL> args . team , <EOL> args . description , <EOL> args . external_link , <EOL> ) <EOL> ) <EOL> srv = Service ( srvname , args . yelpsoa_config_root ) <EOL> write_paasta_config ( <EOL> srv , <EOL> service_stanza , <EOL> smartstack_stanza , <EOL> monitoring_stanza , <EOL> deploy_stanza , <EOL> marathon_stanza , <EOL> cluster_stanza , <EOL> ) <EOL> print PaastaColors . yellow ( "<STR_LIT>" ) <EOL> print PaastaColors . red ( "<STR_LIT>" ) <EOL> print PaastaColors . green ( "<STR_LIT>" ) <EOL> print PaastaColors . cyan ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> print <EOL> print PaastaColors . bold ( "<STR_LIT>" % srvname ) <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" % join ( args . yelpsoa_config_root , srvname ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" % srvname <EOL> print "<STR_LIT>" <EOL> print </s>
