-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnaproute_scripts
507 lines (467 loc) · 14.1 KB
/
snaproute_scripts
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#!/bin/bash
function switch_branch {
echo $SR_CODE_BASE
cd $SR_CODE_BASE
if [[ $1 == "" ]]; then
echo "please specify the branch that you want to checkout"
return
fi
for dir in *; do
if [ $dir == "reltools" ]; then
echo $dir
cd $dir
git checkout $1
elif [ $dir == "snaproute" ]; then
cd $dir/src
for srcDir in */; do
is_asicd_dir=false
if [ $srcDir != "out/" ] && [ $srcDir != "vendors/" ] && [ $srcDir != "flexui/" ] && [ $srcDir != "opticd/" ]; then
echo $SR_CODE_BASE/$dir/src/$srcDir
cd $SR_CODE_BASE/$dir/src/$srcDir
if [ $srcDir == "flexSdk/" ]; then
git checkout .
elif [ $srcDir == "asicd/" ]; then
#revert_lfs_files
is_asicd_dir=true
fi
git checkout $1
if $is_asicd_dir; then
#git lfs fetch
#git lfs checkout
is_asicd_dir=false
fi
echo
fi
done
fi
cd $SR_CODE_BASE
done
}
function chkout {
echo $SR_CODE_BASE
cd $SR_CODE_BASE
if [[ $1 == "" ]]; then
echo "please specify the branch that you want to checkout"
return
fi
for dir in *; do
if [ $dir == "reltools" ]; then
echo $dir
cd $dir
git fetch upstream
git checkout -b $1 upstream/$1
elif [ $dir == "snaproute" ]; then
cd $dir/src
for srcDir in */; do
is_asicd_dir=false
if [ $srcDir != "out/" ] && [ $srcDir != "vendors/" ] && [ $srcDir != "flexui/" ] && [ $srcDir != "opticd/" ]; then
echo $SR_CODE_BASE/$dir/src/$srcDir
cd $SR_CODE_BASE/$dir/src/$srcDir
if [ $srcDir == "flexSdk/" ]; then
git checkout .
elif [ $srcDir == "asicd/" ]; then
#revert_lfs_files
is_asicd_dir=true
fi
git fetch upstream
git checkout -b $1 upstream/$1
if $is_asicd_dir; then
#git lfs fetch
#git lfs checkout
is_asicd_dir=false
fi
echo
fi
done
fi
cd $SR_CODE_BASE
done
}
function repos_sync {
echo $SR_CODE_BASE
cd $SR_CODE_BASE
for dir in *; do
if [ $dir == "reltools" ]; then
echo $dir
cd $dir
mr_sync
elif [ $dir == "snaproute" ]; then
cd $dir/src
for srcDir in */; do
is_asicd_dir=false
if [ $srcDir != "out/" ]; then
echo $SR_CODE_BASE/$dir/src/$srcDir
cd $SR_CODE_BASE/$dir/src/$srcDir
if [ $srcDir == "flexSdk/" ]; then
git checkout .
elif [ $srcDir == "asicd/" ]; then
#revert_lfs_files
is_asicd_dir=true
fi
mr_sync
if $is_asicd_dir; then
#git lfs fetch
#git lfs checkout
is_asicd_dir=false
fi
echo
fi
done
fi
cd $SR_CODE_BASE
done
}
function sync_on_mino {
git pull origin
}
function mino_branch_status {
git status
}
baseComp=(
"chartpackager"
"platforminitx8664"
"pmd"
)
componentCharts=(
"asicd"
"intfd"
"adjd"
"ufibd"
)
#snapl docker helper functions
function set_docker_login_info() {
export MY_DOCKER_USER=jgheewala
export MY_REPOSITORY=jgheewala
export MY_DOCKER_PASS=Snaproute_123
}
#if you want to set comp version..use this function and it will automatically set it.
function set_docker_comp_version() {
if [ "$1" == "" ]; then
echo "specify component docker version, for e.g: l3_data_path_demo, v1_dev_11"
return
fi
include_chart=""
space_char=" "
termination="\""
pmd_bootstrap=pmd-bootstrap
for comp in "${baseComp[@]}"; do
echo "setting version for comp" $comp
export VERSION_$comp=$1
done
include_chart=$termination
for comp in "${componentCharts[@]}"; do
echo "setting version for comp" $comp
export VERSION_$comp=$1
include_chart=$include_chart$space_char$comp
done
include_chart=$include_chart$space_char$pmd_bootstrap$termination
echo "export chart version" $include_chart
export INCLUDE_CHARTS=$include_chart
}
minoOrgRepos=(
"reltools"
"asicd"
"utils"
"l2"
"l3"
"tools"
"infra"
"commondefs"
"pi"
)
function sync_all_repos {
echo $SR_CODE_BASE
SRC=$SR_CODE_BASE/snaproute/src
for repo in "${minoOrgRepos[@]}"; do
echo "repo is:" $repo
if [ $repo == "reltools" ]; then
cd $SR_CODE_BASE/$repo
echo "current directory is" $SR_CODE_BASE/$repo
sync_on_mino
elif [ $repo == "asicd" ] || [ $repo == "utils" ] || [ $repo == "commondefs" ]; then
cd $SRC/$repo
echo "current directory is" $SRC/$repo
sync_on_mino
else
cd $SRC/$repo
for dir in *; do
export retVal=0
#echo "dir is" $dir
cd $dir; export retVal=$?
echo ""
echo "current directory is" $SRC/$repo/$dir
sync_on_mino
if [ $retVal == 0 ]; then
cd - > /dev/null
fi
done
fi
cd - > /dev/null
echo
done
cd $SRC
}
function merge_mino_branch {
echo $SR_CODE_BASE
SRC=$SR_CODE_BASE/snaproute/src
if [ "$1" == "" ]; then
echo "specify branch you want to sync from"
else
for repo in "${minoOrgRepos[@]}"; do
echo "repo is:" $repo
if [ $repo == "reltools" ]; then
cd $SR_CODE_BASE/$repo
echo "current directory is" $SR_CODE_BASE/$repo
git merge origin/$1
elif [ $repo == "asicd" ] || [ $repo == "utils" ] || [ $repo == "commondefs" ]; then
cd $SRC/$repo
echo "current directory is" $SRC/$repo
git merge origin/$1
else
cd $SRC/$repo
for dir in *; do
export retVal=0
#echo "dir is" $dir
cd $dir; export retVal=$?
echo ""
echo "current directory is" $SRC/$repo/$dir
git merge origin/$1
if [ $retVal == 0 ]; then
cd - > /dev/null
fi
done
fi
cd - > /dev/null
echo
done
fi
cd $SRC
}
function branch_name {
echo $SR_CODE_BASE
SRC=$SR_CODE_BASE/snaproute/src
for repo in "${minoOrgRepos[@]}"; do
echo "repo is:" $repo
if [ $repo == "reltools" ]; then
cd $SR_CODE_BASE/$repo
echo "current directory is" $SR_CODE_BASE/$repo
git branch
elif [ $repo == "asicd" ] || [ $repo == "utils" ] || [ $repo == "commondefs" ]; then
cd $SRC/$repo
echo "current directory is" $SRC/$repo
git branch
else
cd $SRC/$repo
for dir in *; do
export retVal=0
#echo "dir is" $dir
cd $dir; export retVal=$?
echo ""
echo "current directory is" $SRC/$repo/$dir
git branch
if [ $retVal == 0 ]; then
cd - > /dev/null
fi
done
fi
cd - > /dev/null
echo
done
cd $SRC
}
function branch_status {
echo $SR_CODE_BASE
SRC=$SR_CODE_BASE/snaproute/src
for repo in "${minoOrgRepos[@]}"; do
echo "repo is:" $repo
if [ $repo == "reltools" ]; then
cd $SR_CODE_BASE/$repo
echo ""
echo "current directory is" $SR_CODE_BASE/$repo
mino_branch_status
elif [ $repo == "asicd" ] || [ $repo == "utils" ] || [ $repo == "commondefs" ]; then
cd $SRC/$repo
echo ""
echo "current directory is" $SRC/$repo
mino_branch_status
else
cd $SRC/$repo
for dir in *; do
export retVal=0
#echo "dir is" $dir
cd $dir; export retVal=$?
echo ""
echo "current directory is" $SRC/$repo/$dir
mino_branch_status
if [ $retVal == 0 ]; then
cd - > /dev/null
fi
done
fi
cd - > /dev/null
echo
done
cd $SRC
}
function prepare_ws() {
cd $SR_CODE_BASE
echo "Syncing worspace to HEAD"
mr syncall
find . -name "cscope*" -exec rm -rf {} \;
cd $SR_CODE_BASE/snaproute/src
echo "Building cscope"
~/scripts/cscope_build
echo "Building CTAGS"
~/scripts/tags_build
echo "Doing Clean Build of WorkSpace"
cd $SR_CODE_BASE/snaproute/src
make clean_all; make
echo ""
echo "Done with setting up workspace"
echo ""
}
# checks if branch has something pending
function parse_git_dirty() {
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*"
}
# gets the current git branch
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
# get last commit hash prepended with @ (i.e. @8a323d0)
function parse_git_hash() {
git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/@\1/"
}
# DEMO
GIT_BRANCH=$(parse_git_branch)$(parse_git_hash)
function build_all {
cd $SR_CODE_BASE/snaproute/src
if [ "$1" == "" ]; then
make clean_all; make
else
make clean_all; make BUILD_TARGET=$1
fi
echo "Done Clean Build of WorkSpace"
cd $SR_CODE_BASE
echo "Building cscope"
~/scripts/cscope_build
echo "Building TAGS"
ftags
}
function mr_sync {
str="Doing MR SYNC on branch: $(parse_git_branch)"
echo $str
git pull origin $(parse_git_branch)
git fetch upstream
git merge upstream/$(parse_git_branch)
git push origin $(parse_git_branch)
}
function run_ovsdb_docker {
echo "pull socketplane ops"
docker pull socketplane/openvswitch
echo "start docker container"
cid=$(docker run -itd --cap-add NET_ADMIN --name "ovsdb_test" socketplane/openvswitch)
echo "cid: $cid"
}
function remove_ovsdb_docker {
echo "KILL and remove OVSDB_TEST"
docker kill "ovsdb_test"
docker rm "ovsdb_test"
}
function mrg_branch {
if [ "$1" == "" ]; then
echo "specify branch you want to sync from"
else
cd $SR_CODE_BASE
for dir in *; do
if [ $dir == "snaproute" ]; then
cd $dir/src
for srcDir in */; do
if [ $srcDir != "out/" ] && [ $srcDir != "flexSdk/" ] && [ $srcDir != "vendors/" ] && [ $srcDir != "flexui/" ] && [ $srcDir != "opticd/" ]; then
cd $SR_CODE_BASE/$dir/src/$srcDir
repo=${srcDir///}
echo "Syncing $(parse_git_branch) to $1 for $repo"
git fetch upstream
git merge upstream/$1
git push origin $(parse_git_branch)
# merge_branch
# git merge --no-ff upstream/$1
# git commit -s --amend
# git push origin $(parse_git_branch)
fi
done
fi
cd $SR_CODE_BASE
done
fi
}
function copy_fs() {
#scp $1 [email protected].$2:$1
scp $1 [email protected].$2:$1
}
function fs() {
#ssh [email protected].$1
ssh [email protected].$1
}
function switch() {
ssh [email protected].$1
#ssh [email protected].$1
}
function daemon_cp() {
scp $SR_CODE_BASE/snaproute/src/out/bin/$1 [email protected].$2:
#scp $SR_CODE_BASE/snaproute/src/out/bin/$1 [email protected].$2:/opt/flexswitch/bin
}
function svr() {
ssh [email protected].$1
}
function botsvr() {
}
function build_tags() {
cd $SR_CODE_BASE
~/scripts/tags_build
cd -
}
function bcm_shell() {
#rlwrap nc 10.1.10.$1 40000
rlwrap nc 192.168.100.$1 40000
}
function fs_cli() {
#cd $SR_CODE_BASE/snaproute/src/apps/cli2
#source env.sh
#./snap_cli.py -s 10.1.10.$1
#./snap_cli.py -s 192.168.100.$1
ssh [email protected].$1 -p2022
}
function gen_pkg_build() {
cd $SR_CODE_BASE/reltools
python makePkg.py
build_all $1
}
function merge_branch() {
if [ "$1" == "" ]; then
echo "specify branch you want to sync from"
else
git fetch upstream
git merge upstream/$1
git push origin $(parse_git_branch)
fi
}
alias rt='cd $SR_CODE_BASE/reltools'
alias sr='cd $SR_CODE_BASE/snaproute/src'
alias asicd='cd $SR_CODE_BASE/snaproute/src/asicd'
alias models='cd $SR_CODE_BASE/snaproute/src/models'
alias vendors='cd $SR_CODE_BASE/snaproute/src/vendors'
alias l3='cd $SR_CODE_BASE/snaproute/src/l3'
alias l2='cd $SR_CODE_BASE/snaproute/src/l2'
alias sr_test='cd $SR_CODE_BASE/snaproute/src/test'
alias set_git_env='source ~/scripts/env_setup'
alias cli_dir='cd $SR_CODE_BASE/snaproute/src/apps/cli2'
alias sr_utils='cd $SR_CODE_BASE/snaproute/src/utils'
alias sr_fp='cd $SR_CODE_BASE/snaproute/src/flexpath'
alias sr_pi='cd $SR_CODE_BASE/snaproute/src/pi/'
alias intfd='cd $SR_CODE_BASE/snaproute/src/pi/intf'
alias ufibd='cd $SR_CODE_BASE/snaproute/src/pi/ufib'
alias adjd='cd $SR_CODE_BASE/snaproute/src/pi/adj'
alias build_gotags='source ~/scripts/gotags_build'
alias c_csope='source ~/scripts/cur_dir_scope'