summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorasakkurr <asakkurr@microsoft.com>2018-10-31 20:19:15 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-10-31 20:19:15 +0000
commit907395104bb5850d221924365102cc5ab0eca2f1 (patch)
tree0ce9d2eca6abde46bc75acb62e970ab52c751217 /cloudinit
parentd74d3f0ff5c8d453f626b113f4e6065322f822fa (diff)
downloadvyos-cloud-init-907395104bb5850d221924365102cc5ab0eca2f1.tar.gz
vyos-cloud-init-907395104bb5850d221924365102cc5ab0eca2f1.zip
azure: report ready to fabric after reprovision and reduce logging
When reusing a preprovisioned VM, report ready to Azure fabric as soon as we get the reprovision data and the goal state so that we are not delayed by the cloud-init stage switch, saving 2-3 seconds. Also reduce logging when polling IMDS for reprovision data. LP: #1799594
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceAzure.py15
-rw-r--r--cloudinit/url_helper.py17
2 files changed, 23 insertions, 9 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index d0358e96..8642915e 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -267,6 +267,7 @@ class DataSourceAzure(sources.DataSource):
dsname = 'Azure'
_negotiated = False
_metadata_imds = sources.UNSET
+ lease_info = None
def __init__(self, sys_cfg, distro, paths):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
@@ -406,8 +407,10 @@ class DataSourceAzure(sources.DataSource):
LOG.warning("%s was not mountable", cdev)
continue
+ should_report_ready_after_reprovision = False
if reprovision or self._should_reprovision(ret):
ret = self._reprovision()
+ should_report_ready_after_reprovision = True
imds_md = get_metadata_from_imds(
self.fallback_interface, retries=3)
(md, userdata_raw, cfg, files) = ret
@@ -434,6 +437,11 @@ class DataSourceAzure(sources.DataSource):
crawled_data['metadata']['random_seed'] = seed
crawled_data['metadata']['instance-id'] = util.read_dmi_data(
'system-uuid')
+
+ if should_report_ready_after_reprovision:
+ LOG.info("Reporting ready to Azure after getting ReprovisionData")
+ self._report_ready(lease=self.lease_info)
+
return crawled_data
def _is_platform_viable(self):
@@ -522,6 +530,7 @@ class DataSourceAzure(sources.DataSource):
while True:
try:
with EphemeralDHCPv4() as lease:
+ self.lease_info = lease
if report_ready:
path = REPORTED_READY_MARKER_FILE
LOG.info(
@@ -531,13 +540,13 @@ class DataSourceAzure(sources.DataSource):
self._report_ready(lease=lease)
report_ready = False
return readurl(url, timeout=1, headers=headers,
- exception_cb=exc_cb, infinite=True).contents
+ exception_cb=exc_cb, infinite=True,
+ log_req_resp=False).contents
except UrlError:
pass
def _report_ready(self, lease):
- """Tells the fabric provisioning has completed
- before we go into our polling loop."""
+ """Tells the fabric provisioning has completed """
try:
get_metadata_from_fabric(None, lease['unknown-245'])
except Exception:
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index 8067979e..cf57dbd5 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -199,7 +199,7 @@ def _get_ssl_args(url, ssl_details):
def readurl(url, data=None, timeout=None, retries=0, sec_between=1,
headers=None, headers_cb=None, ssl_details=None,
check_status=True, allow_redirects=True, exception_cb=None,
- session=None, infinite=False):
+ session=None, infinite=False, log_req_resp=True):
url = _cleanurl(url)
req_args = {
'url': url,
@@ -256,9 +256,11 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1,
continue
filtered_req_args[k] = v
try:
- LOG.debug("[%s/%s] open '%s' with %s configuration", i,
- "infinite" if infinite else manual_tries, url,
- filtered_req_args)
+
+ if log_req_resp:
+ LOG.debug("[%s/%s] open '%s' with %s configuration", i,
+ "infinite" if infinite else manual_tries, url,
+ filtered_req_args)
if session is None:
session = requests.Session()
@@ -294,8 +296,11 @@ def readurl(url, data=None, timeout=None, retries=0, sec_between=1,
break
if (infinite and sec_between > 0) or \
(i + 1 < manual_tries and sec_between > 0):
- LOG.debug("Please wait %s seconds while we wait to try again",
- sec_between)
+
+ if log_req_resp:
+ LOG.debug(
+ "Please wait %s seconds while we wait to try again",
+ sec_between)
time.sleep(sec_between)
if excps:
raise excps[-1]