summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceEc2.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/sources/DataSourceEc2.py')
-rw-r--r--cloudinit/sources/DataSourceEc2.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
index 9c525d3d..32659848 100644
--- a/cloudinit/sources/DataSourceEc2.py
+++ b/cloudinit/sources/DataSourceEc2.py
@@ -11,6 +11,7 @@
import copy
import os
import time
+from typing import List
from cloudinit import dmi
from cloudinit import log as logging
@@ -18,7 +19,8 @@ from cloudinit import net, sources
from cloudinit import url_helper as uhelp
from cloudinit import util, warnings
from cloudinit.event import EventScope, EventType
-from cloudinit.net.dhcp import EphemeralDHCPv4, NoDHCPLeaseError
+from cloudinit.net.dhcp import NoDHCPLeaseError
+from cloudinit.net.ephemeral import EphemeralIPNetwork
from cloudinit.sources.helpers import ec2
LOG = logging.getLogger(__name__)
@@ -67,7 +69,11 @@ class DataSourceEc2(sources.DataSource):
# Priority ordered list of additional metadata versions which will be tried
# for extended metadata content. IPv6 support comes in 2016-09-02.
# Tags support comes in 2021-03-23.
- extended_metadata_versions = ["2021-03-23", "2018-09-24", "2016-09-02"]
+ extended_metadata_versions: List[str] = [
+ "2021-03-23",
+ "2018-09-24",
+ "2016-09-02",
+ ]
# Setup read_url parameters per get_url_params.
url_max_wait = 120
@@ -120,12 +126,16 @@ class DataSourceEc2(sources.DataSource):
LOG.debug("FreeBSD doesn't support running dhclient with -sf")
return False
try:
- with EphemeralDHCPv4(self.fallback_interface):
+ with EphemeralIPNetwork(
+ self.fallback_interface, ipv6=True
+ ) as netw:
+ state_msg = f" {netw.state_msg}" if netw.state_msg else ""
self._crawled_metadata = util.log_time(
logfunc=LOG.debug,
- msg="Crawl of metadata service",
+ msg=f"Crawl of metadata service{state_msg}",
func=self.crawl_metadata,
)
+
except NoDHCPLeaseError:
return False
else:
@@ -222,7 +232,7 @@ class DataSourceEc2(sources.DataSource):
else:
return self.metadata["instance-id"]
- def _maybe_fetch_api_token(self, mdurls, timeout=None, max_wait=None):
+ def _maybe_fetch_api_token(self, mdurls):
"""Get an API token for EC2 Instance Metadata Service.
On EC2. IMDS will always answer an API token, unless
@@ -472,12 +482,6 @@ class DataSourceEc2(sources.DataSource):
),
)
- # RELEASE_BLOCKER: xenial should drop the below if statement,
- # because the issue being addressed doesn't exist pre-netplan.
- # (This datasource doesn't implement check_instance_id() so the
- # datasource object is recreated every boot; this means we don't
- # need to modify update_events on cloud-init upgrade.)
-
# Non-VPC (aka Classic) Ec2 instances need to rewrite the
# network config file every boot due to MAC address change.
if self.is_classic_instance():