forked from CiscoDevNet/ydk-gen
-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_ydk_sdk_for_github.sh
executable file
·221 lines (184 loc) · 7.65 KB
/
create_ydk_sdk_for_github.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
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
#!/bin/bash
# ----------------------------------------------------------------
# Copyright 2016 Cisco Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------
#
# Script for running ydk CI on travis-ci.org
#
# ------------------------------------------------------------------
function usage {
printf "\n Usage: Use this script to create YDK repositories (ydk-py, ydk-go etc) hosted on github, generated using ydk-gen. Specify the language to create the SDK and the path to where the github SDK is cloned \n\n ./%s -l <[one of python|cpp|go]> -s <PATH-TO-SDK>\n\n" "$( basename "${BASH_SOURCE[0]}" )"
}
function check_gen_api_directories {
GEN_API_CONTENTS=$(ls ${1})
printf "Examining content of directory ${1}\n$GEN_API_CONTENTS\n"
if [[ ${GEN_API_CONTENTS} != *"cisco_ios_xe-bundle"* ]] || [[ ${GEN_API_CONTENTS} != *"cisco_ios_xr-bundle"* ]] \
|| [[ ${GEN_API_CONTENTS} != *"openconfig-bundle"* ]] || [[ ${GEN_API_CONTENTS} != *"ietf-bundle"* ]] \
|| [[ ${GEN_API_CONTENTS} != *"cisco_nx_os-bundle"* ]] || [[ ${GEN_API_CONTENTS} != *"ydk"* ]] \
|| [[ ${GEN_API_CONTENTS} != *"ydk-service-gnmi"* ]]; then
printf "\n Not all packages have been generated.\n\
Please run './generate.py --${LANGUAGE} --bundle profile/bundles/<profile>.json' for all desired bundles.\n\
Run './generate.py --${LANGUAGE} --core' for core\n\
Run './generate.py --${LANGUAGE} --service' for gnmi\n\n"
exit 1
fi
}
function copy_bundle_packages {
echo "Copying ietf from ${GEN_API_PATH}/ietf-bundle/ to ${SDK_PATH}"
cp -r ${GEN_API_PATH}/ietf-bundle/* ${SDK_PATH}/ietf
echo "Copying openconfig from ${GEN_API_PATH}/openconfig-bundle/ to ${SDK_PATH}"
cp -r ${GEN_API_PATH}/openconfig-bundle/* ${SDK_PATH}/openconfig
echo "Copying cisco-ios-xr from ${GEN_API_PATH}/cisco_ios_xr-bundle/ to ${SDK_PATH}"
cp -r ${GEN_API_PATH}/cisco_ios_xr-bundle/* ${SDK_PATH}/cisco-ios-xr
echo "Copying cisco-ios-xe from ${GEN_API_PATH}/cisco_ios_xe-bundle/ to ${SDK_PATH}"
cp -r ${GEN_API_PATH}/cisco_ios_xe-bundle/* ${SDK_PATH}/cisco-ios-xe
echo "Copying cisco-ios-nx from ${GEN_API_PATH}/cisco_ios_nx-bundle/ to ${SDK_PATH}"
cp -r ${GEN_API_PATH}/cisco_nx_os-bundle/* ${SDK_PATH}/cisco-nx-os
}
function copy_readme {
echo " "
echo "Copying README from ${SDK_STUB_PATH} to ${SDK_PATH}"
cp -r ${SDK_STUB_PATH}/README.${1} ${SDK_PATH}
}
function copy_gen_api_to_go_sdk {
GO_GEN_API_DIR=${1}
echo " "
if [[ $GO_GEN_API_DIR == "ydk" ]]; then
target_path="$SDK_PATH"
echo "Copying ${GO_GEN_API_DIR}/ydk from ${GEN_API_PATH}/${GO_GEN_API_DIR}/ to $SDK_PATH"
cp -r ${GEN_API_PATH}/${GO_GEN_API_DIR}/ydk $SDK_PATH
echo "Copying samples from ${GEN_API_PATH}/${GO_GEN_API_DIR}/samples to $SDK_PATH"
cp -r ${GEN_API_PATH}/${GO_GEN_API_DIR}/samples $SDK_PATH
elif [[ $GO_GEN_API_DIR == "ydk-service-gnmi" ]]; then
target_path="$SDK_PATH/gnmi"
echo "Copying ${GO_GEN_API_DIR}/ydk from ${GEN_API_PATH}/${GO_GEN_API_DIR}/ to ${target_path}"
cp -r ${GEN_API_PATH}/${GO_GEN_API_DIR}/ydk ${target_path}
echo "Copying samples from ${GEN_API_PATH}/${GO_GEN_API_DIR}/samples to ${target_path}"
cp -r ${GEN_API_PATH}/${GO_GEN_API_DIR}/samples $target_path
else
target_path="$SDK_PATH/ydk/models"
echo "Copying ${GO_GEN_API_DIR} model bundle from ${GEN_API_PATH}/${GO_GEN_API_DIR}/ to ${target_path}"
cp -r ${GEN_API_PATH}/${GO_GEN_API_DIR}/ydk/models/* ${target_path}
fi
}
function clear_sdk_directories {
echo "Clearing ${SDK_PATH} of existing files"
rm -rf ${SDK_PATH}/ietf/* ${SDK_PATH}/openconfig/* ${SDK_PATH}/cisco-ios-xr/* ${SDK_PATH}/cisco-ios-xe/* ${SDK_PATH}/cisco-nx-os/*
}
########################## EXECUTION STARTS HERE #############################
######################################
# Parse args
######################################
LANGUAGE=0
SDK_PATH=0
# extract options and their arguments into variables.
while getopts ":l:s:h" opt; do
case ${opt} in
l )
LANGUAGE=$OPTARG
;;
s )
SDK_PATH=$OPTARG
;;
h )
usage
exit 1
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
usage
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
usage
exit 1
;;
esac
done
if [[ ${LANGUAGE} == 0 ]] || [[ ${SDK_PATH} == 0 ]] ; then
usage
exit 1
fi
if [[ ${LANGUAGE} != "cpp" ]] && [[ ${LANGUAGE} != "python" ]] && [[ ${LANGUAGE} != "go" ]]; then
echo " Invalid language"
usage
exit 1
fi
GEN_API_PATH=$(pwd)/gen-api/${LANGUAGE}
SDK_STUB_PATH=$(pwd)/sdk/${LANGUAGE}
if [[ ! -d ${SDK_PATH} ]]; then
echo "SDK path '${SDK_PATH}' is invalid! Please provide valid path to the repository cloned of the YDK github SDK \n"
exit 1
fi
check_gen_api_directories ${GEN_API_PATH}
while true; do
printf "\n"
read -p " About to delete docs directories. Continue? (y/n)" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) printf "\nExiting...\n\n";exit;;
* ) echo "Please answer yes or no.";;
esac
done
printf "\nDeleting docs directories..\n\n"
rm -rf ${GEN_API_PATH}/*/docsgen # ${GEN_API_PATH}/*/docs_expanded
echo "${LANGUAGE} being copied to ${SDK_PATH}"
if [[ ${LANGUAGE} == "cpp" ]]; then
clear_sdk_directories
rm -rf ${SDK_PATH}/core/ydk/*
rm -rf ${SDK_PATH}/gnmi/ydk/*
echo " "
echo "Copying core ${GEN_API_PATH}/ydk/* to ${SDK_PATH}/core"
cp -r ${GEN_API_PATH}/ydk/* ${SDK_PATH}/core/ydk
echo "Copying gnmi ${GEN_API_PATH}/ydk-service-gnmi/* to ${SDK_PATH}/gnmi"
cp -r ${GEN_API_PATH}/ydk-service-gnmi/* ${SDK_PATH}/gnmi
copy_bundle_packages
copy_readme md
elif [[ ${LANGUAGE} == "python" ]]; then
clear_sdk_directories
rm -rf ${SDK_PATH}/core/ydk/*
rm -rf ${SDK_PATH}/gnmi/ydk/*
echo "Deleting ${GEN_API_PATH}/ydk/tests"
rm -rf ${GEN_API_PATH}/ydk/tests
echo "Deleting ${GEN_API_PATH}/ydk-service-gnmi/tests"
rm -rf ${GEN_API_PATH}/ydk-service-gnmi/tests
echo " "
echo "Copying core ${GEN_API_PATH}/ydk/* to ${SDK_PATH}/core"
cp -r ${GEN_API_PATH}/ydk/* ${SDK_PATH}/core/
echo "Copying gnmi ${GEN_API_PATH}/ydk-service-gnmi/* to ${SDK_PATH}/gnmi"
cp -r ${GEN_API_PATH}/ydk-service-gnmi/* ${SDK_PATH}/gnmi/
copy_bundle_packages
copy_readme rst
elif [[ ${LANGUAGE} == "go" ]]; then
echo " "
echo "Cleaning ${SDK_PATH} of existing files"
rm -rf ${SDK_PATH}/ydk/*
rm -rf ${SDK_PATH}/gnmi/*
rm -rf ${SDK_PATH}/samples/*
echo "Deleting ${GEN_API_PATH}/ydk/tests"
rm -rf ${GEN_API_PATH}/ydk/tests
echo "Deleting ${GEN_API_PATH}/ydk-service-gnmi/tests"
rm -rf ${GEN_API_PATH}/ydk-service-gnmi/tests
copy_gen_api_to_go_sdk ydk
copy_gen_api_to_go_sdk ydk-service-gnmi
copy_gen_api_to_go_sdk ietf-bundle
copy_gen_api_to_go_sdk openconfig-bundle
copy_gen_api_to_go_sdk cisco_ios_xr-bundle
copy_gen_api_to_go_sdk cisco_ios_xe-bundle
copy_gen_api_to_go_sdk cisco_nx_os-bundle
copy_readme md
fi
printf "\n\n Please check ${SDK_PATH} and perform the git commit and push\n\n"