#NEWLINE# def apply( squadron_dir , node_name , tempdir , resources , previous_run , dry_run = False ) : #NEWLINE# #INDENT# "\n    This method takes input from the given squadron_dir and configures\n    a temporary directory according to that information\n\n    Keyword arguments:\n        squadron_dir -- configuration directory for input\n        node_name -- this node's name\n        tempdir -- the base temporary directory to use\n        previous_run -- the previous successfully applied dir\n        dry_run -- whether or not to actually create the temp directory\n            or change any system-wide configuration via state file\n    " #NEWLINE# log . debug ( 'entering commit.apply %s' , [ squadron_dir , node_name , tempdir , resources , dry_run ] ) #NEWLINE# node_info = get_node_info ( os . path . join ( squadron_dir , 'nodes' ) , node_name ) #NEWLINE# if ( not check_node_info ( node_info ) ) : #NEWLINE# #INDENT# log . debug ( 'leaving commit.apply, check_node_info returned error' ) #NEWLINE# return ( False , None ) #NEWLINE# #UNINDENT# log . debug ( ( "node_info['env']: " + str ( node_info [ 'env' ] ) ) ) #NEWLINE# conf_dir = os . path . join ( squadron_dir , 'config' , node_info [ 'env' ] ) #NEWLINE# result = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# library_dir = os . path . join ( squadron_dir , 'libraries' ) #NEWLINE# state = StateHandler ( library_dir ) #NEWLINE# for service in node_info [ 'services' ] : #NEWLINE# #INDENT# configdata = _get_config ( conf_dir , service ) #NEWLINE# version = configdata [ 'version' ] #NEWLINE# base_dir = configdata [ 'base_dir' ] #NEWLINE# get_service_file = functools . partial ( _get_service_file , squadron_dir , service , version ) #NEWLINE# cfg = get_service_file ( 'defaults' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# cfg . update ( { #NEWLINE# #INDENT# 'node_name' : node_name , #NEWLINE# #UNINDENT# } ) #NEWLINE# cfg . update ( configdata [ 'config' ] ) #NEWLINE# schema = get_service_file ( 'schema' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if schema : #NEWLINE# #INDENT# jsonschema . validate ( cfg , schema ) #NEWLINE# #UNINDENT# stateinfo = get_service_file ( 'state' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , config = cfg ) #NEWLINE# for state_item in stateinfo : #NEWLINE# #INDENT# library = state_item [ 'name' ] #NEWLINE# items = state_item [ 'parameters' ] #NEWLINE# if ( isinstance ( items [ 0 ] , str ) or isinstance ( items [ 0 ] , unicode ) ) : #NEWLINE# #INDENT# print_items = ', ' . join ( items ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print_items = items #NEWLINE# #UNINDENT# log . info ( '%s %s through %s' , ( 'Would process' if dry_run else 'Processing' ) , print_items , library ) #NEWLINE# state . apply ( library , items , dry_run ) #NEWLINE# #UNINDENT# service_dir = os . path . join ( squadron_dir , 'services' , service , version , 'root' ) #NEWLINE# render = DirectoryRender ( service_dir ) #NEWLINE# tmp_serv_dir = os . path . join ( tempdir , service ) #NEWLINE# makedirsp ( tmp_serv_dir ) #NEWLINE# atomic = render . render ( tmp_serv_dir , cfg , resources , dry_run ) #NEWLINE# copy_config = get_service_file ( 'copy' , [ ] , config = cfg ) #NEWLINE# _apply_copy ( copy_config , previous_run , service , tmp_serv_dir ) #NEWLINE# result [ service ] = { #NEWLINE# #INDENT# 'atomic' : atomic , #NEWLINE# 'base_dir' : base_dir , #NEWLINE# 'config' : cfg , #NEWLINE# 'dir' : tmp_serv_dir , #NEWLINE# 'version' : version , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# log . debug ( ( 'leaving commit.apply: ' + str ( result ) ) ) #NEWLINE# return result