forked from cnp3/CampusNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_node_utils.sh
executable file
·36 lines (31 loc) · 1.01 KB
/
_node_utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Common commands that are used by multiple scripts
# Get a node's config directory
# $1: node name
function node_cfg {
echo "${BDIR}/${CONFIGDIR}/$1"
}
# Get the config template directory
function template_cfg {
# Make the template dir if non-existent
mkdir -p "${BDIR}/${CONFIGDIR}/templates" > /dev/null &> /dev/null
echo "${BDIR}/${CONFIGDIR}/templates"
}
# Get the puppet module directory
function puppet_modules {
mkdir -p "${BDIR}/${CONFIGDIR}/puppetmodules" > /dev/null &> /dev/null
echo "${BDIR}/${CONFIGDIR}/puppetmodules"
}
# Get a node /run directory
# $1: node name
function node_rundir {
echo "/run/$1"
}
# Execute a command in a node
# $1: node name
# $@: command terms
function node_exec_command {
ip netns exec "$1" bash -c "mount --bind $(node_cfg $1) /etc && mkdir -p /templates \
&& mount --bind $(template_cfg) /templates && mkdir -p /puppetmodules \
&& mount --bind $(puppet_modules) /puppetmodules && mount --bind $(node_rundir $1) /run && ${@:2}"
}