<s> import time , sys , os , config , string , random <EOL> from comodit_client . api . exceptions import PythonApiException <EOL> from comodit_client . rest . exceptions import ApiException <EOL> def create_host ( env , name , platform , distribution , applications = [ ] ) : <EOL> host = env . hosts ( ) . create ( name , "<STR_LIT>" , platform [ '<STR_LIT:name>' ] , distribution [ '<STR_LIT:name>' ] ) <EOL> context = host . get_platform ( ) <EOL> for key , value in platform [ '<STR_LIT>' ] . iteritems ( ) : <EOL> context . settings ( ) . create ( key , value ) <EOL> context = host . get_distribution ( ) <EOL> for key , value in distribution [ '<STR_LIT>' ] . iteritems ( ) : <EOL> context . settings ( ) . create ( key , value ) <EOL> for app in applications : <EOL> host . install ( app [ '<STR_LIT:name>' ] , app [ '<STR_LIT>' ] ) <EOL> return host <EOL> def get_short_hostname ( hostname ) : <EOL> parts = hostname . split ( '<STR_LIT:.>' ) <EOL> return parts [ <NUM_LIT:0> ] <EOL> def get_latest_id ( prefix , env ) : <EOL> names = env . hosts_f <EOL> last_id = - <NUM_LIT:1> <EOL> for name in names : <EOL> if name . startswith ( prefix ) : <EOL> i = int ( name [ len ( prefix ) : ] . rstrip ( ) ) <EOL> if i > last_id : <EOL> last_id = i <EOL> return last_id <EOL> def generate_id ( size = <NUM_LIT:6> , chars = string . ascii_uppercase + string . digits ) : <EOL> return '<STR_LIT>' . join ( random . choice ( chars ) for x in range ( size ) ) <EOL> def track_changes ( host ) : <EOL> changes = host . changes ( ) . list ( ) <EOL> c = changes [ - <NUM_LIT:1> ] <EOL> current_task = - <NUM_LIT:1> <EOL> done = False <EOL> while not done : <EOL> for t in c . tasks : <EOL> if t . order_num < current_task : <EOL> continue <EOL> if t . order_num == current_task : <EOL> if t . status == "<STR_LIT:OK>" : <EOL> print "<STR_LIT>" <EOL> if current_task == len ( c . tasks ) - <NUM_LIT:1> : <EOL> done = True <EOL> continue <EOL> elif t . status == "<STR_LIT>" : <EOL> print "<STR_LIT>" % t . error [ : <NUM_LIT> ] <EOL> if current_task == len ( c . tasks ) - <NUM_LIT:1> : <EOL> done = True <EOL> continue <EOL> if t . status == "<STR_LIT>" : <EOL> break <EOL> current_task = t . order_num <EOL> sys . stdout . write ( "<STR_LIT>" % t . description ) <EOL> sys . stdout . flush ( ) <EOL> break <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> c . refresh ( ) </s>
