summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common-functions.sh85
-rwxr-xr-xlib/python/apex-python-utils.py11
-rw-r--r--lib/python/apex/__init__.py1
-rw-r--r--lib/python/apex/deploy_env.py149
4 files changed, 216 insertions, 30 deletions
diff --git a/lib/common-functions.sh b/lib/common-functions.sh
index e7041ac4..dfac008e 100644
--- a/lib/common-functions.sh
+++ b/lib/common-functions.sh
@@ -27,6 +27,7 @@ function find_ip {
function attach_interface_to_ovs {
local bridge interface
local if_ip if_mask if_gw if_file ovs_file if_prefix
+ local if_metric if_dns1 if_dns2
if [[ -z "$1" || -z "$2" ]]; then
return 1
@@ -46,6 +47,9 @@ function attach_interface_to_ovs {
if_ip=$(sed -n 's/^IPADDR=\(.*\)$/\1/p' ${if_file})
if_mask=$(sed -n 's/^NETMASK=\(.*\)$/\1/p' ${if_file})
if_gw=$(sed -n 's/^GATEWAY=\(.*\)$/\1/p' ${if_file})
+ if_metric=$(sed -n 's/^METRIC=\(.*\)$/\1/p' ${if_file})
+ if_dns1=$(sed -n 's/^DNS1=\(.*\)$/\1/p' ${if_file})
+ if_dns2=$(sed -n 's/^DNS2=\(.*\)$/\1/p' ${if_file})
else
echo "ERROR: ifcfg file missing for ${interface}"
return 1
@@ -77,7 +81,7 @@ ONBOOT=yes
OVS_BRIDGE=${bridge}
PROMISC=yes" > ${if_file}
- if [ -z ${if_gw} ]; then
+
# create bridge cfg
echo "DEVICE=${bridge}
DEVICETYPE=ovs
@@ -89,17 +93,24 @@ TYPE=OVSBridge
PROMISC=yes
PEERDNS=no" > ${ovs_file}
- else
- echo "DEVICE=${bridge}
-DEVICETYPE=ovs
-IPADDR=${if_ip}
-NETMASK=${if_mask}
-BOOTPROTO=static
-ONBOOT=yes
-TYPE=OVSBridge
-PROMISC=yes
-GATEWAY=${if_gw}
-PEERDNS=no" > ${ovs_file}
+ if [ -n "$if_gw" ]; then
+ echo "GATEWAY=${if_gw}" >> ${ovs_file}
+ fi
+
+ if [ -n "$if_metric" ]; then
+ echo "METRIC=${if_metric}" >> ${ovs_file}
+ fi
+
+ if [[ -n "$if_dns1" || -n "$if_dns2" ]]; then
+ sed -i '/PEERDNS/c\PEERDNS=yes' ${ovs_file}
+
+ if [ -n "$if_dns1" ]; then
+ echo "DNS1=${if_dns1}" >> ${ovs_file}
+ fi
+
+ if [ -n "$if_dns2" ]; then
+ echo "DNS2=${if_dns2}" >> ${ovs_file}
+ fi
fi
sudo systemctl restart network
@@ -113,6 +124,7 @@ function detach_interface_from_ovs {
local port_output ports_no_orig
local net_path
local if_ip if_mask if_gw if_prefix
+ local if_metric if_dns1 if_dns2
net_path=/etc/sysconfig/network-scripts/
if [[ -z "$1" ]]; then
@@ -134,12 +146,15 @@ function detach_interface_from_ovs {
elif [ -e ${net_path}/ifcfg-${line}.orig ]; then
mv -f ${net_path}/ifcfg-${line}.orig ${net_path}/ifcfg-${line}
elif [ -e ${net_path}/ifcfg-${bridge} ]; then
- if_ip=$(sed -n 's/^IPADDR=\(.*\)$/\1/p' ${if_file})
- if_mask=$(sed -n 's/^NETMASK=\(.*\)$/\1/p' ${if_file})
- if_gw=$(sed -n 's/^GATEWAY=\(.*\)$/\1/p' ${if_file})
+ if_ip=$(sed -n 's/^IPADDR=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
+ if_mask=$(sed -n 's/^NETMASK=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
+ if_gw=$(sed -n 's/^GATEWAY=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
+ if_metric=$(sed -n 's/^METRIC=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
+ if_dns1=$(sed -n 's/^DNS1=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
+ if_dns2=$(sed -n 's/^DNS2=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
if [ -z "$if_mask" ]; then
- if_prefix=$(sed -n 's/^PREFIX=\(.*\)$/\1/p' ${if_file})
+ if_prefix=$(sed -n 's/^PREFIX=\(.*\)$/\1/p' ${net_path}/ifcfg-${bridge})
if_mask=$(prefix2mask ${if_prefix})
fi
@@ -148,26 +163,34 @@ function detach_interface_from_ovs {
return 1
fi
- if [ -z ${if_gw} ]; then
- # create if cfg
- echo "DEVICE=${line}
-IPADDR=${if_ip}
-NETMASK=${if_mask}
-BOOTPROTO=static
-ONBOOT=yes
-TYPE=Ethernet
-NM_CONTROLLED=no
-PEERDNS=no" > ${net_path}/ifcfg-${line}
- else
- echo "DEVICE=${line}
+ # create if cfg
+ echo "DEVICE=${line}
IPADDR=${if_ip}
NETMASK=${if_mask}
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
NM_CONTROLLED=no
-GATEWAY=${if_gw}
PEERDNS=no" > ${net_path}/ifcfg-${line}
+
+ if [ -n "$if_gw" ]; then
+ echo "GATEWAY=${if_gw}" >> ${net_path}/ifcfg-${line}
+ fi
+
+ if [ -n "$if_metric" ]; then
+ echo "METRIC=${if_metric}" >> ${net_path}/ifcfg-${line}
+ fi
+
+ if [[ -n "$if_dns1" || -n "$if_dns2" ]]; then
+ sed -i '/PEERDNS/c\PEERDNS=yes' ${net_path}/ifcfg-${line}
+
+ if [ -n "$if_dns1" ]; then
+ echo "DNS1=${if_dns1}" >> ${net_path}/ifcfg-${line}
+ fi
+
+ if [ -n "$if_dns2" ]; then
+ echo "DNS2=${if_dns2}" >> ${net_path}/ifcfg-${line}
+ fi
fi
break
else
@@ -182,6 +205,10 @@ PEERDNS=no" > ${net_path}/ifcfg-${line}
sudo sed -i 's/IPADDR=.*//' ${net_path}/ifcfg-${bridge}
sudo sed -i 's/NETMASK=.*//' ${net_path}/ifcfg-${bridge}
sudo sed -i 's/GATEWAY=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/DNS1=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/DNS2=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/METRIC=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/PEERDNS=.*//' ${net_path}/ifcfg-${bridge}
sudo systemctl restart network
}
diff --git a/lib/python/apex-python-utils.py b/lib/python/apex-python-utils.py
index 1d5b4a7c..7e947ea6 100755
--- a/lib/python/apex-python-utils.py
+++ b/lib/python/apex-python-utils.py
@@ -7,7 +7,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
import argparse
import sys
import apex
@@ -21,6 +20,10 @@ def parse_net_settings(settings_args):
settings_args.network_isolation)
settings.dump_bash()
+def parse_deploy_settings(settings_args):
+ settings = apex.DeploySettings(settings_args.path)
+ settings.dump_bash()
+
def find_ip(int_args):
interface = apex.ip_utils.get_interface(int_args.interface,
@@ -73,6 +76,12 @@ nic_template.add_argument('-af', '--address_family', type=int, default=4,
help='IP address family')
nic_template.set_defaults(func=build_nic_template)
+deploy_settings = subparsers.add_parser('parse-deploy-settings',
+ help='Parse deploy settings file')
+deploy_settings.add_argument('-f', '--path', default='deploy_settings.yaml',
+ help='path to deploy settings file')
+deploy_settings.set_defaults(func=parse_deploy_settings)
+
args = parser.parse_args(sys.argv[1:])
if args.DEBUG:
logging.basicConfig(level=logging.DEBUG)
diff --git a/lib/python/apex/__init__.py b/lib/python/apex/__init__.py
index 88b066b2..2efc64f4 100644
--- a/lib/python/apex/__init__.py
+++ b/lib/python/apex/__init__.py
@@ -9,3 +9,4 @@
from .net_env import NetworkSettings
+from .deploy_env import DeploySettings
diff --git a/lib/python/apex/deploy_env.py b/lib/python/apex/deploy_env.py
new file mode 100644
index 00000000..5c733248
--- /dev/null
+++ b/lib/python/apex/deploy_env.py
@@ -0,0 +1,149 @@
+##############################################################################
+# Copyright (c) 2016 Michael Chapman (michapma@redhat.com) and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+
+import yaml
+import logging
+
+REQ_DEPLOY_SETTINGS = ['sdn_controller',
+ 'sdn_l3',
+ 'tacker',
+ 'congress',
+ 'sfc',
+ 'vpn']
+
+OPT_DEPLOY_SETTINGS = ['performance']
+
+VALID_ROLES = ['Controller', 'Compute', 'ObjectStorage']
+VALID_PERF_OPTS = ['kernel','nova']
+
+class DeploySettings:
+ """
+ This class parses a APEX deploy settings yaml file into an object
+
+ Currently the parsed object is dumped into a bash global definition file
+ for deploy.sh consumption. This object will later be used directly as
+ deployment script move to python.
+ """
+ def __init__(self, filename):
+ with open(filename, 'r') as settings_file:
+ self.deploy_settings = yaml.load(settings_file)
+ self._validate_settings()
+
+ def _validate_settings(self):
+ """
+ Validates the deploy settings file provided
+
+ DeploySettingsException will be raised if validation fails.
+ """
+
+ if 'deploy_options' not in self.deploy_settings:
+ raise DeploySettingsException("No deploy options provided in"
+ "deploy settings file")
+ if 'global_params' not in self.deploy_settings:
+ raise DeploySettingsException("No global options provided in"
+ "deploy settings file")
+
+ deploy_options = self.deploy_settings['deploy_options']
+ if not isinstance(deploy_options, dict):
+ raise DeploySettingsException("deploy_options should be a list")
+
+ for option in deploy_options:
+ if option not in REQ_DEPLOY_SETTINGS + OPT_DEPLOY_SETTINGS:
+ raise DeploySettingsException("Invalid deploy_option {} "
+ "specified".format(option))
+
+ for required_setting in REQ_DEPLOY_SETTINGS:
+ if required_setting not in deploy_options:
+ self.deploy_settings['deploy_options'][required] = False
+
+ if 'performance' in deploy_options:
+ if not isinstance(deploy_options['performance'], dict):
+ raise DeploySettingsException("Performance deploy_option"
+ "must be a dictionary.")
+ for role,role_perf_sets in deploy_options['performance'].items():
+ if role not in VALID_ROLES:
+ raise DeploySettingsException("Performance role {}"
+ "is not valid, choose"
+ "from {}".format(
+ role," ".join(VALID_ROLES)
+ ))
+
+ for key in role_perf_sets:
+ if key not in VALID_PERF_OPTS:
+ raise DeploySettingsException("Performance option {}"
+ "is not valid, choose"
+ "from {}".format(
+ key," ".join(
+ VALID_PERF_OPTS)))
+
+
+ def _dump_performance(self):
+ """
+ Creates performance settings string for bash consumption.
+
+ Output will be in the form of a list that can be iterated over in bash,
+ with each string being the direct input to the performance setting script
+ in the form <role> <category> <key> <value> to facilitate modification of the
+ correct image.
+ """
+ bash_str = 'performance_options=(\n'
+ for role,settings in self.deploy_settings['deploy_options']['performance'].items():
+ for category,options in settings.items():
+ for key,value in options.items():
+ bash_str += "\"{} {} {} {}\"\n".format(role, category, key, value)
+ bash_str += ')\n'
+ bash_str += '\n'
+ bash_str += 'performance_roles=(\n'
+ for role in self.deploy_settings['deploy_options']['performance']:
+ bash_str += role + '\n'
+ bash_str += ')\n'
+ bash_str += '\n'
+
+ return bash_str
+
+ def _dump_deploy_options_array(self):
+ """
+ Creates deploy settings array in bash syntax.
+ """
+ bash_str = ''
+ for key,value in self.deploy_settings['deploy_options'].items():
+ if not isinstance(value, bool):
+ bash_str += "deploy_options_array[{}]=\"{}\"\n".format(key, value)
+ else:
+ bash_str += "deploy_options_array[{}]={}\n".format(key, value)
+ return bash_str
+
+ def dump_bash(self, path=None):
+ """
+ Prints settings for bash consumption.
+
+ If optional path is provided, bash string will be written to the file
+ instead of stdout.
+ """
+ bash_str = ''
+ for key, value in self.deploy_settings['global_params'].items():
+ bash_str += "if [ -z \"$(eval echo \$${})\" ]; then\n{}={}\nfi\n".format(key,key, value)
+ if 'performance' in self.deploy_settings['deploy_options']:
+ bash_str += self._dump_performance()
+ bash_str += self._dump_deploy_options_array()
+
+ if path:
+ with open(path, 'w') as file:
+ file.write(bash_str)
+ else:
+ print(bash_str)
+
+
+class DeploySettingsException(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return self.value