Skip to content

Commit 5594da1

Browse files
wjhnaichuans
wjh
authored andcommitted
xs-openstack: Save hackathon code
Save hackathon code for xva openstack scale out
1 parent b4caf02 commit 5594da1

File tree

7 files changed

+317
-0
lines changed

7 files changed

+317
-0
lines changed

scaleComputeUsingXVA/config.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[ComputeHost]
2+
#name=xrtuk-11-36
3+
name=xrtuk-11-36
4+
#ip=10.62.65.34
5+
ip=10.71.192.128
6+
user=root
7+
password=xenroot
8+
9+
[ComputeNode]
10+
name=computeTest
11+
user=root
12+
password=admin
13+
ip=10.71.193.2
14+
15+
[ControlNode]
16+
ip=10.62.20.182
17+
18+
19+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -x
3+
4+
source ./readconfig.sh
5+
6+
set -x
7+
8+
function init_conf_info() {
9+
CNODE_USER=$(readIni config.ini ComputeNode user)
10+
CNODE_PWD=$(readIni config.ini ComputeNode password)
11+
cnode_ip=$(readIni config.ini ComputeNode ip)
12+
host_ip=$(readIni config.ini ComputeHost ip)
13+
ctl_ip=$(readIni config.ini ControlNode ip)
14+
}
15+
16+
function config_cnode_entry() {
17+
set -ex
18+
if [ ! -f $CNODE_INFO_FILE ]; then
19+
exit -1
20+
fi
21+
echo $CNODE_INFO_FILE
22+
init_conf_info
23+
for ip in $cnode_ip
24+
do
25+
echo $cnode_ip
26+
create_no_pwd_access $cnode_ip $CNODE_USER $CNODE_PWD
27+
on_no_pwd_host $cnode_ip $CNODE_USER << CONFIG_CNODE_BLOCK
28+
if ! sudo ls ~root/.ssh;
29+
then
30+
sudo mkdir -p ~root/.ssh/
31+
fi
32+
CONFIG_CNODE_BLOCK
33+
34+
scp $_SSH_OPTIONS ssh_key.priv root@$ip:/root/.ssh/id_rsa
35+
scp $_SSH_OPTIONS ssh_key.priv.pub root@$ip:/root/.ssh/id_rsa.pub
36+
37+
create_no_pwd_access $host_ip root xenroot
38+
on_no_pwd_host $cnode_ip $CNODE_USER << CONFIG_CNODE_BLOCK
39+
40+
set +e
41+
set -x
42+
sudo sed -i "s/10.62.66.6/$ctl_ip/g" \`grep 10.62.66.6 -rl /etc/\`
43+
DEST=/opt/stack XENAPI_CONNECTION_URL="http://$host_ip" DOMZERO_USER='root' /opt/stack/os-xenapi/devstack/plugin.sh 'stack' install
44+
CONFIG_CNODE_BLOCK
45+
46+
done
47+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
source ./readconfig.sh
5+
6+
ComputeHostName=$(readIni config.ini ComputeHost name)
7+
ComputeHostIP=$(readIni config.ini ComputeHost ip)
8+
ComputeHostUser=$(readIni config.ini ComputeHost user)
9+
ComputeHostPassword=$(readIni config.ini ComputeHost password)
10+
ComputeNodeName=$(readIni config.ini ComputeNode name)
11+
ComputeNodeUser=$(readIni config.ini ComputeNode user)
12+
ComputeNodePassword=$(readIni config.ini ComputeNode password)
13+
14+
15+
#sshpass -p "xenroot" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] "pwd; ls"
16+
# ssh_command $host $user $password $command
17+
sudo apt-get install sshpass
18+
19+
function ssh_command {
20+
sshpass -p ${ComputeHostPassword} ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${ComputeHostUser}@${ComputeHostIP} $@
21+
}
22+
23+
VMUUID=""
24+
VMIP=""
25+
ControllerIP="10.62.66.6"
26+
27+
28+
function import_cpu {
29+
importXva="xe vm-import filename=/root/computeNodeFinal.xva"
30+
VMUUID=$(ssh_command $importXva)
31+
}
32+
33+
function start_cpu {
34+
start_cpu="xe vm-start uuid=$VMUUID"
35+
ssh_command $start_cpu
36+
}
37+
38+
function get_xva_ip {
39+
local period=10
40+
local max_tries=10
41+
local i=0
42+
43+
local get_ip="xe vm-param-get uuid=$VMUUID param-name=networks | tr ';' '\n' | grep '0/ip:' | cut -d: -f2"
44+
while true; do
45+
if [ $i -ge $max_tries ]; then
46+
echo "Timeout; ip address for VM: $VMUUID"
47+
exit 11
48+
fi
49+
50+
ipaddress=$(ssh_command $get_ip)
51+
52+
if [ -z "$ipaddress" ]; then
53+
sleep $period
54+
i=$((i+1))
55+
else
56+
VMIP=$(echo $ipaddress | sed s/[[:space:]]//g)
57+
break
58+
fi
59+
done
60+
}
61+
62+
function write_config {
63+
writeIni config.ini ComputeNode ip $VMIP
64+
}
65+
66+
function ssh_cpu {
67+
sshpass -p ${ComputeNodePassword} ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${ComputeNodeUser}@${VMIP} $@
68+
}
69+
70+
function configure_cpu_hostIP {
71+
findfile="grep -lr computeHostIP /etc"
72+
files=$(ssh_cpu $findfile)
73+
for file in $files; do
74+
ssh_cpu sed -i \"s/computeHostIP/${ComputeHostIP}/g\" $file
75+
done
76+
}
77+
78+
function configure_cpu_controllerIP {
79+
findfile="grep -lr controllerIP /etc"
80+
files=$(ssh_cpu $findfile)
81+
for file in $files; do
82+
ssh_cpu sed -i \"s/controllerIP/${ControllerIP}/g\" $file
83+
done
84+
}
85+
86+
function configure_cpu_hostName {
87+
findfile="grep -lr computeHostName /etc"
88+
files=$(ssh_cpu $findfile)
89+
for file in $files; do
90+
ssh_cpu sed -i \"s/computeHostName/${ComputeHostName}/g\" $file
91+
done
92+
}
93+
94+
function configure_cpu_myIP {
95+
findfile="grep -lr computeNodeMyIP /etc"
96+
files=$(ssh_cpu $findfile)
97+
for file in $files; do
98+
ssh_cpu sed -i \"s/computeNodeMyIP/${VMIP}/g\" $file
99+
done
100+
}
101+
102+
function prepare_cpu_node_entry {
103+
import_cpu
104+
start_cpu
105+
get_xva_ip
106+
write_config
107+
configure_cpu_hostIP
108+
configure_cpu_controllerIP
109+
configure_cpu_hostName
110+
configure_cpu_myIP
111+
}
112+

scaleComputeUsingXVA/readconfig.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
readIni() {
2+
file=$1;section=$2;item=$3;
3+
val=$(awk -F '=' '/\['${section}'\]/{a=1} (a==1 && "'${item}'"==$1){a=0;print $2}' ${file})
4+
echo ${val}
5+
}
6+
7+
writeIni() {
8+
file=$1;section=$2;item=$3;val=$4
9+
awk -F '=' '/\['${section}'\]/{a=1} (a==1 && "'${item}'"==$1){gsub($2,"'${val}'");a=0} {print $0}' ${file} 1<>${file}
10+
}
11+
12+
readIniSections() {
13+
file=$1;
14+
val=$(awk '/\[/{printf("%s ",$1)}' ${file} | sed 's/\[//g' | sed 's/\]//g')
15+
echo ${val}
16+
}

scaleComputeUsingXVA/scale_out_cpu.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
tmp_path=$(mktemp -d)
5+
CNODE_INFO_FILE=$tmp_path/cnode_info.txt
6+
host_inv_path=''
7+
controller_ip=''
8+
9+
# the format of compute node information should like:
10+
# host_ip: XENSERVER_IP_ADDR1 cnode_ip: CPU_IP_ADDR1
11+
# host_ip: XENSERVER_IP_ADDR2 cnode_ip: CPU_IP_ADDR2
12+
# ...
13+
echo "cnode_ip: CPU_IP_ADDR" > $CNODE_INFO_FILE
14+
15+
REMAINING_OPTIONS="$#"
16+
while getopts ":i:p:" flag; do
17+
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
18+
case "$flag" in
19+
i)
20+
host_inv_path="$OPTARG"
21+
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
22+
;;
23+
p)rm
24+
controller_ip="$OPTARG"
25+
REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1)
26+
;;
27+
\?)
28+
echo "Unexpected argument"
29+
exit -1
30+
esac
31+
done
32+
33+
if [ ! -f ssh_key.priv ]
34+
then
35+
yes | ssh-keygen -t rsa -N "" -f ssh_key.priv
36+
fi
37+
38+
# Set up internal variables
39+
_SSH_OPTIONS="\
40+
-o BatchMode=yes \
41+
-o StrictHostKeyChecking=no \
42+
-o UserKnownHostsFile=/dev/null \
43+
-i ssh_key.priv"
44+
45+
# input the server ip, username and password to acheive no pwd access
46+
function create_no_pwd_access() {
47+
username=$2
48+
server_ip=$1
49+
password=$3
50+
sshpass -p $password \
51+
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
52+
$username@$server_ip "if [ ! -f ~/.ssh/authorized_keys ]; then mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys; fi"
53+
PUBKEY=$(cat ssh_key.priv.pub)
54+
sshpass -p $password \
55+
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
56+
$username@$server_ip "echo $PUBKEY >> ~/.ssh/authorized_keys"
57+
}
58+
# excute remote shell on no pwd host
59+
function on_no_pwd_host() {
60+
username=$2
61+
server_ip=$1
62+
ssh $_SSH_OPTIONS "$username@$server_ip" bash -s --
63+
}
64+
65+
source prepare_cpu_node.sh # managed by liang
66+
source config_cpu_node.sh
67+
68+
prepare_cpu_node_entry # managed by liang
69+
config_cnode_entry
70+
echo $?
71+
set -x
72+
73+
source ./readconfig.sh
74+
75+
CNODE_USER=$(readIni config.ini ComputeNode user)
76+
CNODE_PWD=$(readIni config.ini ComputeNode password)
77+
cnode_ip=$(readIni config.ini ComputeNode ip)
78+
host_ip=$(readIni config.ini ComputeHost ip)
79+
80+
on_no_pwd_host $cnode_ip $CNODE_USER <<CMDEND
81+
set -x
82+
# service start staff
83+
service_list=\$(ls -al /etc/systemd/system | grep devstack@ | awk '{ print \$9 }')
84+
for srv in \$service_list
85+
do
86+
systemctl enable \$srv 2>&1 | tee -a /tmp/test.wjh
87+
systemctl start \$srv
88+
done
89+
CMDEND
90+
#nova-manage cell_v2 simple_cell_setup
91+
/opt/stack/devstack/tools/discover_hosts.sh > /tmp/dis.log
92+
# verify staff
93+
# log staff
94+
95+
rm -rf $tmp_path

scaleComputeUsingXVA/ssh_key.priv

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEowIBAAKCAQEAv1I/e4g0sD6SKIHuobwHziTZjkZLZH1XUM4VGIhSxuhQuUFD
3+
KlGIfDvompjeyBpV5v/MfS/t+oNWufdevZToCc6Upzb1q5Q6gdXGDbxvD6fwxluc
4+
O05+d7DF3K5qn78cFLLwbo4ZrTcT1iMrm4SoGloMEi5+6le5bxvLkFQ+AgiKT5Gf
5+
RefM26fsosxVMKM5QvTu5m62am8FUSXrNJ7uxW5QpCp7bWfrbtvjewsndmRkYa9s
6+
Pm8yNxYg30x/951DJNyciTAWmH04a6J42GLbwqIFPuiI1iyY3omuMVP9vgRU9OkB
7+
3WeaDt4qMWbBoWCirO0f2wC3pxMsEyuNHKRQVQIDAQABAoIBAFoPW3bJHRRBwAd1
8+
cmGL45i0W/zPNjotjmapO+D6ewzK2wT5paZMDxV8FfiAMY68ZueATkA3yax9Gtwb
9+
h+tyJvBG4E7+XhLQieIIQVzB8P3LrlmRUi/QuVOaUOma6PIdwhg0S12fYpLZNGs+
10+
zw48Ge2dqcT9Qh0KAm49BUwBe9b0Yc3laT7+Sj3w4h32C83NS9sstFuiYQ1E3AOT
11+
SWEYcrSwIRufWzB74vuUS8zZDb2KQGPTVdHHR8yl78KU2wCLoKT0dUg5qCEreqdX
12+
9hHTJrF1X5E6N2cdLAc2icEqKRY9xtBECcT25OpZcHUkkwXIfxLFuNc7TvQwCF97
13+
KtGc9IECgYEA4nE2Z0Z/Q7EiBGLGjnsL0ftA9Q4Gr2U/UQIOyhffQW4v0IiXbvbW
14+
jALMEc6iWh9clFZY7hAlU32bFCsx73X//0YD+dl0xFXEU/q1KH8JJMTZ1614qMCN
15+
kgot1Tl1U0HX1OOnSI36owbcTDxVvsWnPCvEctTM8o/CqFpfJ8AyQYUCgYEA2Etv
16+
QfxCRVFmMOK7jxRQkpwGXVJRUVvNypPnrBZxivGNBRSVXY3+O7HF1lgb5+wqiHJW
17+
bfC052eyFHujORTNiMYoft2c8mjMNkm0XBngJEHX5yT7Kfoy+XMZVmxT4m2lEIn9
18+
HSmliw+nwh7IBMfP/2Weagh5he3hsgvqzFGkpJECgYAmrkYn0CAPNSPlceYPEq/L
19+
N8s50SKNNZNiSCK0nO1TJPpf+eU8XEf79MJdTFnpYTAUWseoKvPlVjB2eoZ2LEcF
20+
mTU2qdHLdAcsfUgS2dh7AnFf6U8SLIpCZyC7KqyDA11WDWlW+IHW9WYOU8Ql6WeO
21+
3L8bCoTT7oDG92EHzkoHbQKBgDXMhY7nHOC6/20XaEmNZwEgd+DMcdeHuycxJMXE
22+
C1fg/w+NcB2GDP9yF2BaKA7GykmIDwFnhsesHjpECnRPPVRQ3Y+4taoB8RFrwcXK
23+
1dqO2hHvO93UEsvDGkFJzo+acB0uBVw0mK1/Jl39ZAj0XkMLVpzPINL0OVgc6LkL
24+
caVRAoGBAMF+t6ja3f74vHhJbtWfSf/jSSof4X3wPe4IVwM9d3zXd10VM9MUvhVI
25+
XGSCGo035TWB1VKMtbjM04eYwkCKyQN5VCuqZ8WysRg1/7sz/WwlNKhlYKcv6HU3
26+
bcQwaV453NVcPXuttgrmV+nhAXiL3EU53mHTHgTq7YbKu1TF9aTo
27+
-----END RSA PRIVATE KEY-----

scaleComputeUsingXVA/ssh_key.priv.pub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/Uj97iDSwPpIoge6hvAfOJNmORktkfVdQzhUYiFLG6FC5QUMqUYh8O+iamN7IGlXm/8x9L+36g1a59169lOgJzpSnNvWrlDqB1cYNvG8Pp/DGW5w7Tn53sMXcrmqfvxwUsvBujhmtNxPWIyubhKgaWgwSLn7qV7lvG8uQVD4CCIpPkZ9F58zbp+yizFUwozlC9O7mbrZqbwVRJes0nu7FblCkKnttZ+tu2+N7Cyd2ZGRhr2w+bzI3FiDfTH/3nUMk3JyJMBaYfThronjYYtvCogU+6IjWLJjeia4xU/2+BFT06QHdZ5oO3ioxZsGhYKKs7R/bALenEywTK40cpFBV stack@DevStackOSDomU

0 commit comments

Comments
 (0)