<s> import os <EOL> import sys <EOL> import json <EOL> import requests <EOL> def master_spec ( domain , master_ip , port , registry , tag ) : <EOL> return { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:image>" : "<STR_LIT>" % ( registry , tag ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : port } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : port + <NUM_LIT:1> } <EOL> ] <EOL> } <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" % ( master_ip , port + <NUM_LIT:2> ) <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" % domain ] , <EOL> "<STR_LIT>" : [ [ "<STR_LIT>" , "<STR_LIT>" , master_ip ] ] <EOL> } <EOL> def monitor_spec ( domain , master_ip , port , registry , tag ) : <EOL> return { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:image>" : "<STR_LIT>" % ( registry , tag ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT:0> } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : port + <NUM_LIT:2> } <EOL> ] <EOL> } <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : [ [ "<STR_LIT>" , "<STR_LIT>" , master_ip ] ] <EOL> } <EOL> def recordings_spec ( domain , master_ip , port , registry , tag , connection_string ) : <EOL> return { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:image>" : "<STR_LIT>" % ( registry , tag ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT:0> } , <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : port + <NUM_LIT:5> } <EOL> ] <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> ] <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : connection_string , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" + domain <EOL> } , <EOL> "<STR_LIT>" : [ [ "<STR_LIT>" , "<STR_LIT>" , master_ip ] ] <EOL> } <EOL> def api_spec ( domain , master_ip , port , registry , tag , connection_string ) : <EOL> return { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:image>" : "<STR_LIT>" % ( registry , tag ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT:0> } <EOL> ] <EOL> } <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : connection_string , <EOL> "<STR_LIT>" : "<STR_LIT>" % ( master_ip , port + <NUM_LIT:1> ) , <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" % domain ] <EOL> } <EOL> def web_spec ( domain , master_ip , port , registry , tag , connection_string , google_login_client_id , google_login_client_secret , ga_tracking_id , marathon_url , marathon_login , marathon_password ) : <EOL> return { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:image>" : "<STR_LIT>" % ( registry , tag ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT:0> } <EOL> ] <EOL> } <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : connection_string , <EOL> "<STR_LIT>" : google_login_client_id , <EOL> "<STR_LIT>" : google_login_client_secret , <EOL> "<STR_LIT>" : ga_tracking_id , <EOL> "<STR_LIT>" : "<STR_LIT>" + domain , <EOL> "<STR_LIT>" : marathon_url , <EOL> "<STR_LIT>" : marathon_login , <EOL> "<STR_LIT>" : marathon_password , <EOL> "<STR_LIT>" : "<STR_LIT>" % ( master_ip , port ) , <EOL> "<STR_LIT>" : "<STR_LIT>" % ( master_ip , port + <NUM_LIT:5> ) <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" % domain ] <EOL> } <EOL> def worker_spec ( domain , master_ip , port , image , model , instances , registry , tag , env , cpu , mem ) : <EOL> env [ '<STR_LIT>' ] = "<STR_LIT>" % ( master_ip , port ) <EOL> env [ '<STR_LIT>' ] = "<STR_LIT>" % ( master_ip , port + <NUM_LIT:5> ) <EOL> env [ '<STR_LIT>' ] = model <EOL> return { <EOL> "<STR_LIT:id>" : "<STR_LIT>" + model , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:image>" : "<STR_LIT>" % ( registry , image , tag ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT:0> } <EOL> ] <EOL> } <EOL> } , <EOL> "<STR_LIT>" : instances , <EOL> "<STR_LIT>" : cpu , <EOL> "<STR_LIT>" : mem , <EOL> "<STR_LIT>" : env , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" % domain , <EOL> "<STR_LIT>" % domain <EOL> ] <EOL> } <EOL> def ensure_charset_is_in_connection_string ( connection_string ) : <EOL> if not "<STR_LIT>" in connection_string : <EOL> print "<STR_LIT>" <EOL> exit ( ) <EOL> return connection_string <EOL> def app_spec ( config ) : <EOL> domain = config [ "<STR_LIT>" ] <EOL> master_ip = config [ "<STR_LIT>" ] <EOL> port = config . get ( "<STR_LIT:port>" , <NUM_LIT> ) <EOL> registry = config . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> tag = config . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> connection_string = ensure_charset_is_in_connection_string ( config [ "<STR_LIT>" ] ) <EOL> google_login_client_id = config [ "<STR_LIT>" ] <EOL> google_login_client_secret = config [ "<STR_LIT>" ] <EOL> ga_tracking_id = config . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return { <EOL> "<STR_LIT:id>" : domain , <EOL> "<STR_LIT>" : [ <EOL> master_spec ( domain , master_ip , port , registry , tag ) , <EOL> monitor_spec ( domain , master_ip , port , registry , tag ) , <EOL> recordings_spec ( domain , master_ip , port , registry , tag , connection_string ) , <EOL> api_spec ( domain , master_ip , port , registry , tag , connection_string ) , <EOL> web_spec ( domain , master_ip , port , registry , tag , connection_string , google_login_client_id , google_login_client_secret , ga_tracking_id , config [ "<STR_LIT>" ] , config [ "<STR_LIT>" ] , config [ "<STR_LIT>" ] ) , <EOL> ] + [ <EOL> worker_spec ( domain , master_ip , port , worker [ "<STR_LIT:image>" ] , worker [ "<STR_LIT>" ] , worker [ "<STR_LIT>" ] , registry , tag , worker . get ( '<STR_LIT>' , { } ) , worker . get ( '<STR_LIT>' , <NUM_LIT:0.5> ) , worker . get ( '<STR_LIT>' , <NUM_LIT> ) ) for worker in config [ "<STR_LIT>" ] <EOL> ] <EOL> } <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( sys . argv ) != <NUM_LIT:2> : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> config = json . load ( open ( sys . argv [ <NUM_LIT:1> ] ) ) <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } <EOL> login = config . get ( "<STR_LIT>" , None ) <EOL> password = config . get ( "<STR_LIT>" , None ) <EOL> print app_spec ( config ) <EOL> r = requests . put ( config [ "<STR_LIT>" ] + "<STR_LIT>" , data = json . dumps ( app_spec ( config ) ) , headers = headers , auth = ( login , password ) ) <EOL> print r . json ( ) </s>
