<s> import time , sys , os , config <EOL> from comodit_client . api import Client <EOL> from comodit_client . api . exceptions import PythonApiException <EOL> from comodit_client . api . collection import EntityNotFoundException <EOL> from comodit_client . rest . exceptions import ApiException <EOL> from comodit_client . api . host import Host <EOL> from helper import create_host , get_short_hostname <EOL> def deploy ( ) : <EOL> print "<STR_LIT>" <EOL> start_time = time . time ( ) <EOL> NUM_OF_MON = <NUM_LIT:1> <EOL> NUM_OF_OSD = <NUM_LIT:2> <EOL> client = Client ( config . endpoint , config . username , config . password ) <EOL> env = client . get_environment ( config . organization , '<STR_LIT>' ) <EOL> for key in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> try : <EOL> env . settings ( ) . create ( key , [ ] ) <EOL> except : <EOL> pass <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> try : <EOL> env . settings ( ) . create ( "<STR_LIT>" , config . admin_key ) <EOL> except : <EOL> pass <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> conf_app = [ { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : { } } ] <EOL> mon_hosts = [ ] <EOL> for i in xrange ( <NUM_LIT:0> , NUM_OF_MON ) : <EOL> try : <EOL> mon = env . get_host ( '<STR_LIT>' + str ( i ) ) <EOL> except EntityNotFoundException : <EOL> mon = create_host ( env , '<STR_LIT>' + str ( i ) , config . platform , config . distribution , conf_app ) <EOL> print "<STR_LIT>" + str ( i ) <EOL> mon . provision ( ) <EOL> mon_hosts . append ( mon ) <EOL> osd_hosts = [ ] <EOL> for i in xrange ( <NUM_LIT:0> , NUM_OF_OSD ) : <EOL> try : <EOL> osd = env . get_host ( '<STR_LIT>' + str ( i ) ) <EOL> except EntityNotFoundException : <EOL> osd = create_host ( env , '<STR_LIT>' + str ( i ) , config . platform , config . distribution , conf_app ) <EOL> print "<STR_LIT>" + str ( i ) <EOL> osd . provision ( ) <EOL> osd_hosts . append ( osd ) <EOL> print "<STR_LIT>" <EOL> for h in mon_hosts + osd_hosts : <EOL> h . wait_for_state ( Host . State . READY , config . time_out ) <EOL> mon_ips = [ ] <EOL> mon_names = [ ] <EOL> mon_addrs = [ ] <EOL> for h in mon_hosts : <EOL> ip = h . get_instance ( ) . wait_for_property ( "<STR_LIT>" , config . time_out ) <EOL> mon_ips . append ( ip ) <EOL> mon_names . append ( get_short_hostname ( h . get_instance ( ) . wait_for_property ( "<STR_LIT>" , config . time_out ) ) ) <EOL> mon_addrs . append ( ip + "<STR_LIT>" ) <EOL> osd_ips = [ ] <EOL> osd_names = [ ] <EOL> for h in osd_hosts : <EOL> osd_ips . append ( h . get_instance ( ) . wait_for_property ( "<STR_LIT>" , config . time_out ) ) <EOL> osd_names . append ( get_short_hostname ( h . get_instance ( ) . wait_for_property ( "<STR_LIT>" , config . time_out ) ) ) <EOL> for i in xrange ( <NUM_LIT:0> , len ( mon_addrs ) ) : <EOL> print "<STR_LIT>" % ( i , mon_addrs [ i ] , mon_names [ i ] ) <EOL> for i in xrange ( <NUM_LIT:0> , len ( osd_ips ) ) : <EOL> print "<STR_LIT>" % ( i , osd_ips [ i ] , osd_names [ i ] ) <EOL> print <EOL> print "<STR_LIT>" <EOL> monitors = [ ] <EOL> for i in xrange ( <NUM_LIT:0> , len ( mon_addrs ) ) : <EOL> monitors . append ( { "<STR_LIT:id>" : str ( i ) , "<STR_LIT:host>" : mon_names [ i ] , "<STR_LIT>" : mon_addrs [ i ] } ) <EOL> osds = [ ] <EOL> for i in xrange ( <NUM_LIT:0> , len ( osd_names ) ) : <EOL> osds . append ( { "<STR_LIT:id>" : str ( i ) , "<STR_LIT:host>" : osd_names [ i ] } ) <EOL> mdss = [ ] <EOL> for i in xrange ( <NUM_LIT:0> , len ( mon_names ) ) : <EOL> mdss . append ( { "<STR_LIT:id>" : str ( i ) , "<STR_LIT:host>" : mon_names [ i ] } ) <EOL> env . settings ( ) . update ( "<STR_LIT>" , monitors ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> env . settings ( ) . update ( "<STR_LIT>" , osds ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> env . settings ( ) . update ( "<STR_LIT>" , mdss ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> env . settings ( ) . update ( "<STR_LIT>" , config . admin_key ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> print "<STR_LIT>" <EOL> mon_hosts [ <NUM_LIT:0> ] . install ( "<STR_LIT>" , { "<STR_LIT>" : True , "<STR_LIT>" : "<STR_LIT:0>" , "<STR_LIT>" : mon_addrs [ <NUM_LIT:0> ] } ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> mon_hosts [ <NUM_LIT:0> ] . install ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT:0>" } ) <EOL> mon_hosts [ <NUM_LIT:0> ] . wait_for_pending_changes ( ) <EOL> print "<STR_LIT>" <EOL> for i in xrange ( <NUM_LIT:1> , len ( mon_hosts ) ) : <EOL> mon_hosts [ i ] . install ( "<STR_LIT>" , { "<STR_LIT>" : str ( i ) } ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> mon_hosts [ i ] . install ( "<STR_LIT>" , { "<STR_LIT>" : str ( i ) } ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> for h in mon_hosts : <EOL> h . wait_for_pending_changes ( ) <EOL> print "<STR_LIT>" <EOL> for i in xrange ( <NUM_LIT:0> , len ( osd_hosts ) ) : <EOL> osd_hosts [ i ] . install ( "<STR_LIT>" , { "<STR_LIT>" : str ( i ) , "<STR_LIT>" : osd_names [ i ] } ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> for h in osd_hosts : <EOL> h . wait_for_pending_changes ( ) <EOL> total_time = time . time ( ) - start_time <EOL> print "<STR_LIT>" % ( mon_hosts [ <NUM_LIT:0> ] . get_instance ( ) . wait_for_address ( config . time_out ) ) <EOL> print "<STR_LIT>" + str ( total_time ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> deploy ( ) <EOL> except PythonApiException as e : <EOL> print e </s>
