diff options
author | Zhijiang Hu <hu.zhijiang@zte.com.cn> | 2017-03-23 02:04:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-03-23 02:04:10 +0000 |
commit | 19951f6c2bbfc3d4c9a87a7b1039fe7bc9116d38 (patch) | |
tree | 092712d1e160c7842765983c76becf67f1ec903b /deploy/post/execute.py | |
parent | 1f2aa321b64d65487d77cfd6bd51c9c9903b9a7b (diff) | |
parent | 6c077560e1cd2293fb9c6fac9065f11e555b1bbb (diff) |
Merge "bugfix hardcoded network configuration"
Diffstat (limited to 'deploy/post/execute.py')
-rw-r--r-- | deploy/post/execute.py | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/deploy/post/execute.py b/deploy/post/execute.py index 288e949b..d310acbc 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() |