finish cdist-object-codegen-all

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-02-16 20:24:58 +01:00
parent 6914071fe0
commit 80c745383a
3 changed files with 29 additions and 102 deletions

View file

@ -24,18 +24,25 @@ set -x
export PATH="$PATH:$(pwd -P)/bin" export PATH="$PATH:$(pwd -P)/bin"
object_tmp=/tmp/localhost/objects object_tmp=/tmp/localhost/objects
explorer_tmp=/tmp/localhost/explorers explorer_tmp=/tmp/localhost/explorers
exec_tmp=/tmp/localhost/exec
# Test first level manifest execution # Test first level manifest execution
__cdist_config=$(pwd -P)/conf cdist-manifest-init localhost "$object_tmp" __cdist_config=$(pwd -P)/conf cdist-manifest-init localhost "$object_tmp"
# See what it generated # See what it generated
find $object_tmp find "$object_tmp"
# Run explorer on a "remote" host # Run explorer on a "remote" host
__cdist_config=$(pwd -P)/conf cdist-explorer-run localhost "$explorer_tmp" __cdist_config=$(pwd -P)/conf cdist-explorer-run localhost "$explorer_tmp"
# Display result # Display result
find $explorer_tmp find "$explorer_tmp"
# Generate code for all objects in object dir
__cdist_config=$(pwd -P)/conf cdist-object-codegen-all localhost "$object_tmp" "$exec_tmp"
# Display result
find "$exec_tmp"
################################################################################ ################################################################################
# Soon working # Soon working
@ -43,9 +50,3 @@ find $explorer_tmp
# Generate all objects, including from types that generate objects as well # Generate all objects, including from types that generate objects as well
__cdist_config=$(pwd -P)/conf cdist-manifest-recursive-run localhost "$object_tmp" __cdist_config=$(pwd -P)/conf cdist-manifest-recursive-run localhost "$object_tmp"
# Generate code for one object
__cdist_config=$(pwd -P)/conf cdist-object-codegen localhost "$object_tmp" __file/etc-issue
# Generate code for all objects in object dir
__cdist_config=$(pwd -P)/conf cdist-code-gen-all localhost "$object_tmp"

View file

@ -142,8 +142,7 @@ __cdist_object_list()
cd "${basedir}" cd "${basedir}"
find . -name "$__cdist_name_object_source" | \ find . -name "$__cdist_name_object_source" | \
sed -e "s;$__cdist_name_object_source\$;;" \ sed -e "s;$__cdist_name_object_source\$;;" -e 's;^./;;'
-e 's;^./;;'
} }
__cdist_tmp_removal() __cdist_tmp_removal()

View file

@ -18,110 +18,37 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
# #
# For each created object # For each created object create the code to be executed on the
# run the manifest of the type (with object id), # target.
# try to merge back newly created objects (otherwise fail),
# mark the object as being run
# and iterate until all objects are marked being run.
#
#
# #
. cdist-config . cdist-config
if [ $# -ne 2 ]; then if [ $# -ne 3 ]; then
__cdist_usage "<target host> <object_dir>" __cdist_usage "<target host> <object_base_dir> <outdir>"
fi fi
set -eu set -eu
__cdist_target_host="$1"; shift __cdist_target_host="$1"; shift
__cdist_object_dir="$1"; shift __cdist_object_base_dir="$1"; shift
__cdist_exec_dir="$1"; shift
# change to directory containing objects # change to directory containing objects
cd "$__cdist_object_dir" # cd "$__cdist_object_base_dir"
# Loop until we do not create new objects anymore set -x
# which is equal to all objects have been run __cdist_object_list "$__cdist_object_base_dir" > "$__cdist_tmp_file"
__cdist_object_created_new=1
while [ "$__cdist_object_created_new" = 1 ]; do
# assume we're done after this run
__cdist_object_created_new=0
# find all objects (every object has the source recorded)
find . -name "$__cdist_object_source" | \
sed -e "s;$__cdist_object_source\$;;" \
-e 's;^./;;' \
> "$__cdist_tmp_file"
# FIXME: DEBUG
cat "$__cdist_tmp_file"
while read object; do while read object; do
if [ ! -f "${object}/$__cdist_object_finished" ]; then outdir="$__cdist_exec_dir/${object}"
echo "Working on object ${object} ..." outfile="${outdir}/${__cdist_name_exec}"
type=${object%%/*} mkdir -p "${outdir}"
manifest="$__cdist_type_dir/${type}/${__cdist_name_init}"
if [ -x "${manifest}" ]; then cdist-object-codegen "$__cdist_target_host" \
echo "Running manifest of type ${type} ..." "$__cdist_object_base_dir" \
"$object" > "${outfile}"
# FIXME: use subdir in tmpdir? chmod u+x "${outfile}"
cdist-manifest-run "$__cdist_target_host" "${manifest}" "${__cdist_tmp_dir}"
echo "Trying to merge... "
# list of new objects
cd "${__cdist_tmp_dir}"
find . -name "$__cdist_object_source" | \
sed -e "s;$__cdist_object_source\$;;" \
-e 's;^./;;' \
> "$__cdist_tmp_file"
while read newobject; do
if [ -e "$__cdist_object_dir/${newobject}" ]; then
__cdist_exit_err "${newobject} already exists, merge failed."
else
# Fine, merge back! FIXME: touch correct here?
touch "${newobject}/$__cdist_object_finished"
pax -r -w "$newobject" "$__cdist_object_dir"
fi
done < "$__cdist_tmp_file" done < "$__cdist_tmp_file"
# Always rerun the whole loop if we ran
# a manifest of an object
break
# FIXME: continue here
# tar, cp, pax, mv?
# mv/cp -n look good - posix?
# pax:
# pax -r -w -k could work, but -k does not raise an error if files
# are already existing
# - copy if not existing
# fail (abort whole recursive run) if existing
#
# iterate over all new objects and copy each back?
else
# Be nice, warn user if manifests exists, but is not executable
if [ -f "${manifest}" ]; then
echo "Warning ${manifest} is not executable"
fi
fi
# At least one more run needed
__cdist_object_created_new=1
fi
done < "$__cdist_tmp_file"
done
exit 0