forked from Nordix/xcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvsettings
132 lines (110 loc) · 3.29 KB
/
Envsettings
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! /bin/sh
test -n "$XCLUSTER" && return 0
if ! ./xcadmin.sh env_check; then
cat <<EOF
# Install dependecies;
sudo apt install -y net-tools qemu-kvm xterm screen
# Add user to the "kvm" group;
sudo usermod -a -G kvm $USER
# (logout/login after usermod)
EOF
return 0
fi
if test -z "$XCLUSTER_WORKSPACE"; then
export XCLUSTER_WORKSPACE="$(readlink -f .)/workspace"
if ! test -d "$XCLUSTER_WORKSPACE"; then
mkdir -p "$XCLUSTER_WORKSPACE"
cat <<EOF
The \$XCLUSTER_WORKSPACE is set to;
XCLUSTER_WORKSPACE=$XCLUSTER_WORKSPACE
EOF
fi
fi
test -n "$ARCHIVE" || export ARCHIVE=$HOME/Downloads
mkdir -p $ARCHIVE
cdo() {
cd $($XCLUSTER ovld $1)
}
export XCLUSTER="$(readlink -f .)/xcluster.sh"
alias xc=$XCLUSTER
alias xcadmin="$(readlink -f .)/xcadmin.sh"
eval $($XCLUSTER env | grep -i DISKIM)
export DISKIM
alias diskim=$DISKIM
which mke2fs > /dev/null || export PATH=$PATH:/sbin:/usr/sbin
if ip netns id | grep -q -E "xcluster[0-9]+\$"; then
# We are in a netns. Reset the $__net_setup is it is set for main
# netns.
echo $__net_setup | grep -q '/config/net-setup-userspace.sh' && \
unset __net_setup
vm() {
local bg='#040'
test "$1" -gt 200 && bg='#400'
test "$1" -gt 220 && bg='#004'
XXTERM=XCLUSTER exec xterm -T "vm-$1" -fg wheat -bg "$bg" $xtermopt \
-e "telnet 192.168.0.$1" &
}
else
# We are not in a xcluster netns. Use user-space networking.
export __net_setup="$(readlink -f .)/config/net-setup-userspace.sh"
vm() {
local bg='#040'
test "$1" -gt 200 && bg='#400'
test "$1" -gt 220 && bg='#004'
local nodeid=$1
local p=$((12000+nodeid))
test -n "$XCLUSTER_TELNET_BASE" && p=$((XCLUSTER_TELNET_BASE+nodeid))
XXTERM=XCLUSTER exec xterm -T "vm-$1" -fg wheat -bg "$bg" $xtermopt \
-e "telnet 127.0.0.1 $p" &
}
fi
mynetns=$(ip netns id)
if ! netstat -lutan | grep -q :::10053; then
cdns=$GOPATH/bin/coredns
test -x $cdns || cdns=$XCLUSTER_WORKSPACE/bin/coredns
if test -x $cdns; then
cdnslog=/tmp/$USER/coredns.log
test -n "$mynetns" && cdnslog=/tmp/$USER/coredns-$mynetns.log
mkdir -p /tmp/$USER
echo "Starting a local coredns on port 10053. Log in $cdnslog"
$cdns -conf "$(readlink -f .)/config/Corefile" > $cdnslog 2>&1 &
else
echo "WARNING: CoreDNS not found. DNS from within the cluster will not work!"
fi
unset cdns cdnslog
fi
alias images="$(readlink -f .)/ovl/images/images.sh"
test -n "$__dns_spoof" || export __dns_spoof=$(readlink -f .)/config/dns-spoof.txt
# completion is a bash thing
ps -p $$ | grep -q bash || return 0
test -n "$PS1" || return 0
_cdo_completion() {
local XCLUSTER_OVLPATH d o
eval $($XCLUSTER env | grep XCLUSTER_OVLPATH=)
for d in $(echo $XCLUSTER_OVLPATH | tr : ' '); do
test -d $d || continue
o+=$(find $d -mindepth 1 -maxdepth 1 -type d -name "$2*" -printf "%f ")
done
COMPREPLY=($o)
}
complete -F _cdo_completion cdo
_xc_completion() {
COMPREPLY=($($XCLUSTER completion $2))
}
complete -F _xc_completion xc
lso() {
local XCLUSTER_OVLPATH d arg
eval $($XCLUSTER env | grep XCLUSTER_OVLPATH=)
for d in $(echo $XCLUSTER_OVLPATH | tr : '\n' | sort -u); do
arg="$arg $d/*"
done
if echo $@ | grep -qF -- '-t'; then
\ls -dt $arg | sed -E 's,.*/([^/]+),\1,'
else
if test -t 1 -o "$1" = '-c'; then
\ls -d $arg | sed -E 's,.*/([^/]+),\1,' | sort -u | column
else
\ls -d $arg | sed -E 's,.*/([^/]+),\1,' | sort -u
fi
fi
}