summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-08-18 12:25:29 -0400
committerScott Moser <smoser@brickies.net>2016-08-22 16:20:10 -0400
commit64522efe710faf6fa1615dbb60a2fc4cc8a7c278 (patch)
tree7dfaca3f98f1105b9f9e08621c5bc29c2cdfe4c2 /tools
parent685ffd49561bb92971f6b76e4690b86d7d6ecc0f (diff)
downloadvyos-cloud-init-64522efe710faf6fa1615dbb60a2fc4cc8a7c278.tar.gz
vyos-cloud-init-64522efe710faf6fa1615dbb60a2fc4cc8a7c278.zip
azure dhclient-hook cleanups
This adds some function to the generator to maintain the presense of a flag file '/run/cloud-init/enabled' indicating that cloud-init is enabled. Then, only run the dhclient hooks if on Azure and cloud-init is enabled. The test for is_azure currently only checks to see that the board vendor is Microsoft, not actually that we are on azure. Running should not be harmful anywhere, other than slowing down dhclient. The value of this additional code is that then dhclient having run does not task the system with the load of cloud-init. Additionally, some changes to config are done here. * rename 'dhclient_leases' to 'dhclient_lease_file' * move that to the datasource config (datasource/Azure/dhclient_lease_file) Also, it removes the config in config/cloud.cfg that set agent_command to __builtin__. This means that by default cloud-init still needs the agent installed. The suggested follow-on improvement is to use __builtin__ if there is no walinux-agent installed.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/hook-dhclient25
-rwxr-xr-xtools/hook-network-manager23
-rwxr-xr-xtools/hook-rhel.sh15
3 files changed, 54 insertions, 9 deletions
diff --git a/tools/hook-dhclient b/tools/hook-dhclient
index d099979a..6a4626c6 100755
--- a/tools/hook-dhclient
+++ b/tools/hook-dhclient
@@ -1,9 +1,24 @@
#!/bin/sh
# This script writes DHCP lease information into the cloud-init run directory
# It is sourced, not executed. For more information see dhclient-script(8).
+is_azure() {
+ local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
+ if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
+ [ "$vendor" = "Microsoft Corporation" ] && return 0
+ fi
+ return 1
+}
-case "$reason" in
- BOUND) cloud-init dhclient-hook up "$interface";;
- DOWN|RELEASE|REBOOT|STOP|EXPIRE)
- cloud-init dhclient-hook down "$interface";;
-esac
+is_enabled() {
+ # only execute hooks if cloud-init is enabled and on azure
+ [ -e /run/cloud-init/enabled ] || return 1
+ is_azure
+}
+
+if is_enabled; then
+ case "$reason" in
+ BOUND) cloud-init dhclient-hook up "$interface";;
+ DOWN|RELEASE|REBOOT|STOP|EXPIRE)
+ cloud-init dhclient-hook down "$interface";;
+ esac
+fi
diff --git a/tools/hook-network-manager b/tools/hook-network-manager
index 447b134e..98a36c8a 100755
--- a/tools/hook-network-manager
+++ b/tools/hook-network-manager
@@ -2,8 +2,23 @@
# This script hooks into NetworkManager(8) via its scripts
# arguments are 'interface-name' and 'action'
#
+is_azure() {
+ local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
+ if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
+ [ "$vendor" = "Microsoft Corporation" ] && return 0
+ fi
+ return 1
+}
-case "$1:$2" in
- *:up) exec cloud-init dhclient-hook up "$1";;
- *:down) exec cloud-init dhclient-hook down "$1";;
-esac
+is_enabled() {
+ # only execute hooks if cloud-init is enabled and on azure
+ [ -e /run/cloud-init/enabled ] || return 1
+ is_azure
+}
+
+if is_enabled; then
+ case "$1:$2" in
+ *:up) exec cloud-init dhclient-hook up "$1";;
+ *:down) exec cloud-init dhclient-hook down "$1";;
+ esac
+fi
diff --git a/tools/hook-rhel.sh b/tools/hook-rhel.sh
index 5e963a89..8232414c 100755
--- a/tools/hook-rhel.sh
+++ b/tools/hook-rhel.sh
@@ -2,11 +2,26 @@
# Current versions of RHEL and CentOS do not honor the directory
# /etc/dhcp/dhclient-exit-hooks.d so this file can be placed in
# /etc/dhcp/dhclient.d instead
+is_azure() {
+ local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
+ if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
+ [ "$vendor" = "Microsoft Corporation" ] && return 0
+ fi
+ return 1
+}
+
+is_enabled() {
+ # only execute hooks if cloud-init is enabled and on azure
+ [ -e /run/cloud-init/enabled ] || return 1
+ is_azure
+}
hook-rhel_config(){
+ is_enabled || return 0
cloud-init dhclient-hook up "$interface"
}
hook-rhel_restore(){
+ is_enabled || return 0
cloud-init dhclient-hook down "$interface"
}