summaryrefslogtreecommitdiffstats
path: root/deploy/post
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-16 15:16:12 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-21 18:25:21 +0800
commit6c077560e1cd2293fb9c6fac9065f11e555b1bbb (patch)
treed4f5a2ec3cd429c7355e922184a6276d7009d54a /deploy/post
parentfd49859523e1914bece099b326ea723068e33262 (diff)
bugfix hardcoded network configuration
Change-Id: I1fb6036a2805ccb9bdbe23622514ccd9d997c1a5 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'deploy/post')
-rw-r--r--deploy/post/execute.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/deploy/post/execute.py b/deploy/post/execute.py
index b9665e10..159f3b67 100644
--- a/deploy/post/execute.py
+++ b/deploy/post/execute.py
@@ -9,15 +9,17 @@
import os
import glance
+import argparse
+
import neutron
import nova
+from deploy.config.network import NetworkConfig
-def _config_admin_external_network():
- name = 'admin_external'
+def _config_external_network(ext_name):
body = {
'network': {
- 'name': name,
+ 'name': ext_name,
'admin_state_up': True,
'shared': False,
'provider:network_type': 'flat',
@@ -26,28 +28,34 @@ def _config_admin_external_network():
}
}
- return name, body
+ return body
-def _config_admin_external_subnet(nid):
+def _config_external_subnet(ext_id, network_conf):
return {
'subnets': [
{
- 'name': 'admin_external_subnet',
- 'cidr': '172.10.101.0/24',
+ 'name': '{}_subnet'.format(network_conf.ext_network_name),
+ 'cidr': network_conf.ext_cidr,
'ip_version': 4,
- 'network_id': nid,
- 'gateway_ip': '172.10.101.1',
- 'allocation_pools': [{
- 'start': '172.10.101.2',
- 'end': '172.10.101.12'
- }],
+ 'network_id': ext_id,
+ 'gateway_ip': network_conf.ext_gateway,
+ 'allocation_pools': network_conf.ext_ip_ranges,
'enable_dhcp': False
}
]
}
+def _create_external_network(network_file):
+ network_conf = NetworkConfig(network_file=network_file)
+ ext_name = network_conf.ext_network_name
+ neutronclient = neutron.Neutron()
+ ext_id = neutronclient.create_network(ext_name,
+ _config_external_network(ext_name))
+ neutronclient.create_subnet(_config_external_subnet(ext_id, network_conf))
+
+
def _create_flavor_m1_micro():
name = 'm1.micro'
novaclient = nova.Nova()
@@ -96,9 +104,13 @@ def _create_image_TestVM():
def main():
- neutronclient = neutron.Neutron()
- nid = neutronclient.create_network(*(_config_admin_external_network()))
- neutronclient.create_subnet(_config_admin_external_subnet(nid))
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-nw', '--network-file',
+ type=str,
+ required=True,
+ help='network configuration file')
+ args = parser.parse_args()
+ _create_external_network(args.network_file)
_create_flavor_m1_micro()
_create_image_TestVM()