-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-new-tenant-network.sh
executable file
·127 lines (99 loc) · 3.7 KB
/
create-new-tenant-network.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
#!/bin/sh
# Copyright (C) 2015 Red Hat Inc.
# Kashyap Chamarthy <[email protected]>
#
# # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Purpose: To create a new Neutron tenant network
#
# Assumption: An external network already exists, by name "ext"
# Usage
if [ $# -ne 6 ]; then
echo "Usage: $0 \\
TENANTNAME USERNAME \\
SUBNETSPACE ROUTERNAME \\
PRIVNETNAME PRIVSUBNETNAME \\
Examples:
1. To create a priv net with 14.0.0.0/24 subnet:
$ ./`basename $0` \\
demoten1 tuser1 \\
14.0.0.0 trouter1 \\
priv-net1 priv-subnet1
2. To create a new user tenant with 15.0.0.0.24 subnet:
$ ./`basename $0` \\
demoten2 tuser2 \\
15.0.0.0 trouter2 \\
priv-net2 priv-subnet2
"
exit 1
fi
# Source the admin credentials
source $PWD/keystonerc_admin
# Positional parameters
tenantname=$1
username=$2
subnetspace=$3
routername=$4
privnetname=$5
privsubnetname=$6
# Create a tenant, user and associate a role/tenant to it
keystone tenant-create \
--name $tenantname
keystone user-create \
--name $username \
--pass fedora \
--tenant $tenantname
keystone user-role-add \
--user $username \
--role _member_ \
--tenant $tenantname
# Create an RC file for this user and source the credentials
cat >> keystonerc_$username<<EOF
export OS_USERNAME=$username
export OS_TENANT_NAME=$tenantname
export OS_PASSWORD=fedora
export OS_AUTH_URL=http://localhost:5000/v2.0/
export PS1='[\u@\h \W(keystone_$username)]\$ '
EOF
# Source this user credentials
source $PWD/keystonerc_$username
# Create new private network, subnet for this user tenant
neutron net-create $privnetname
neutron subnet-create $privnetname \
$subnetspace/24 \
--name $privsubnetname
# Create a router
neutron router-create $routername
# Associate the router to the external network by setting its gateway
# NOTE: This assumes the external network name is 'ext'
EXT_NET=$(neutron net-list | grep ext | awk '{print $2;}')
PRIV_NET=$(neutron subnet-list | grep $privsubnetname | awk '{print $2;}')
ROUTER_ID=$(neutron router-list | grep $routername | awk '{print $2;}')
neutron router-gateway-set \
$ROUTER_ID $EXT_NET
neutron router-interface-add \
$ROUTER_ID $PRIV_NET
# Add Neutron security groups for this test tenant
neutron security-group-rule-create \
--protocol icmp \
--direction ingress \
--remote-ip-prefix 0.0.0.0/0 \
default
neutron security-group-rule-create \
--protocol tcp \
--port-range-min 22 \
--port-range-max 22 \
--direction ingress \
--remote-ip-prefix 0.0.0.0/0 \
default