-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice creation v 2.sh
230 lines (166 loc) · 4.63 KB
/
slice creation v 2.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
222
223
224
225
226
227
228
229
230
#!/bin/bash
#------------------------------------------
# |
# Slice creation v 2.0 |
# |
#------------------------------------------
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
IP=192.168.42.11
Port=35357
PASS=labstack
Flavor=$3
Image=$4
#Authentication
echo ""
echo ""
echo ""
echo -n "Input your Dashboard ID: "
read User_ID
echo ""
echo -n "Input your Password: "
stty -echo
read Password
echo ""
stty echo
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=$User_ID
export OS_USERNAME=$User_ID
export OS_PASSWORD=$Password
export OS_AUTH_URL=http://$IP/identity/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
echo "######################## Successfully login ################"
echo ""
echo ""
echo "Generating Token for" $User_ID
echo ""
echo ""
Output=`openstack token issue`
echo "check is $Output"
if [ "$Output" == "" ]; then
echo "Authentication Failed"
exit 1
fi
echo ""
echo ""
echo "######################## Token generated successfully ################"
echo ""
echo ""
##Need to check SLicing ID Part!!!
echo -n "Input Sllicing ID (Integers only): "
read Slicing
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=$PASS
export OS_AUTH_URL=http://$IP/identity/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
##Checking Network
net_list=`openstack network list | grep vxlan_$Slicing`
if [ "$net_list" == "" ]; then
echo ""
echo ""
echo "Creating slice...."
echo
echo ""
echo ""
# Create Network
#openstack network create --project $User_ID --provider-network-type vlan --provider-physical-network provider --provider-segment $Slicing vlan_$Slicing
openstack network create vxlan_$Slicing --provider-network-type vxlan --provider-segment $Slicing
echo ""
echo "#################### Slice has been created #####################"
echo ""
echo ""
# Obtain Network ID
Net_ID=`openstack network list | grep vxlan_$Slicing | awk '{print $2}'`
# Create Subnet
subnet=`cat network_pool | grep $Slicing | awk '{print $3}'`
allocation=`cat network_pool | grep $Slicing | awk '{print $4}'`
echo "#################### IP address assignment #####################"
echo ""
echo ""
echo -n "Input Subnet range(eg. 10.0.0.0/24): "
read subnet_ip
echo ""
echo ""
echo -n "Input Gateway address (eg. 10.0.0.1): "
read gt_add
echo ""
echo ""
openstack subnet create --project $User_ID --subnet-range $subnet_ip --ip-version 4 --network $Net_ID --dhcp --gateway $gt_add sub_$Slicing
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=$User_ID
export OS_USERNAME=$User_ID
export OS_PASSWORD=$Password
export OS_AUTH_URL=http://$IP/identity/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
# Create Router
openstack router create router_$Slicing
# Setting External Gateway
openstack router set --external-gateway public router_$Slicing
# Add Port
openstack router add subnet router_$Slicing sub_$Slicing
else
echo "#################### Slice has been created #####################"
echo ""
echo ""
fi
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=$User_ID
export OS_USERNAME=$User_ID
export OS_PASSWORD=$Password
export OS_AUTH_URL=http://$IP/identity/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
# Flavor & Image
echo ""
echo ""
echo "#################### Starting VM Creation #####################"
echo ""
echo ""
openstack flavor list
echo ""
echo ""
echo -n "Input Flavor for VM creation from the list: "
read Flavor
echo ""
echo ""
openstack image list
echo ""
echo ""
echo -n "Input Image for VM creation from the list: "
read Image
echo ""
echo ""
# obtain Network ID
Net_ID=`openstack network list | grep vxlan_$Slicing | awk '{print $2}'`
# Create Instance
openstack server create --flavor $Flavor --image $Image --nic net-id=$Net_ID Cloud_Instance_$Slicing
echo ""
echo ""
echo "#################### VM have been created successfully #####################"
echo ""
echo ""
echo ""
echo ""
echo "Slice have been created successfully with slice ID:" $Slicing
echo ""
echo ""
echo ""
echo ""
#Instance_ID=`openstack server list | grep Cloud_Instance_$2 | awk '{print $2}'`
# Add DB
#cat << EOF | mysql -h 172.20.90.167 -uroot -p$PASSWORD
#use Slicing_Management;
#INSERT INTO Slicing_Instance('Slicing_ID', 'Instance_ID') VALUES ($2, $Instance_ID);
#quit
#EOF