summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2016-04-12 14:39:32 -0400
committerDan Radez <dradez@redhat.com>2016-06-28 10:02:05 -0400
commitec53529b33c22eb54f6d9af5aa14e4ef74340963 (patch)
treed67781d8e834de3c9d803ec5e44e2a3b6bc14d9c /lib
parentcc35694a87dfab1afbf429bedf67e2ef63003f3d (diff)
Adding VLAN support
JIRA: APEX-136 JIRA: APEX-30 Change-Id: I7cbbe11f4c1f1455dba253733c78fe8dc215de97 Signed-off-by: Dan Radez <dradez@redhat.com>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/python/apex-python-utils.py56
-rw-r--r--lib/python/apex/network_environment.py15
-rw-r--r--lib/python/apex/network_settings.py5
3 files changed, 62 insertions, 14 deletions
diff --git a/lib/python/apex-python-utils.py b/lib/python/apex-python-utils.py
index c9dcaa55..01e6b03b 100755
--- a/lib/python/apex-python-utils.py
+++ b/lib/python/apex-python-utils.py
@@ -9,11 +9,21 @@
import argparse
import sys
-import apex
import logging
import os
import yaml
-from jinja2 import Environment, FileSystemLoader
+
+from copy import copy
+
+from jinja2 import Environment
+from jinja2 import FileSystemLoader
+
+from apex import NetworkSettings
+from apex import NetworkEnvironment
+from apex import DeploySettings
+from apex import ip_utils
+from apex.common.constants import OPNFV_NETWORK_TYPES
+from apex.common.constants import ADMIN_NETWORK
def parse_net_settings(args):
@@ -27,9 +37,9 @@ def parse_net_settings(args):
- network_isolation: bool
enable or disable network_isolation
"""
- settings = apex.NetworkSettings(args.net_settings_file,
- args.network_isolation)
- net_env = apex.NetworkEnvironment(settings, args.net_env_file)
+ settings = NetworkSettings(args.net_settings_file,
+ args.network_isolation)
+ net_env = NetworkEnvironment(settings, args.net_env_file)
dump_yaml(net_env.get_netenv_settings(), '/tmp/network-environment.yaml')
settings.dump_bash()
@@ -46,7 +56,7 @@ def dump_yaml(data, file):
def parse_deploy_settings(args):
- settings = apex.DeploySettings(args.file)
+ settings = DeploySettings(args.file)
settings.dump_bash()
@@ -60,8 +70,8 @@ def find_ip(args):
- address_family: int
4 or 6, respective to ipv4 or ipv6
"""
- interface = apex.ip_utils.get_interface(args.interface,
- args.address_family)
+ interface = ip_utils.get_interface(args.interface,
+ args.address_family)
if interface:
print(interface.ip)
@@ -84,12 +94,24 @@ def build_nic_template(args):
"""
template_dir, template = args.template.rsplit('/', 1)
+ settings = NetworkSettings(args.net_settings_file,
+ args.network_isolation).settings_obj
env = Environment(loader=FileSystemLoader(template_dir))
template = env.get_template(template)
- print(template.render(enabled_networks=args.enabled_networks,
- external_net_type=args.ext_net_type,
- external_net_af=args.address_family,
- ovs_dpdk_bridge=args.ovs_dpdk_bridge))
+
+ # gather vlan values into a dict
+ net_list = copy(args.enabled_networks).split(' ')
+ net_list.remove(ADMIN_NETWORK)
+ vlans_vals = map(lambda x: settings[x]['vlan'], net_list)
+ vlans = dict(zip(net_list, vlans_vals))
+
+ print(template.render(
+ enabled_networks=args.enabled_networks,
+ role=args.role,
+ vlans=vlans,
+ external_net_type=args.ext_net_type,
+ external_net_af=args.address_family,
+ ovs_dpdk_bridge=args.ovs_dpdk_bridge))
def parse_args():
@@ -126,9 +148,19 @@ def parse_args():
nic_template = subparsers.add_parser('nic-template',
help='Build NIC templates')
+ nic_template.add_argument('-r', '--role', required=True,
+ choices=['controller', 'compute'],
+ help='Role template generated for')
nic_template.add_argument('-t', '--template', required=True,
dest='template',
help='Template file to process')
+ nic_template.add_argument('-s', '--net-settings-file',
+ default='network-settings.yaml',
+ dest='net_settings_file',
+ help='path to network settings file')
+ nic_template.add_argument('-i', '--network-isolation', type=bool,
+ default=True, dest='network_isolation',
+ help='network isolation')
nic_template.add_argument('-n', '--enabled-networks', required=True,
dest='enabled_networks',
help='enabled network list')
diff --git a/lib/python/apex/network_environment.py b/lib/python/apex/network_environment.py
index c6483d12..fd6f5286 100644
--- a/lib/python/apex/network_environment.py
+++ b/lib/python/apex/network_environment.py
@@ -69,6 +69,7 @@ class NetworkEnvironment:
break
if not tht_dir:
raise NetworkEnvException('Unable to parse THT Directory')
+
admin_cidr = net_settings[constants.ADMIN_NETWORK]['cidr']
admin_prefix = str(admin_cidr.prefixlen)
self.netenv_obj[param_def]['ControlPlaneSubnetCidr'] = admin_prefix
@@ -76,6 +77,9 @@ class NetworkEnvironment:
net_settings[constants.ADMIN_NETWORK]['provisioner_ip']
public_cidr = net_settings[constants.PUBLIC_NETWORK]['cidr']
self.netenv_obj[param_def]['ExternalNetCidr'] = str(public_cidr)
+ if net_settings[constants.PUBLIC_NETWORK]['vlan'] != 'native':
+ self.netenv_obj[param_def]['ExternalNetworkVlanID'] = \
+ net_settings[constants.PUBLIC_NETWORK]['vlan']
public_range = net_settings[constants.PUBLIC_NETWORK][
'usable_ip_range'].split(',')
self.netenv_obj[param_def]['ExternalAllocationPools'] = \
@@ -114,6 +118,9 @@ class NetworkEnvironment:
postfix = '/tenant_v6.yaml'
else:
postfix = '/tenant.yaml'
+ if net_settings[constants.PRIVATE_NETWORK]['vlan'] != 'native':
+ self.netenv_obj[param_def]['TenantNetworkVlanID'] = \
+ net_settings[constants.PRIVATE_NETWORK]['vlan']
else:
postfix = '/noop.yaml'
@@ -137,6 +144,9 @@ class NetworkEnvironment:
postfix = '/storage_v6.yaml'
else:
postfix = '/storage.yaml'
+ if net_settings[constants.STORAGE_NETWORK]['vlan'] != 'native':
+ self.netenv_obj[param_def]['StorageNetworkVlanID'] = \
+ net_settings[constants.STORAGE_NETWORK]['vlan']
else:
postfix = '/noop.yaml'
@@ -160,8 +170,9 @@ class NetworkEnvironment:
postfix = '/internal_api_v6.yaml'
else:
postfix = '/internal_api.yaml'
-
-
+ if net_settings[constants.API_NETWORK]['vlan'] != 'native':
+ self.netenv_obj[param_def]['InternalApiNetworkVlanID'] = \
+ net_settings[constants.API_NETWORK]['vlan']
else:
postfix = '/noop.yaml'
diff --git a/lib/python/apex/network_settings.py b/lib/python/apex/network_settings.py
index 9df8a1de..475082df 100644
--- a/lib/python/apex/network_settings.py
+++ b/lib/python/apex/network_settings.py
@@ -84,6 +84,11 @@ class NetworkSettings:
given NIC in the system. The resulting config in settings object will
be an ipaddress.network object, replacing the NIC name.
"""
+ # if vlan not defined then default it to native
+ if network is not constants.ADMIN_NETWORK:
+ if 'vlan' not in self.settings_obj[network]:
+ self.settings_obj[network]['vlan'] = 'native'
+
cidr = self.settings_obj[network].get('cidr')
nic_name = self.settings_obj[network].get('bridged_interface')