Merge ~smoser/cloud-init:dhclient-hook-on-azure-only into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merged at revision: 64522efe710faf6fa1615dbb60a2fc4cc8a7c278
Proposed branch: ~smoser/cloud-init:dhclient-hook-on-azure-only
Merge into: cloud-init:master
Diff against target: 127 lines (+59/-9)
4 files modified
systemd/cloud-init-generator (+5/-0)
tools/hook-dhclient (+20/-5)
tools/hook-network-manager (+19/-4)
tools/hook-rhel.sh (+15/-0)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+303303@code.launchpad.net

Commit message

dhclient-hook: only run if on azure and cloud-init is enabled.

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, in the hook scripts, only run the cloud-init dhclient-hook
if we are 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.

The value of this additional code is that then dhclient having run
does not task the system with the load of cloud-init.

To post a comment you must log in.
Revision history for this message
Lars Kellogg-Stedman (larsks) :
Revision history for this message
Lars Kellogg-Stedman (larsks) :

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/systemd/cloud-init-generator b/systemd/cloud-init-generator
index 2d31969..fedb630 100755
--- a/systemd/cloud-init-generator
+++ b/systemd/cloud-init-generator
@@ -6,6 +6,7 @@ DEBUG_LEVEL=1
6LOG_D="/run/cloud-init"6LOG_D="/run/cloud-init"
7ENABLE="enabled"7ENABLE="enabled"
8DISABLE="disabled"8DISABLE="disabled"
9RUN_ENABLED_FILE="$LOG_D/$ENABLE"
9CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"10CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
10CLOUD_TARGET_NAME="cloud-init.target"11CLOUD_TARGET_NAME="cloud-init.target"
11# lxc sets 'container', but lets make that explicitly a global12# lxc sets 'container', but lets make that explicitly a global
@@ -107,6 +108,7 @@ main() {
107 "ln $CLOUD_SYSTEM_TARGET $link_path"108 "ln $CLOUD_SYSTEM_TARGET $link_path"
108 fi109 fi
109 fi110 fi
111 : > "$RUN_ENABLED_FILE"
110 elif [ "$result" = "$DISABLE" ]; then112 elif [ "$result" = "$DISABLE" ]; then
111 if [ -f "$link_path" ]; then113 if [ -f "$link_path" ]; then
112 if rm -f "$link_path"; then114 if rm -f "$link_path"; then
@@ -118,6 +120,9 @@ main() {
118 else120 else
119 debug 1 "already disabled: no change needed [no $link_path]"121 debug 1 "already disabled: no change needed [no $link_path]"
120 fi122 fi
123 if [ -e "$RUN_ENABLED_FILE" ]; then
124 rm -f "$RUN_ENABLED_FILE"
125 fi
121 else126 else
122 debug 0 "unexpected result '$result'"127 debug 0 "unexpected result '$result'"
123 ret=3128 ret=3
diff --git a/tools/hook-dhclient b/tools/hook-dhclient
index d099979..6a4626c 100755
--- a/tools/hook-dhclient
+++ b/tools/hook-dhclient
@@ -1,9 +1,24 @@
1#!/bin/sh1#!/bin/sh
2# This script writes DHCP lease information into the cloud-init run directory2# This script writes DHCP lease information into the cloud-init run directory
3# It is sourced, not executed. For more information see dhclient-script(8).3# It is sourced, not executed. For more information see dhclient-script(8).
4is_azure() {
5 local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
6 if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
7 [ "$vendor" = "Microsoft Corporation" ] && return 0
8 fi
9 return 1
10}
411
5case "$reason" in12is_enabled() {
6 BOUND) cloud-init dhclient-hook up "$interface";;13 # only execute hooks if cloud-init is enabled and on azure
7 DOWN|RELEASE|REBOOT|STOP|EXPIRE)14 [ -e /run/cloud-init/enabled ] || return 1
8 cloud-init dhclient-hook down "$interface";;15 is_azure
9esac16}
17
18if is_enabled; then
19 case "$reason" in
20 BOUND) cloud-init dhclient-hook up "$interface";;
21 DOWN|RELEASE|REBOOT|STOP|EXPIRE)
22 cloud-init dhclient-hook down "$interface";;
23 esac
24fi
diff --git a/tools/hook-network-manager b/tools/hook-network-manager
index 447b134..98a36c8 100755
--- a/tools/hook-network-manager
+++ b/tools/hook-network-manager
@@ -2,8 +2,23 @@
2# This script hooks into NetworkManager(8) via its scripts2# This script hooks into NetworkManager(8) via its scripts
3# arguments are 'interface-name' and 'action'3# arguments are 'interface-name' and 'action'
4#4#
5is_azure() {
6 local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
7 if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
8 [ "$vendor" = "Microsoft Corporation" ] && return 0
9 fi
10 return 1
11}
512
6case "$1:$2" in13is_enabled() {
7 *:up) exec cloud-init dhclient-hook up "$1";;14 # only execute hooks if cloud-init is enabled and on azure
8 *:down) exec cloud-init dhclient-hook down "$1";;15 [ -e /run/cloud-init/enabled ] || return 1
9esac16 is_azure
17}
18
19if is_enabled; then
20 case "$1:$2" in
21 *:up) exec cloud-init dhclient-hook up "$1";;
22 *:down) exec cloud-init dhclient-hook down "$1";;
23 esac
24fi
diff --git a/tools/hook-rhel.sh b/tools/hook-rhel.sh
index 5e963a8..8232414 100755
--- a/tools/hook-rhel.sh
+++ b/tools/hook-rhel.sh
@@ -2,11 +2,26 @@
2# Current versions of RHEL and CentOS do not honor the directory2# Current versions of RHEL and CentOS do not honor the directory
3# /etc/dhcp/dhclient-exit-hooks.d so this file can be placed in3# /etc/dhcp/dhclient-exit-hooks.d so this file can be placed in
4# /etc/dhcp/dhclient.d instead4# /etc/dhcp/dhclient.d instead
5is_azure() {
6 local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
7 if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
8 [ "$vendor" = "Microsoft Corporation" ] && return 0
9 fi
10 return 1
11}
12
13is_enabled() {
14 # only execute hooks if cloud-init is enabled and on azure
15 [ -e /run/cloud-init/enabled ] || return 1
16 is_azure
17}
518
6hook-rhel_config(){19hook-rhel_config(){
20 is_enabled || return 0
7 cloud-init dhclient-hook up "$interface"21 cloud-init dhclient-hook up "$interface"
8}22}
923
10hook-rhel_restore(){24hook-rhel_restore(){
25 is_enabled || return 0
11 cloud-init dhclient-hook down "$interface"26 cloud-init dhclient-hook down "$interface"
12}27}

Subscribers

People subscribed via source and target branches