refactor so that there is no interaction between code-local and code-remote
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								a3dea70a97
							
						
					
				
			
			
				commit
				
					
						fcfd2d0a3c
					
				
			
		
					 3 changed files with 19 additions and 20 deletions
				
			
		| 
						 | 
					@ -53,11 +53,24 @@ if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
   fi
 | 
					   fi
 | 
				
			||||||
   if [ "$create_file" -o "$upload_file" ]; then
 | 
					   if [ "$create_file" -o "$upload_file" ]; then
 | 
				
			||||||
 | 
					      # tell gencode-remote that we created or uploaded a file and that it must
 | 
				
			||||||
 | 
					      # set all attributes no matter what the explorer retreived
 | 
				
			||||||
      mkdir "$__object/files"
 | 
					      mkdir "$__object/files"
 | 
				
			||||||
 | 
					      touch "$__object/files/set-attributes"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # upload file to temp location
 | 
				
			||||||
      tempfile_template="${destination}.cdist.XXXXXXXXXX"
 | 
					      tempfile_template="${destination}.cdist.XXXXXXXXXX"
 | 
				
			||||||
      echo "$__remote_exec ${__target_host} \"mktemp $tempfile_template\" > \"$__object/files/destination_upload\""
 | 
					      cat << DONE
 | 
				
			||||||
 | 
					destination_upload="\$($__remote_exec $__target_host "mktemp $tempfile_template")"
 | 
				
			||||||
 | 
					DONE
 | 
				
			||||||
      if [ "$upload_file" ]; then
 | 
					      if [ "$upload_file" ]; then
 | 
				
			||||||
         echo "$__remote_copy $source ${__target_host}:\$(cat \"$__object/files/destination_upload\")"
 | 
					         cat << DONE
 | 
				
			||||||
 | 
					$__remote_copy $source ${__target_host}:\$destination_upload
 | 
				
			||||||
 | 
					DONE
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
 | 
					# move uploaded file into place
 | 
				
			||||||
 | 
					cat << DONE
 | 
				
			||||||
 | 
					$__remote_exec $__target_host "rm -rf \"$destination\"; mv \"\$destination_upload\" \"$destination\""
 | 
				
			||||||
 | 
					DONE
 | 
				
			||||||
   fi
 | 
					   fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,29 +57,13 @@ set_mode() {
 | 
				
			||||||
set_attributes=
 | 
					set_attributes=
 | 
				
			||||||
case "$state_should" in
 | 
					case "$state_should" in
 | 
				
			||||||
   present|exists)
 | 
					   present|exists)
 | 
				
			||||||
      if [ -f "$__object/files/destination_upload" ]; then
 | 
					 | 
				
			||||||
         # we uploaded a file, move it into place and set all attributes
 | 
					 | 
				
			||||||
         destination_upload="$(cat "$__object/files/destination_upload")"
 | 
					 | 
				
			||||||
         set_attributes=1
 | 
					 | 
				
			||||||
         if [ "$type" = "directory" ]; then
 | 
					 | 
				
			||||||
            # our destination is currently a directory, delete it
 | 
					 | 
				
			||||||
            cat << DONE
 | 
					 | 
				
			||||||
rm -rf "$destination"
 | 
					 | 
				
			||||||
DONE
 | 
					 | 
				
			||||||
         fi
 | 
					 | 
				
			||||||
         # move our upload into place
 | 
					 | 
				
			||||||
         cat << DONE
 | 
					 | 
				
			||||||
mv "$destination_upload" "$destination"
 | 
					 | 
				
			||||||
DONE
 | 
					 | 
				
			||||||
      fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
 | 
					      # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
 | 
				
			||||||
      #  clearing S_ISUID and S_ISGID bits (see chown(2))
 | 
					      #  clearing S_ISUID and S_ISGID bits (see chown(2))
 | 
				
			||||||
      for attribute in group owner mode; do
 | 
					      for attribute in group owner mode; do
 | 
				
			||||||
         if [ -f "$__object/parameter/$attribute" ]; then
 | 
					         if [ -f "$__object/parameter/$attribute" ]; then
 | 
				
			||||||
            value_should="$(cat "$__object/parameter/$attribute")"
 | 
					            value_should="$(cat "$__object/parameter/$attribute")"
 | 
				
			||||||
            value_is="$(get_current_value "$attribute" "$value_should")"
 | 
					            value_is="$(get_current_value "$attribute" "$value_should")"
 | 
				
			||||||
            if [ "$set_attributes" -o "$value_should" != "$value_is" ]; then
 | 
					            if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
 | 
				
			||||||
               "set_$attribute" "$value_should"
 | 
					               "set_$attribute" "$value_should"
 | 
				
			||||||
            fi
 | 
					            fi
 | 
				
			||||||
         fi
 | 
					         fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -249,7 +249,7 @@ class Config(object):
 | 
				
			||||||
        cdist_type = cdist_object.cdist_type
 | 
					        cdist_type = cdist_object.cdist_type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Generate
 | 
					        # Generate
 | 
				
			||||||
        self.log.info("Generating and executing code for %s" % (cdist_object.name))
 | 
					        self.log.info("Generating code for %s" % (cdist_object.name))
 | 
				
			||||||
        cdist_object.code_local = self.code.run_gencode_local(cdist_object)
 | 
					        cdist_object.code_local = self.code.run_gencode_local(cdist_object)
 | 
				
			||||||
        cdist_object.code_remote = self.code.run_gencode_remote(cdist_object)
 | 
					        cdist_object.code_remote = self.code.run_gencode_remote(cdist_object)
 | 
				
			||||||
        if cdist_object.code_local or cdist_object.code_remote:
 | 
					        if cdist_object.code_local or cdist_object.code_remote:
 | 
				
			||||||
| 
						 | 
					@ -257,6 +257,8 @@ class Config(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Execute
 | 
					        # Execute
 | 
				
			||||||
        if not self.dry_run:
 | 
					        if not self.dry_run:
 | 
				
			||||||
 | 
					            if cdist_object.code_local or cdist_object.code_remote:
 | 
				
			||||||
 | 
					                self.log.info("Executing code for %s" % (cdist_object.name))
 | 
				
			||||||
            if cdist_object.code_local:
 | 
					            if cdist_object.code_local:
 | 
				
			||||||
                self.code.run_code_local(cdist_object)
 | 
					                self.code.run_code_local(cdist_object)
 | 
				
			||||||
            if cdist_object.code_remote:
 | 
					            if cdist_object.code_remote:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue