Merge ~rodrigo-barbieri2010/stsstack-bundles:demo_networks into stsstack-bundles:master
- Git
- lp:~rodrigo-barbieri2010/stsstack-bundles
- demo_networks
- Merge into master
Proposed by
Rodrigo Barbieri
Status: | Rejected |
---|---|
Rejected by: | Edward Hope-Morley |
Proposed branch: | ~rodrigo-barbieri2010/stsstack-bundles:demo_networks |
Merge into: | stsstack-bundles:master |
Diff against target: |
284 lines (+103/-87) 5 files modified
openstack/bin/neutron-ext-net (+0/-23) openstack/bin/neutron-ext-net-ksv3 (+0/-23) openstack/bin/neutron-tenant-net (+43/-20) openstack/bin/neutron-tenant-net-ksv3 (+53/-17) openstack/profiles/default (+7/-4) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Edward Hope-Morley | Needs Information | ||
Review via email: mp+386921@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Edward Hope-Morley (hopem) wrote : | # |
Revision history for this message
Edward Hope-Morley (hopem) : | # |
review:
Needs Information
Revision history for this message
Edward Hope-Morley (hopem) wrote : | # |
The repository has moved to https:/
Unmerged commits
- a7d3b45... by Rodrigo Barbieri
-
Add demo tenant networks to configure
Also fixed bugs within the networks scripts
and refactored where necessary.A few changes to note:
- moved user creation to before networks, so
demo network could be created immediately after
admin networks
- moved provider-router creation and setting gateway
to same script that creates private networks,
because routers are tenant-related.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/openstack/bin/neutron-ext-net b/openstack/bin/neutron-ext-net |
2 | index 05e2133..0ba0ed8 100755 |
3 | --- a/openstack/bin/neutron-ext-net |
4 | +++ b/openstack/bin/neutron-ext-net |
5 | @@ -151,26 +151,3 @@ if __name__ == '__main__': |
6 | logging.warning('Subnet %s already exists.', subnet_name) |
7 | subnet = subnets['subnets'][0] |
8 | |
9 | - routers = quantum.list_routers(name='provider-router') |
10 | - if len(routers['routers']) == 0: |
11 | - logging.info('Creating provider router for external network access') |
12 | - router = quantum.create_router( |
13 | - {'router': {'name': 'provider-router', 'tenant_id': tenant_id}} |
14 | - )['router'] |
15 | - logging.info('New router created: %s', (router['id'])) |
16 | - else: |
17 | - logging.warning('Router provider-router already exists.') |
18 | - router = routers['routers'][0] |
19 | - |
20 | - ports = quantum.list_ports(device_owner='network:router_gateway', |
21 | - network_id=network['id']) |
22 | - if len(ports['ports']) == 0: |
23 | - logging.info('Plugging router into ext_net') |
24 | - router = \ |
25 | - quantum.add_gateway_router( |
26 | - router=router['id'], |
27 | - body={'network_id': network['id']} |
28 | - ) |
29 | - logging.info('Router connected to %s', net_name) |
30 | - else: |
31 | - logging.warning('Router already connect to %s', net_name) |
32 | diff --git a/openstack/bin/neutron-ext-net-ksv3 b/openstack/bin/neutron-ext-net-ksv3 |
33 | index e647360..52627db 100755 |
34 | --- a/openstack/bin/neutron-ext-net-ksv3 |
35 | +++ b/openstack/bin/neutron-ext-net-ksv3 |
36 | @@ -136,26 +136,3 @@ if __name__ == '__main__': |
37 | logging.warning('Subnet %s already exists.', subnet_name) |
38 | subnet = subnets['subnets'][0] |
39 | |
40 | - routers = quantum.list_routers(name='provider-router') |
41 | - if len(routers['routers']) == 0: |
42 | - logging.info('Creating provider router for external network access') |
43 | - router = quantum.create_router( |
44 | - {'router': {'name': 'provider-router', 'tenant_id': project_id}} |
45 | - )['router'] |
46 | - logging.info('New router created: %s', (router['id'])) |
47 | - else: |
48 | - logging.warning('Router provider-router already exists.') |
49 | - router = routers['routers'][0] |
50 | - |
51 | - ports = quantum.list_ports(device_owner='network:router_gateway', |
52 | - network_id=network['id']) |
53 | - if len(ports['ports']) == 0: |
54 | - logging.info('Plugging router into ext_net') |
55 | - router = \ |
56 | - quantum.add_gateway_router( |
57 | - router=router['id'], |
58 | - body={'network_id': network['id']} |
59 | - ) |
60 | - logging.info('Router connected to %s', net_name) |
61 | - else: |
62 | - logging.warning('Router already connect to %s', net_name) |
63 | diff --git a/openstack/bin/neutron-tenant-net b/openstack/bin/neutron-tenant-net |
64 | index a2e5c13..9daa0ba 100755 |
65 | --- a/openstack/bin/neutron-tenant-net |
66 | +++ b/openstack/bin/neutron-tenant-net |
67 | @@ -10,6 +10,7 @@ except ImportError: |
68 | from keystoneclient.v2_0 import client as ks_client |
69 | import optparse |
70 | import os |
71 | +import random |
72 | import sys |
73 | import logging |
74 | |
75 | @@ -100,10 +101,10 @@ if __name__ == '__main__': |
76 | if opts.network_type == 'vxlan': |
77 | network_msg['network']['provider:segmentation_id'] = 1233 |
78 | elif opts.network_type == 'vlan': |
79 | - network_msg['network']['provider:segmentation_id'] = 5 |
80 | + network_msg['network']['provider:segmentation_id'] = random.randint(5, 1000) |
81 | network_msg['network']['provider:physical_network'] = 'physnet1' |
82 | else: |
83 | - network_msg['network']['provider:segmentation_id'] = 5 |
84 | + network_msg['network']['provider:segmentation_id'] = random.randint(5, 1000) |
85 | |
86 | network = quantum.create_network(network_msg)['network'] |
87 | else: |
88 | @@ -146,22 +147,44 @@ if __name__ == '__main__': |
89 | if opts.router: |
90 | routers = quantum.list_routers(name=opts.router) |
91 | if len(routers['routers']) == 0: |
92 | - logging.error('Unable to locate provider router %s', opts.router) |
93 | - sys.exit(1) |
94 | + logging.info('Creating tenant router for external network access') |
95 | + router = quantum.create_router( |
96 | + {'router': {'name': opts.router, 'tenant_id': tenant_id}} |
97 | + )['router'] |
98 | + logging.info('New router created: %s', (router['id'])) |
99 | else: |
100 | - # Check to see if subnet already plugged into router |
101 | - ports = quantum.list_ports(device_owner='network:router_interface', |
102 | - network_id=network['id']) |
103 | - |
104 | - ha_ports = quantum.list_ports( |
105 | - device_owner='network:ha_router_replicated_interface', |
106 | - network_id=network['id']) |
107 | - |
108 | - if len(ports['ports'] + ha_ports['ports']) == 0: |
109 | - logging.info('Adding interface from %s to %s', |
110 | - opts.router, subnet_name) |
111 | - router = routers['routers'][0] |
112 | - quantum.add_interface_router(router['id'], |
113 | - {'subnet_id': subnet['id']}) |
114 | - else: |
115 | - logging.warning('Router already connected to subnet') |
116 | + logging.warning('Router {} already exists.'.format(opts.router)) |
117 | + router = routers['routers'][0] |
118 | + # Check to see if subnet already plugged into router |
119 | + ports = quantum.list_ports(device_owner='network:router_interface', |
120 | + network_id=network['id']) |
121 | + |
122 | + dist_ports = quantum.list_ports( |
123 | + device_owner='network:router_interface_distributed', |
124 | + network_id=network['id']) |
125 | + |
126 | + ha_ports = quantum.list_ports( |
127 | + device_owner='network:ha_router_replicated_interface', |
128 | + network_id=network['id']) |
129 | + |
130 | + if len(ports['ports'] + ha_ports['ports'] + dist_ports['ports']) == 0: |
131 | + logging.info('Adding interface from %s to %s', |
132 | + opts.router, subnet_name) |
133 | + quantum.add_interface_router(router['id'], |
134 | + {'subnet_id': subnet['id']}) |
135 | + else: |
136 | + logging.warning('Router already connected to subnet') |
137 | + |
138 | + if not router['external_gateway_info']: |
139 | + |
140 | + ext_network = quantum.list_networks(name='ext_net')['networks'][0] |
141 | + |
142 | + logging.info('Plugging router into ext_net') |
143 | + router = quantum.add_gateway_router( |
144 | + router=router['id'], |
145 | + body={'network_id': ext_network['id']} |
146 | + ) |
147 | + logging.info('Router connected to %s', 'ext_net') |
148 | + else: |
149 | + logging.warning('Router already connect to %s', 'ext_net') |
150 | + |
151 | diff --git a/openstack/bin/neutron-tenant-net-ksv3 b/openstack/bin/neutron-tenant-net-ksv3 |
152 | index 42b9f0b..6dd2091 100755 |
153 | --- a/openstack/bin/neutron-tenant-net-ksv3 |
154 | +++ b/openstack/bin/neutron-tenant-net-ksv3 |
155 | @@ -5,6 +5,7 @@ from keystoneclient import session, v3 |
156 | from neutronclient.v2_0 import client |
157 | import optparse |
158 | import os |
159 | +import random |
160 | import sys |
161 | import logging |
162 | |
163 | @@ -72,9 +73,17 @@ if __name__ == '__main__': |
164 | quantum = client.Client(session=sess) |
165 | |
166 | # Resolve tenant id |
167 | - project_id = auth.get_project_id(sess) |
168 | + project_id = None |
169 | + if opts.project != 'admin': |
170 | + for project in keystone.projects.list(): |
171 | + if project.name == opts.project: |
172 | + project_id = project.id |
173 | + break # Tenant ID found - stop looking |
174 | + else: |
175 | + project_id = auth.get_project_id(sess) |
176 | + |
177 | if not project_id: |
178 | - logging.error("Unable to locate project id for %s.", opts.tenant) |
179 | + logging.error("Unable to locate project id for %s.", opts.project) |
180 | sys.exit(1) |
181 | |
182 | # Create network |
183 | @@ -93,10 +102,10 @@ if __name__ == '__main__': |
184 | if opts.network_type == 'vxlan': |
185 | network_msg['network']['provider:segmentation_id'] = 1233 |
186 | elif opts.network_type == 'vlan': |
187 | - network_msg['network']['provider:segmentation_id'] = 5 |
188 | + network_msg['network']['provider:segmentation_id'] = random.randint(5, 1000) |
189 | network_msg['network']['provider:physical_network'] = 'physnet1' |
190 | else: |
191 | - network_msg['network']['provider:segmentation_id'] = 5 |
192 | + network_msg['network']['provider:segmentation_id'] = random.randint(5, 1000) |
193 | |
194 | network = quantum.create_network(network_msg)['network'] |
195 | else: |
196 | @@ -139,17 +148,44 @@ if __name__ == '__main__': |
197 | if opts.router: |
198 | routers = quantum.list_routers(name=opts.router) |
199 | if len(routers['routers']) == 0: |
200 | - logging.error('Unable to locate provider router %s', opts.router) |
201 | - sys.exit(1) |
202 | + logging.info('Creating tenant router for external network access') |
203 | + router = quantum.create_router( |
204 | + {'router': {'name': opts.router, 'tenant_id': project_id}} |
205 | + )['router'] |
206 | + logging.info('New router created: %s', (router['id'])) |
207 | + else: |
208 | + logging.warning('Router {} already exists.'.format(opts.router)) |
209 | + router = routers['routers'][0] |
210 | + # Check to see if subnet already plugged into router |
211 | + ports = quantum.list_ports(device_owner='network:router_interface', |
212 | + network_id=network['id']) |
213 | + |
214 | + dist_ports = quantum.list_ports( |
215 | + device_owner='network:router_interface_distributed', |
216 | + network_id=network['id']) |
217 | + |
218 | + ha_ports = quantum.list_ports( |
219 | + device_owner='network:ha_router_replicated_interface', |
220 | + network_id=network['id']) |
221 | + |
222 | + if len(ports['ports'] + ha_ports['ports'] + dist_ports['ports']) == 0: |
223 | + logging.info('Adding interface from %s to %s', |
224 | + opts.router, subnet_name) |
225 | + quantum.add_interface_router(router['id'], |
226 | + {'subnet_id': subnet['id']}) |
227 | + else: |
228 | + logging.warning('Router already connected to subnet') |
229 | + |
230 | + if not router['external_gateway_info']: |
231 | + |
232 | + ext_network = quantum.list_networks(name='ext_net')['networks'][0] |
233 | + |
234 | + logging.info('Plugging router into ext_net') |
235 | + router = quantum.add_gateway_router( |
236 | + router=router['id'], |
237 | + body={'network_id': ext_network['id']} |
238 | + ) |
239 | + logging.info('Router connected to %s', 'ext_net') |
240 | else: |
241 | - # Check to see if subnet already plugged into router |
242 | - ports = quantum.list_ports(device_owner='network:router_interface', |
243 | - network_id=network['id']) |
244 | - if len(ports['ports']) == 0: |
245 | - logging.info('Adding interface from %s to %s', |
246 | - opts.router, subnet_name) |
247 | - router = routers['routers'][0] |
248 | - quantum.add_interface_router(router['id'], |
249 | - {'subnet_id': subnet['id']}) |
250 | - else: |
251 | - logging.warning('Router already connected to subnet') |
252 | + logging.warning('Router already connect to %s', 'ext_net') |
253 | + |
254 | diff --git a/openstack/profiles/default b/openstack/profiles/default |
255 | index ce561e0..811526c 100755 |
256 | --- a/openstack/profiles/default |
257 | +++ b/openstack/profiles/default |
258 | @@ -34,15 +34,17 @@ fi |
259 | source novarc |
260 | |
261 | if is_ksv3; then |
262 | - ./bin/neutron-ext-net-ksv3 --project admin --network-type flat -g $GATEWAY -c $CIDR_EXT -f $FIP_RANGE ext_net |
263 | - ./bin/neutron-tenant-net-ksv3 --project admin --network-type $net_type -r provider-router $NS_ARG private $CIDR_PRIV |
264 | # Create demo/testing users, tenants and flavor |
265 | create_tempest_users_v3 |
266 | + ./bin/neutron-ext-net-ksv3 --project admin --network-type flat -g $GATEWAY -c $CIDR_EXT -f $FIP_RANGE ext_net |
267 | + ./bin/neutron-tenant-net-ksv3 --project admin --network-type $net_type -r provider-router $NS_ARG private $CIDR_PRIV |
268 | + ./bin/neutron-tenant-net-ksv3 --project demo --network-type $net_type -r demo-router $NS_ARG private-demo $CIDR_PRIV |
269 | else |
270 | - ./bin/neutron-ext-net --network-type flat -g $GATEWAY -c $CIDR_EXT -f $FIP_RANGE ext_net |
271 | - ./bin/neutron-tenant-net --network-type $net_type -t admin -r provider-router $NS_ARG private $CIDR_PRIV |
272 | # Create demo/testing users, tenants and flavor |
273 | create_tempest_users |
274 | + ./bin/neutron-ext-net --network-type flat -g $GATEWAY -c $CIDR_EXT -f $FIP_RANGE ext_net |
275 | + ./bin/neutron-tenant-net --network-type $net_type -t admin -r provider-router $NS_ARG private $CIDR_PRIV |
276 | + ./bin/neutron-tenant-net --network-type $net_type -t demo -r demo-router $NS_ARG private-demo $CIDR_PRIV |
277 | fi |
278 | |
279 | # Download images if not already present |
280 | @@ -74,3 +76,4 @@ image_alt_id=$(openstack image list --name cirros2 -f value -c ID 2>/dev/null || |
281 | echo "Flavors" |
282 | create_tempest_flavors |
283 | create_default_flavors |
284 | + |
Hi Rodrigo, thanks for taking the time to look at this code. I think it might be better to add this as a new script/tool (i.e. under /tools) so that people can have an easy way to create arbitrary networks. I can see the benefit of having an extra network but personally i don't want to have one whenever i do a deployment and for debug and comparison purposes it actually helps me if the segmentation id is always the same (since if it changes it is yet another thing to identify). Also regarding moving router creation, I think the reason why router and network creation were kept in separate scripts was somewhat for this reason. Typically a tenant will have a one router with one or more networks attached. Maybe lets have a think about how we can make this work for everybody.