-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(distrib): Network configuration customization during Kura install (
#5419) * Fixed typo in postinstall debian scripts Signed-off-by: pierantoniomerlino <[email protected]> * Implemented default network configuration selection logic Signed-off-by: pierantoniomerlino <[email protected]> * Removed useless empty lines in templates; fix variable name Signed-off-by: pierantoniomerlino <[email protected]> * Removed commented block Signed-off-by: pierantoniomerlino <[email protected]> * Fixed sevaral typos in templates Signed-off-by: pierantoniomerlino <[email protected]> * Updated constants in python scripts Signed-off-by: pierantoniomerlino <[email protected]> * Fixed args management in Python scritps Signed-off-by: pierantoniomerlino <[email protected]> * Fixed ugly for loop management Signed-off-by: pierantoniomerlino <[email protected]> * Updated file management in python scripts Signed-off-by: pierantoniomerlino <[email protected]> * Added management of NN profiles configuration Signed-off-by: pierantoniomerlino <[email protected]> * Improved snapshot management Signed-off-by: pierantoniomerlino <[email protected]> * Fixed raspberry nn installation Signed-off-by: pierantoniomerlino <[email protected]> * Removed comment Signed-off-by: pierantoniomerlino <[email protected]> * Fixed eth and wlan default configuration Signed-off-by: pierantoniomerlino <[email protected]> * Removed resources for specific devices Signed-off-by: pierantoniomerlino <[email protected]> * Added argparse to python scripts Signed-off-by: pierantoniomerlino <[email protected]> * Fixed script usage message Signed-off-by: pierantoniomerlino <[email protected]> --------- Signed-off-by: pierantoniomerlino <[email protected]>
- Loading branch information
1 parent
23a27ee
commit 34f4fae
Showing
35 changed files
with
743 additions
and
945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
kura/distrib/src/main/resources/common/customize_iptables.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
# | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Eurotech | ||
# | ||
import sys | ||
import logging | ||
import os | ||
from network_tools import get_eth_wlan_interfaces_names | ||
|
||
def main(): | ||
logging.basicConfig( | ||
format='[customize_iptables.py] %(asctime)s %(levelname)s %(message)s', | ||
level=logging.INFO, | ||
datefmt='%Y-%m-%d %H:%M:%S', | ||
handlers=[ | ||
logging.StreamHandler() | ||
] | ||
) | ||
|
||
IPTABLES_FILENAME = "/opt/eclipse/kura/.data/iptables" | ||
|
||
(eth_names, wlan_names) = get_eth_wlan_interfaces_names() | ||
|
||
eth_number = len(eth_names) | ||
wlan_number = len(wlan_names) | ||
|
||
if eth_number == 0: | ||
logging.info("ERROR: no ethernet interface found") | ||
exit(1) | ||
|
||
logging.info("%s : starting editing", IPTABLES_FILENAME) | ||
with open(IPTABLES_FILENAME, 'r', encoding='utf-8') as iptables: | ||
iptables_content = iptables.read() | ||
|
||
iptables_content_updated = "" | ||
if wlan_number == 0: | ||
for line in iptables_content.split("\n"): | ||
if 'WIFI_INTERFACE_0' not in line: | ||
iptables_content_updated += (line.replace('ETH_INTERFACE_0', eth_names[0]) + "\n") | ||
else: | ||
iptables_content_updated = iptables_content | ||
iptables_content_updated = iptables_content_updated.replace('ETH_INTERFACE_0', eth_names[0]) | ||
iptables_content_updated = iptables_content_updated.replace('WIFI_INTERFACE_0', wlan_names[0]) | ||
|
||
with open(IPTABLES_FILENAME, 'w', encoding='utf-8') as iptables: | ||
iptables.write(iptables_content_updated) | ||
|
||
logging.info("%s : successfully edited", IPTABLES_FILENAME) | ||
|
||
if __name__ == "__main__": | ||
main() |
55 changes: 55 additions & 0 deletions
55
kura/distrib/src/main/resources/common/customize_kura_properties.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
# | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Eurotech | ||
# | ||
import sys | ||
import logging | ||
import os | ||
import argparse | ||
from network_tools import get_eth_wlan_interfaces_names | ||
|
||
def main(): | ||
logging.basicConfig( | ||
format='[customize_kura_properties.py] %(asctime)s %(levelname)s %(message)s', | ||
level=logging.INFO, | ||
datefmt='%Y-%m-%d %H:%M:%S', | ||
handlers=[ | ||
logging.StreamHandler() | ||
] | ||
) | ||
|
||
parser = argparse.ArgumentParser(description="Customize kura properties file", usage='%(prog)s device_name') | ||
parser.add_argument('device_name', help='The name of the device') | ||
args = parser.parse_args() | ||
|
||
KURA_PROPERTIES_FILENAME = "/opt/eclipse/kura/framework/kura.properties" | ||
|
||
(eth_names, wlan_names) = get_eth_wlan_interfaces_names() | ||
|
||
if len(eth_names) == 0: | ||
logging.info("ERROR: no ethernet interface found") | ||
exit(1) | ||
|
||
logging.info("%s : starting editing", KURA_PROPERTIES_FILENAME) | ||
with open(KURA_PROPERTIES_FILENAME, 'r', encoding='utf-8') as kura_properties: | ||
kura_properties_content = kura_properties.read() | ||
|
||
kura_properties_content = kura_properties_content.replace('device_name', args.device_name) | ||
kura_properties_content = kura_properties_content.replace('eth0', eth_names[0]) | ||
|
||
with open(KURA_PROPERTIES_FILENAME, 'w', encoding='utf-8') as kura_properties: | ||
kura_properties.write(kura_properties_content) | ||
|
||
logging.info("%s : successfully edited", KURA_PROPERTIES_FILENAME) | ||
|
||
if __name__ == "__main__": | ||
main() |
111 changes: 111 additions & 0 deletions
111
kura/distrib/src/main/resources/common/customize_snapshot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2024 Eurotech and/or its affiliates and others | ||
# | ||
# This program and the accompanying materials are made | ||
# available under the terms of the Eclipse Public License 2.0 | ||
# which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Eurotech | ||
# | ||
import sys | ||
import logging | ||
import os | ||
import argparse | ||
from network_tools import get_eth_wlan_interfaces_names | ||
|
||
def main(): | ||
logging.basicConfig( | ||
format='[customize_snapshot.py] %(asctime)s %(levelname)s %(message)s', | ||
level=logging.INFO, | ||
datefmt='%Y-%m-%d %H:%M:%S', | ||
handlers=[ | ||
logging.StreamHandler() | ||
] | ||
) | ||
|
||
SNAPSHOT_FILENAME = "/opt/eclipse/kura/user/snapshots/snapshot_0.xml" | ||
|
||
parser = argparse.ArgumentParser(description="Customize snapshot_0.xml file", usage='%(prog)s [--networking_profile]') | ||
parser.add_argument('--networking_profile', action='store_true', help='Specifies if this is a profile with or without networking') | ||
parser.set_defaults(networking_profile=False) | ||
args = parser.parse_args() | ||
|
||
if not args.networking_profile: | ||
with open(SNAPSHOT_FILENAME, 'r', encoding='utf-8') as snapshot: | ||
snapshot_content = snapshot.read() | ||
|
||
snapshot_content_updated = "" | ||
for line in snapshot_content.split("\n"): | ||
if 'NETWORK_CONFIGURATION' not in line and 'FIREWALL_CONFIGURATION' not in line: | ||
snapshot_content_updated += (line + "\n") | ||
|
||
with open(SNAPSHOT_FILENAME, 'w', encoding='utf-8') as snapshot: | ||
snapshot.write(snapshot_content_updated) | ||
logging.info("%s : successfully edited", SNAPSHOT_FILENAME) | ||
|
||
else: | ||
(eth_names, wlan_names) = get_eth_wlan_interfaces_names() | ||
|
||
eth_number = len(eth_names) | ||
wlan_number = len(wlan_names) | ||
|
||
if eth_number == 0: | ||
logging.info("ERROR: no ethernet interface found") | ||
exit(1) | ||
|
||
network_configuration_template = "/opt/eclipse/kura/install/template_one_eth_no_wlan" | ||
firewall_configuration_template = "/opt/eclipse/kura/install/template_firewall_eth" | ||
if eth_number == 1: | ||
if wlan_number == 0: | ||
network_configuration_template = "/opt/eclipse/kura/install/template_one_eth_no_wlan" | ||
firewall_configuration_template = "/opt/eclipse/kura/install/template_firewall_eth" | ||
else: | ||
network_configuration_template = "/opt/eclipse/kura/install/template_one_eth_one_wlan" | ||
firewall_configuration_template = "/opt/eclipse/kura/install/template_firewall_eth_wlan" | ||
else: | ||
if wlan_number == 0: | ||
network_configuration_template = "/opt/eclipse/kura/install/template_multiple_eth_no_wlan" | ||
firewall_configuration_template = "/opt/eclipse/kura/install/template_firewall_eth" | ||
else: | ||
network_configuration_template = "/opt/eclipse/kura/install/template_multiple_eth_one_wlan" | ||
firewall_configuration_template = "/opt/eclipse/kura/install/template_firewall_eth_wlan" | ||
|
||
|
||
logging.info("%s : starting editing", SNAPSHOT_FILENAME) | ||
with open(SNAPSHOT_FILENAME, 'r', encoding='utf-8') as snapshot: | ||
snapshot_content = snapshot.read() | ||
|
||
with open(network_configuration_template, 'r', encoding='utf-8') as network_template: | ||
network_template_content = network_template.read() | ||
|
||
with open(firewall_configuration_template, 'r', encoding='utf-8') as firewall_template: | ||
firewall_template_content = firewall_template.read() | ||
|
||
snapshot_content = snapshot_content.replace('NETWORK_CONFIGURATION', network_template_content) | ||
snapshot_content = snapshot_content.replace('FIREWALL_CONFIGURATION', firewall_template_content) | ||
|
||
interfaces_list = "lo" | ||
|
||
for i, eth_name in enumerate(eth_names[:2]): | ||
snapshot_content = snapshot_content.replace('ETH_INTERFACE_' + str(i), eth_name) | ||
interfaces_list += "," + eth_name | ||
logging.info("%s : replaced ETH_INTERFACE_%s with %s", SNAPSHOT_FILENAME, str(i), eth_name) | ||
|
||
for i, wlan_name in enumerate(wlan_names[:1]): | ||
snapshot_content = snapshot_content.replace('WIFI_INTERFACE_' + str(i), wlan_name) | ||
interfaces_list += "," + wlan_name | ||
logging.info("%s : replaced WIFI_INTERFACE_%s with %s", SNAPSHOT_FILENAME, str(i), wlan_name) | ||
|
||
snapshot_content = snapshot_content.replace('INTERFACES_LIST', interfaces_list) | ||
|
||
with open(SNAPSHOT_FILENAME, 'w', encoding='utf-8') as snapshot: | ||
snapshot.write(snapshot_content) | ||
|
||
logging.info("%s : successfully edited", SNAPSHOT_FILENAME) | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.