summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/sources/DataSourceAzure.py13
-rw-r--r--cloudinit/sources/helpers/azure.py3
-rw-r--r--config/cloud.cfg6
-rw-r--r--doc/sources/azure/README.rst9
-rwxr-xr-xsystemd/cloud-init-generator5
-rwxr-xr-xtools/hook-dhclient25
-rwxr-xr-xtools/hook-network-manager23
-rwxr-xr-xtools/hook-rhel.sh15
8 files changed, 71 insertions, 28 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index a251fe01..dbc2bb68 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -54,6 +54,7 @@ BUILTIN_DS_CONFIG = {
'hostname_command': 'hostname',
},
'disk_aliases': {'ephemeral0': '/dev/sdb'},
+ 'dhclient_lease_file': '/var/lib/dhcp/dhclient.eth0.leases',
}
BUILTIN_CLOUD_CONFIG = {
@@ -106,8 +107,6 @@ def temporary_hostname(temp_hostname, cfg, hostname_command='hostname'):
class DataSourceAzureNet(sources.DataSource):
- FALLBACK_LEASE = '/var/lib/dhcp/dhclient.eth0.leases'
-
def __init__(self, sys_cfg, distro, paths):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
self.seed_dir = os.path.join(paths.seed_dir, 'azure')
@@ -116,8 +115,7 @@ class DataSourceAzureNet(sources.DataSource):
self.ds_cfg = util.mergemanydict([
util.get_cfg_by_path(sys_cfg, DS_CFG_PATH, {}),
BUILTIN_DS_CONFIG])
- self.dhclient_lease_file = self.paths.cfgs.get('dhclient_lease',
- self.FALLBACK_LEASE)
+ self.dhclient_lease_file = self.ds_cfg.get('dhclient_lease_file')
def __str__(self):
root = sources.DataSource.__str__(self)
@@ -126,6 +124,9 @@ class DataSourceAzureNet(sources.DataSource):
def get_metadata_from_agent(self):
temp_hostname = self.metadata.get('local-hostname')
hostname_command = self.ds_cfg['hostname_bounce']['hostname_command']
+ agent_cmd = self.ds_cfg['agent_command']
+ LOG.debug("Getting metadata via agent. hostname=%s cmd=%s",
+ temp_hostname, agent_cmd)
with temporary_hostname(temp_hostname, self.ds_cfg,
hostname_command=hostname_command) \
as previous_hostname:
@@ -141,7 +142,7 @@ class DataSourceAzureNet(sources.DataSource):
util.logexc(LOG, "handling set_hostname failed")
try:
- invoke_agent(self.ds_cfg['agent_command'])
+ invoke_agent(agent_cmd)
except util.ProcessExecutionError:
# claim the datasource even if the command failed
util.logexc(LOG, "agent command '%s' failed.",
@@ -234,13 +235,13 @@ class DataSourceAzureNet(sources.DataSource):
dhclient_lease_file)
else:
metadata_func = self.get_metadata_from_agent
+
try:
fabric_data = metadata_func()
except Exception as exc:
LOG.info("Error communicating with Azure fabric; assume we aren't"
" on Azure.", exc_info=True)
return False
-
self.metadata['instance-id'] = util.read_dmi_data('system-uuid')
self.metadata.update(fabric_data)
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
index 6e43440f..689ed4cc 100644
--- a/cloudinit/sources/helpers/azure.py
+++ b/cloudinit/sources/helpers/azure.py
@@ -190,7 +190,8 @@ class WALinuxAgentShim(object):
'</Health>'])
def __init__(self, fallback_lease_file=None):
- LOG.debug('WALinuxAgentShim instantiated...')
+ LOG.debug('WALinuxAgentShim instantiated, fallback_lease_file=%s',
+ fallback_lease_file)
self.dhcpoptions = None
self._endpoint = None
self.openssl_manager = None
diff --git a/config/cloud.cfg b/config/cloud.cfg
index 93ef3423..2d7fb473 100644
--- a/config/cloud.cfg
+++ b/config/cloud.cfg
@@ -98,7 +98,6 @@ system_info:
cloud_dir: /var/lib/cloud/
templates_dir: /etc/cloud/templates/
upstart_dir: /etc/init/
- dhclient_lease:
package_mirrors:
- arches: [i386, amd64]
failsafe:
@@ -115,8 +114,3 @@ system_info:
primary: http://ports.ubuntu.com/ubuntu-ports
security: http://ports.ubuntu.com/ubuntu-ports
ssh_svcname: ssh
-datasource:
- Azure:
- set_hostname: False
- agent_command: __builtin__
-
diff --git a/doc/sources/azure/README.rst b/doc/sources/azure/README.rst
index 48f3cc7a..ec7d9e84 100644
--- a/doc/sources/azure/README.rst
+++ b/doc/sources/azure/README.rst
@@ -30,13 +30,10 @@ datasource:
If those files are not available, the fallback is to check the leases file
for the endpoint server (again option 245).
-You can define the path to the lease file with the 'dhclient_lease' configuration
-value under system_info: and paths:. For example:
+You can define the path to the lease file with the 'dhclient_lease_file'
+configuration. The default value is /var/lib/dhcp/dhclient.eth0.leases.
- dhclient_lease: /var/lib/dhcp/dhclient.eth0.leases
-
-If no configuration value is provided, the dhclient_lease value will fallback to
-/var/lib/dhcp/dhclient.eth0.leases.
+ dhclient_lease_file: /var/lib/dhcp/dhclient.eth0.leases
walinuxagent
------------
diff --git a/systemd/cloud-init-generator b/systemd/cloud-init-generator
index 2d319695..fedb6309 100755
--- a/systemd/cloud-init-generator
+++ b/systemd/cloud-init-generator
@@ -6,6 +6,7 @@ DEBUG_LEVEL=1
LOG_D="/run/cloud-init"
ENABLE="enabled"
DISABLE="disabled"
+RUN_ENABLED_FILE="$LOG_D/$ENABLE"
CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
CLOUD_TARGET_NAME="cloud-init.target"
# lxc sets 'container', but lets make that explicitly a global
@@ -107,6 +108,7 @@ main() {
"ln $CLOUD_SYSTEM_TARGET $link_path"
fi
fi
+ : > "$RUN_ENABLED_FILE"
elif [ "$result" = "$DISABLE" ]; then
if [ -f "$link_path" ]; then
if rm -f "$link_path"; then
@@ -118,6 +120,9 @@ main() {
else
debug 1 "already disabled: no change needed [no $link_path]"
fi
+ if [ -e "$RUN_ENABLED_FILE" ]; then
+ rm -f "$RUN_ENABLED_FILE"
+ fi
else
debug 0 "unexpected result '$result'"
ret=3
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"
}