Merge "Add network commissioning script"
diff --git a/README.rst b/README.rst
index 9e0d472..f6c1f9f 100644
--- a/README.rst
+++ b/README.rst
@@ -130,7 +130,7 @@
subnet: cidr:192.168.10.0/24
mac: '66:55:44:33:22:11'
commissioning_scripts:
- 00-maas-06-create-raid.sh: /srv/salt/reclass/scripts/commisioning_script.sh
+ 00-maas-05-simplify-network-interfaces: /etc/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces
maas_config:
domain: mydomain.local
http_proxy: http://192.168.0.10:3142
diff --git a/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces b/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces
new file mode 100755
index 0000000..b4cc872
--- /dev/null
+++ b/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# Those script exchange default maas commissioning logic:
+# and report interface names in different way.
+# Initial logic stored in:
+# /usr/lib/python3/dist-packages/provisioningserver/refresh/node_info_scripts.py
+# IPADDR_SCRIPT variable.
+
+function process_ipaddr(){
+i=1
+j=1
+
+ethernets=$(ip -o l | grep -E '^[0-9]+:\ .*link/ether.*' | awk -F":" '/,/{gsub(/ /, "", $0); print $2}' | grep -Ev "br|bond")
+
+declare -A interfaces
+for iface in ${ethernets[@]}; do
+ speed=`ethtool $iface | grep '40000'`
+ if [[ "$?" == 0 ]]; then
+ interfaces[$iface]="fourty$i"
+ ((i++))
+ else
+ speed=`ethtool $iface | grep '10000' `
+ if [[ "$?" == 0 ]]; then
+ interfaces[$iface]="ten$i"
+ ((i++))
+ else
+ interfaces[$iface]="one$j"
+ ((j++))
+ fi
+ fi
+done
+
+for i in ${!interfaces[@]}; do
+ sedline+="-e s/${i}/${interfaces[$i]}/ "
+done
+
+ip addr | sed ${sedline}
+}
+
+if [[ "$(basename $0)" != "99-maas-03-network-interfaces" ]]; then
+ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
+ echo "Apply 00-maas-05-simplify-network-interfaces modificathion:"
+ cp -v $0 ${SCRIPTPATH}/99-maas-03-network-interfaces
+ chmod 0755 ${SCRIPTPATH}/99-maas-03-network-interfaces
+else
+ process_ipaddr
+fi
diff --git a/maas/region.sls b/maas/region.sls
index 3b88307..90d6657 100644
--- a/maas/region.sls
+++ b/maas/region.sls
@@ -119,49 +119,81 @@
- require:
- cmd: maas_login_admin
+{%- if region.get('commissioning_scripts', False) %}
+/etc/maas/files/commisioning_scripts/:
+ file.directory:
+ - user: root
+ - group: root
+ - mode: 755
+ - makedirs: true
+ - require:
+ - pkg: maas_region_packages
+
+/etc/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces:
+ file.managed:
+ - source: salt://maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces
+ - mode: 755
+ - user: root
+ - group: root
+ - require:
+ - file: /etc/maas/files/commisioning_scripts/
+
maas_commissioning_scripts:
module.run:
- name: maas.process_commissioning_scripts
- require:
- module: maas_config
+{%- endif %}
+{%- if region.get('fabrics', False) %}
maas_fabrics:
module.run:
- name: maas.process_fabrics
- require:
- module: maas_config
+{%- endif %}
+{%- if region.get('subnets', False) %}
maas_subnets:
module.run:
- name: maas.process_subnets
- require:
- module: maas_config
- module: maas_fabrics
+{%- endif %}
+{%- if region.get('devices', False) %}
maas_devices:
module.run:
- name: maas.process_devices
- require:
- module: maas_config
- module: maas_subnets
+{%- endif %}
+{%- if region.get('dhcp_snippets', False) %}
maas_dhcp_snippets:
module.run:
- name: maas.process_dhcp_snippets
- require:
- module: maas_config
+{%- endif %}
+{%- if region.get('package_repositories', False) %}
maas_package_repositories:
module.run:
- name: maas.process_package_repositories
- require:
- module: maas_config
+{%- endif %}
+{%- if region.get('boot_resources', False) %}
maas_boot_resources:
module.run:
- name: maas.process_boot_resources
- require:
- module: maas_config
+{%- endif %}
maas_domain:
module.run:
@@ -169,10 +201,12 @@
- require:
- module: maas_config
+{%- if region.get('sshprefs', False) %}
maas_sshprefs:
module.run:
- name: maas.process_sshprefs
- require:
- module: maas_config
+{%- endif %}
{%- endif %}