summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authorJoshua Hügli <joshua@trafficteam.ch>2019-11-12 13:42:41 -0700
committerChad Smith <chad.smith@canonical.com>2019-11-12 13:42:41 -0700
commit9662a8791e53bac40a3a37aa3f5bee3076f7d447 (patch)
tree59c225054eefdc381019575c1ed486b4f6065488 /cloudinit/sources
parent5578305e93b445101ae9f7aa7007657f9a79704b (diff)
downloadvyos-cloud-init-9662a8791e53bac40a3a37aa3f5bee3076f7d447.tar.gz
vyos-cloud-init-9662a8791e53bac40a3a37aa3f5bee3076f7d447.zip
add data-server dns entry as new metadata server detection
Diffstat (limited to 'cloudinit/sources')
-rw-r--r--cloudinit/sources/DataSourceCloudStack.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/cloudinit/sources/DataSourceCloudStack.py b/cloudinit/sources/DataSourceCloudStack.py
index f185dc71..e333cb50 100644
--- a/cloudinit/sources/DataSourceCloudStack.py
+++ b/cloudinit/sources/DataSourceCloudStack.py
@@ -13,7 +13,7 @@
# This file is part of cloud-init. See LICENSE file for license information.
import os
-from socket import inet_ntoa
+from socket import inet_ntoa, getaddrinfo, gaierror
from struct import pack
import time
@@ -156,6 +156,17 @@ class DataSourceCloudStack(sources.DataSource):
return self.metadata['availability-zone']
+def get_data_server():
+ # Returns the metadataserver from dns
+ try:
+ addrinfo = getaddrinfo("data-server.", 80)
+ except gaierror:
+ LOG.debug("DNS Entry data-server not found")
+ return None
+ else:
+ return addrinfo[0][4][0] # return IP
+
+
def get_default_gateway():
# Returns the default gateway ip address in the dotted format.
lines = util.load_file("/proc/net/route").splitlines()
@@ -218,7 +229,14 @@ def get_vr_address():
# If no virtual router is detected, fallback on default gateway.
# See http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.8/virtual_machines/user-data.html # noqa
- # Try networkd first...
+ # Try data-server DNS entry first
+ latest_address = get_data_server()
+ if latest_address:
+ LOG.debug("Found metadata server '%s' via data-server DNS entry",
+ latest_address)
+ return latest_address
+
+ # Try networkd second...
latest_address = dhcp.networkd_get_option_from_leases('SERVER_ADDRESS')
if latest_address:
LOG.debug("Found SERVER_ADDRESS '%s' via networkd_leases",