--- /dev/null
+#!/usr/bin/env python
+################################################################################
+# Copyright 2023 highstreet technologies GmbH
+#
+# 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.
+#
+
+import os
+import argparse
+
+default_ip_address = 'aaa.bbb.ccc.ddd'
+default_http_domain = 'smo.o-ran-sc.org'
+
+script_name = os.path.basename(__file__)
+directory_path = os.path.dirname(__file__)
+file_extensions = ['.env', '.yaml', '.json']
+
+parser = argparse.ArgumentParser(script_name)
+required = parser.add_argument_group('required named arguments')
+required.add_argument("-i", "--ip_address", help="The remote accessable IP address of this system.", type=str, required=True)
+parser.add_argument("-d", "--http_domain", help="The http domain. Default is " + default_http_domain + ".", type=str, default=default_http_domain)
+parser.add_argument("-r", "--revert", help="Reverts the previous made changes.", action='store_true')
+args = parser.parse_args()
+
+def find_replace(directory, find_text, replace_text, extensions):
+ for root, dirs, files in os.walk(directory):
+ for file_name in files:
+ file_path = os.path.join(root, file_name)
+ file_ext = os.path.splitext(file_name)[1]
+ if file_ext in extensions or file_name in extensions:
+ with open(file_path, 'r') as file:
+ content = file.read()
+ if find_text in content:
+ updated_content = content.replace(find_text, replace_text)
+ with open(file_path, 'w') as file:
+ file.write(updated_content)
+ print(f"Replaced '{find_text}' with '{replace_text}' in '{file_path}'")
+
+if args.revert == False:
+ # replace ip
+ find_replace(directory_path, default_ip_address, args.ip_address, file_extensions)
+
+ # replace domain
+ if not args.http_domain == default_http_domain:
+ find_replace(directory_path, default_http_domain, args.http_domain, file_extensions)
+else:
+ # revert back ip
+ find_replace(directory_path, args.ip_address, default_ip_address, file_extensions)
+
+ # revert back domain
+ if not args.http_domain == default_http_domain:
+ find_replace(directory_path, args.http_domain, default_http_domain, file_extensions)
import os
import sys
import json
+import re
import requests
import subprocess
import pathlib
def get_environment_variable(name):
configs = Properties()
- path = pathlib.Path( os.path.dirname(os.path.abspath(__file__)) )
+ path = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
env_file = str(path.absolute()) + '/.env'
with open(env_file, "rb") as read_prop:
configs.load(read_prop)
- return configs.get(name).data
+ value = configs.get(name).data
+
+ regex = r"\$\{([^\}]+)\}"
+ matches = re.finditer(regex, value)
+ while True:
+ match = next(matches, None)
+ if match is None:
+ break
+ inner = get_environment_variable(match.group(1))
+ value = value.replace("${" + match.group(1) + "}", inner )
+ return value
dockerFilter = subprocess.check_output("docker ps --format '{{.Names}}'", shell=True)
containers = dockerFilter.splitlines()
import time
import getpass
import requests
+import re
import warnings
from jproperties import Properties
from typing import List
env_file = str(path.parent.absolute()) + '/.env'
with open(env_file, "rb") as read_prop:
configs.load(read_prop)
- return configs.get(name).data
+ value = configs.get(name).data
+
+ regex = r"\$\{([^\}]+)\}"
+ matches = re.finditer(regex, value)
+ while True:
+ match = next(matches, None)
+ if match is None:
+ break
+ inner = get_environment_variable(match.group(1))
+ value = value.replace("${" + match.group(1) + "}", inner )
+ return value
def load_arguments(args: List[str]) -> tuple:
def isReady(timeoutSeconds=180):
url = getBaseUrl()
+ print(f'url={url}')
while timeoutSeconds > 0:
try:
response = requests.get(url, verify=False, headers={})