-
Notifications
You must be signed in to change notification settings - Fork 28
/
setup.sh
executable file
·162 lines (124 loc) · 3.47 KB
/
setup.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
#
# enable only when debug the script
#set -e
prefix_path=/usr/share/axsh/wakame-vdc
builder_path=${prefix_path}/tests/builder
tmp_path=${prefix_path}/tmp
. $builder_path/functions.sh
[[ -f "/etc/lsb-release" ]] && . /etc/lsb-release
RETRYCOUNT=0
# Waiting ip release.
while true
do
echo "Retry ${RETRYCOUNT}"
ipaddr=`/sbin/ip route get 8.8.8.8 | head -1 | awk '{print $7}'`
if [ ${RETRYCOUNT} -ge 5 ]; then
echo "Failed ip release."
exit 1
elif [ "${ipaddr}" = "" ]; then
echo 'Waiting ip release.'
RETRYCOUNT=`expr ${RETRYCOUNT} + 1`
sleep 1
else
break
fi
done
account_id=a-shpoolxx
#account_id=a-00000000
auth_port=3000
auth_bind=127.0.0.1
webui_port=9000
webui_bind=0.0.0.0
api_port=9001
api_bind=127.0.0.1
metadata_port=9002
metadata_bind=${ipaddr}
proxy_port=8080
proxy_bind=127.0.0.1
ports="${auth_port} ${webui_port} ${api_port} ${metadata_port}"
# networks table
ipv4_gw="${ipv4_gw:-$(/sbin/ip route get 8.8.8.8 | head -1 | awk '{print $3}')}"
prefix_len="${prefix_len:-$(/sbin/ip route show | awk '$9 == ip { sub(/.*\//, "", $1); print $1; }' ip=$ipaddr)}"
dns_server=${dns_server:-${ipaddr}}
dhcp_server=${dhcp_server:-${ipaddr}}
metadata_server=${metadata_server:-${ipaddr}}
sta_server=${sta_server:-${ipaddr}}
# local store demo machine image
local_store_path="$tmp_path/images"
# virtual machine
vmdir_path=${tmp_path}/instances
vmimage_uuid=lucid0
vmimage_file=${vmimage_uuid}.qcow2
vmimage_s3="http://dlc.wakame.axsh.jp.s3.amazonaws.com/demo/vmimage/${vmimage_file}.gz"
# mysql
dcmgr_dbname=wakame_dcmgr
dcmgr_dbuser=root
webui_dbname=wakame_dcmgr_gui
webui_dbpass=passwd
hypervisor=kvm
# how many agents?
hva_num=1
sta_num=1
# used resource file
demo_resource=${demo_resource:-'demo_data_setup.sh'}
# work around if this runs under the bundler container.
[[ -n "$BUNDLE_BIN_PATH" ]] && {
export RUBYOPT="$RUBYOPT -rubygems"
alias bundle="$BUNDLE_BIN_PATH"
}
# add bin path to $GEM_HOME/bin.
which gem >/dev/null 2>&1 && {
export PATH="$(ruby -rubygems -e 'puts Gem.bindir'):$PATH"
} || :
alias rake="bundle exec rake"
shopt -s expand_aliases
function init_db() {
dbnames="wakame_dcmgr wakame_dcmgr_gui"
for dbname in ${dbnames}; do
mysqladmin -uroot create ${dbname}
done
cd ${prefix_path}/dcmgr
rake db:init
cd ${prefix_path}/frontend/dcmgr_gui
rake db:init db:sample_data oauth:create_table
echo ... rake oauth:create_consumer[${account_id}]
local oauth_keys=$(rake oauth:create_consumer[${account_id}] | egrep -v '^\(in')
eval ${oauth_keys}
cat <<EOS > ./oauth_client.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
begin
require 'rubygems'
require 'bundler'
Bundler.setup(:default)
rescue Exception
end
require 'oauth'
consumer_key = "${consumer_key}"
secret_key = "${secret_key}"
site = "http://${proxy_bind:-127.0.0.1}:${proxy_port}"
consumer = OAuth::Consumer.new(consumer_key,secret_key, {:site=>site, :version=>'1.0'})
req = "/api/security_groups"
res = consumer.request(:get, req, nil, {}, {'X-VDC-ACCOUNT-UUID' => '${account_id}'})
p res.body
EOS
chmod +x ./oauth_client.rb
# generate demo data
work_dir=$prefix_path
builder_script=$demo_resource
# run script in subshell to inherit variables.
(
[[ -f $work_dir/common.sh ]] && {
. $work_dir/common.sh
}
. $work_dir/$builder_script
) || abort "Failed to run $builder_script"
}
init_db
sleep 1
#Setup wakame's network
echo "Network setup"
${prefix_path}/network_setup.sh
echo "Setup completed"
exit 0