]> gitweb.fluxo.info Git - hydra.git/commitdiff
Initial working version for a node tool and misc changes
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 13 Nov 2010 14:32:55 +0000 (12:32 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 13 Nov 2010 14:32:55 +0000 (12:32 -0200)
lib/hydra/misc
share/hydra/nodes
share/hydra/register

index 4695d5fea18c163384160e54e71c05884d093dfb..d83afbbf90c11a48aef55c2c9e1174b818fdba28 100644 (file)
@@ -2,11 +2,13 @@
 
 # Setup main configuration and load preferences
 function hydra_config_load {
-  if [ -f "$HOME/.$NAME" ]; then
+  local folder="`dirname $CONFIG`"
+
+  if [ -f "$folder" ]; then
     echo "Converting legacy configuration scheme..."
-    mv $HOME/.$NAME $HOME/.$NAME.tmp
-    mkdir $HOME/.$NAME
-    mv $HOME/.$NAME.tmp $CONFIG
+    mv $folder $folder.tmp
+    mkdir -p $folder
+    mv $folder.tmp $CONFIG
   fi
 
   if [ ! -e "$CONFIG" ]; then
@@ -23,10 +25,20 @@ function hydra_config_load {
 
 # Load config preferences
 function hydra_config_load_preferences {
-  # Load custom keyring preferences
+  # Load custom preferences
   if [ ! -z "$PREFERENCES" ] && [ -f "$PREFERENCES" ]; then
     source $PREFERENCES
   fi
+  
+  hydra_check_preferences
+}
+
+# Check preferences
+function hydra_check_preferences {
+  if [ ! -z "$PUPPET" ] && [ ! -d "$PUPPET" ]; then
+    echo "Puppet folder not found: $PUPPET."
+    exit 1
+  fi
 }
 
 # Load a parameter from config
@@ -70,7 +82,12 @@ function hydra_exec {
 
 # Set needed environment variables and do basic checks.
 function hydra_set_env {
+  export CONFIG="$HOME/.hydra/config"
   export ACTION="$1"
+
+  if [ ! -z "$HYDRA" ]; then
+    export PREFERENCES="$HOME/.hydra/$HYDRA"
+  fi
 }
 
 # Get a command argument
index 93593e1c4211397945657cffa0a0f7edab18c45e..c7e4c4cb78c8c0f8cde8a37624b55bf9159e143b 100755 (executable)
@@ -2,3 +2,24 @@
 #
 # Node tool.
 #
+
+# Default node retrieval method
+function hydra_get_nodes {
+  # See http://www.mail-archive.com/puppet-users@googlegroups.com/msg01615.html
+  grep ^node $* | sed -e 's/^node //' | awk -F, '{for(i=1;i<=NF;i++) {print $i}}' | cut -d "'" -f2
+}
+
+# Load functions
+source $APP_BASE/lib/hydra/functions || exit 1
+
+# Load config
+hydra_config_load
+
+# Validation
+if [ -z "$PUPPET" ]; then
+  echo "No PUPPET parameter defined at $HYDRA preferences."
+  exit 1
+fi
+
+# Get nodes
+hydra_get_nodes $PUPPET/manifests/nodes/*
index 5ef0a9d3527a38f84ea69a114c5d392a54f32530..e3d3ed641d04f776c681d276d8f82ce0d46856ca 100755 (executable)
@@ -3,10 +3,13 @@
 # Register an existing hydra
 #
 
-CONFIG="$HOME/.hydra/config"
-PREFERENCES="$HOME/.hydra/$HYDRA"
+# Load functions
+source $APP_BASE/lib/hydra/functions || exit 1
+
+# Command line arguments
 BASEDIR="$1"
 
+# Validation
 if [ -z "$BASEDIR" ]; then
   echo "Usage: hydra [hydra] register <path>"
   exit 1
@@ -15,15 +18,14 @@ elif grep -q -e "^$HYDRA=" $CONFIG &> /dev/null; then
   exit 1
 fi
 
-# Folder setup
-mkdir -p `dirname $CONFIG`
-
 # Reparse basedir to force absolute folder
 BASEDIR="`cd $BASEDIR && pwd`"
 
 # Add entry
 echo "Registering hydra $HYDRA..."
+mkdir -p $BASEDIR
 chmod 700 $BASEDIR
+hydra_config_load
 echo "$HYDRA=\"$BASEDIR\"" >> $CONFIG
 
 # Puppet configuration