summaryrefslogtreecommitdiffstats
path: root/lib/python/apex-python-utils.py
diff options
context:
space:
mode:
authorFeng Pan <fpan@redhat.com>2016-05-07 16:04:00 -0400
committerFeng Pan <fpan@redhat.com>2016-05-08 19:55:46 -0400
commit683f9010b19232897648913e767a0dc05dbf498e (patch)
tree1e144355699651ce404f675e82a9de3147c48a05 /lib/python/apex-python-utils.py
parent5c45d868e4cf4eaf54ae52eae6aadcd982898024 (diff)
Change NIC template format
Convert compute and controller NIC templates to jinja2 format. Added support for IPv6 for those NIC templates. Existing IPv4 template generation behavior does not change. The .template files are kept in tree for now, they will be removed after VLAN changes are made. Change-Id: I2ffc7c403af3659db780ece2bd9195cd62748f0c Signed-off-by: Feng Pan <fpan@redhat.com>
Diffstat (limited to 'lib/python/apex-python-utils.py')
-rwxr-xr-xlib/python/apex-python-utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/python/apex-python-utils.py b/lib/python/apex-python-utils.py
index 802e8571..1d5b4a7c 100755
--- a/lib/python/apex-python-utils.py
+++ b/lib/python/apex-python-utils.py
@@ -13,6 +13,8 @@ import sys
import apex
import logging
import os
+from jinja2 import Environment, FileSystemLoader
+
def parse_net_settings(settings_args):
settings = apex.NetworkSettings(settings_args.path,
@@ -27,6 +29,14 @@ def find_ip(int_args):
print(interface.ip)
+def build_nic_template(nic_args):
+ env = Environment(loader=FileSystemLoader(nic_args.template_directory))
+ template = env.get_template(nic_args.template_filename)
+ print(template.render(enabled_networks=nic_args.enabled_networks,
+ external_net_type=nic_args.ext_net_type,
+ external_net_af=nic_args.address_family))
+
+
parser = argparse.ArgumentParser()
parser.add_argument('--DEBUG', action='store_true', default=False,
help="Turn on debug messages")
@@ -49,6 +59,20 @@ get_int_ip.add_argument('-af', '--address_family', default=4, type=int,
help='IP Address family')
get_int_ip.set_defaults(func=find_ip)
+nic_template = subparsers.add_parser('nic_template', help='Build NIC templates')
+nic_template.add_argument('-d', '--template_directory', required=True,
+ help='Template file directory')
+nic_template.add_argument('-f', '--template_filename', required=True,
+ help='Template file to process')
+nic_template.add_argument('-n', '--enabled_networks', required=True,
+ help='enabled network list')
+nic_template.add_argument('-e', '--ext_net_type', default='interface',
+ choices=['interface', 'br-ex'],
+ help='External network type')
+nic_template.add_argument('-af', '--address_family', type=int, default=4,
+ help='IP address family')
+nic_template.set_defaults(func=build_nic_template)
+
args = parser.parse_args(sys.argv[1:])
if args.DEBUG:
logging.basicConfig(level=logging.DEBUG)