summaryrefslogtreecommitdiff
path: root/cloudinit/sources/__init__.py
diff options
context:
space:
mode:
authorJames Falcon <therealfalcon@gmail.com>2021-08-13 15:34:16 -0500
committerGitHub <noreply@github.com>2021-08-13 15:34:16 -0500
commit65607405aed2fb5e7797bb181dc947025c10f346 (patch)
tree2b01bb7804682a5c16bcd2bfda81efb3c610bcf1 /cloudinit/sources/__init__.py
parentf516a7d37c1654addc02485e681b4358d7e7c0db (diff)
downloadvyos-cloud-init-65607405aed2fb5e7797bb181dc947025c10f346.tar.gz
vyos-cloud-init-65607405aed2fb5e7797bb181dc947025c10f346.zip
Only invoke hotplug socket when functionality is enabled (#952)
Alters hotplug hook to have a query mechanism checking if the functionality is enabled. This allows us to avoid using the hotplug socket and service when hotplug is disabled.
Diffstat (limited to 'cloudinit/sources/__init__.py')
-rw-r--r--cloudinit/sources/__init__.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index bf6bf139..cc7e1c3c 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -679,6 +679,16 @@ class DataSource(CloudInitPickleMixin, metaclass=abc.ABCMeta):
def get_package_mirror_info(self):
return self.distro.get_package_mirror_info(data_source=self)
+ def get_supported_events(self, source_event_types: List[EventType]):
+ supported_events = {} # type: Dict[EventScope, set]
+ for event in source_event_types:
+ for update_scope, update_events in self.supported_update_events.items(): # noqa: E501
+ if event in update_events:
+ if not supported_events.get(update_scope):
+ supported_events[update_scope] = set()
+ supported_events[update_scope].add(event)
+ return supported_events
+
def update_metadata_if_supported(
self, source_event_types: List[EventType]
) -> bool:
@@ -694,13 +704,7 @@ class DataSource(CloudInitPickleMixin, metaclass=abc.ABCMeta):
@return True if the datasource did successfully update cached metadata
due to source_event_type.
"""
- supported_events = {} # type: Dict[EventScope, set]
- for event in source_event_types:
- for update_scope, update_events in self.supported_update_events.items(): # noqa: E501
- if event in update_events:
- if not supported_events.get(update_scope):
- supported_events[update_scope] = set()
- supported_events[update_scope].add(event)
+ supported_events = self.get_supported_events(source_event_types)
for scope, matched_events in supported_events.items():
LOG.debug(
"Update datasource metadata and %s config due to events: %s",