X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwcm%2Fplugins%2Frwconman%2Frift%2Ftasklets%2Frwconmantasklet%2Fxlate_cfg.py;fp=rwcm%2Fplugins%2Frwconman%2Frift%2Ftasklets%2Frwconmantasklet%2Fxlate_cfg.py;h=add8a9a49fed46fb38743b9ca96538073503b190;hb=6f07e6f33f751ab4ffe624f6037f887b243bece2;hp=0000000000000000000000000000000000000000;hpb=72a563886272088feb7cb52e4aafbe6d2c580ff9;p=osm%2FSO.git diff --git a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/xlate_cfg.py b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/xlate_cfg.py new file mode 100644 index 00000000..add8a9a4 --- /dev/null +++ b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/xlate_cfg.py @@ -0,0 +1,245 @@ +#!/usr/bin/env python3 + +# +# Copyright 2016 RIFT.IO Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +''' +This script will go through the input conffiguration template and convert all the matching "regular expression" and "strings" +specified in xlate_cp_list & xlate_str_list with matching IP addresses passed in as dictionary to this script. + +-i Configuration template +-o Output final configuration complete with IP addresses +-x Xlate(Translate dictionary in string format +-t TAGS to be translated + +''' + +import sys +import getopt +import ast +import re +import yaml +import netaddr + +from inspect import getsourcefile +import os.path + +xlate_dict = None + +def xlate_cp_list(line, cp_list): + for cp_string in cp_list: + match = re.search(cp_string, line) + if match is not None: + # resolve IP address using Connection Point dictionary + resolved_ip = xlate_dict[match.group(1)] + if resolved_ip is None: + print("No matching CP found: ", match.group(1)) + exit(2) + else: + line = line[:match.start()] + resolved_ip + line[match.end():] + return line + +def xlate_multi_colon_list(line, multi_colon_list): + for ucp_string in multi_colon_list: + #print("Searching :", ucp_string) + match = re.search(ucp_string, line) + if match is not None: + #print("match :", match.group()) + # resolve IP address using Connection Point dictionary for specified member (unique) index + ucp_str_list = match.group(1).split(':') + print("matched = {}, split list = {}".format(match.group(1), ucp_str_list)) + if len(ucp_str_list) != 3: + print("Invalid TAG in the configuration: ", match.group(1)) + exit(2) + + # Traslate given CP address & mask into netaddr + if ucp_string.startswith('