diff --git a/cloudinit/osys/windows/general.py b/cloudinit/osys/windows/general.py
index 578b996..f1b7bf2 100644
--- a/cloudinit/osys/windows/general.py
+++ b/cloudinit/osys/windows/general.py
@@ -9,7 +9,6 @@ import ctypes
from cloudinit import exceptions
from cloudinit.osys import general
-from cloudinit.osys.windows.util import kernel32
class General(general.General):
@@ -18,6 +17,7 @@ class General(general.General):
@staticmethod
def check_os_version(major, minor, build=0):
"""Check if this OS version is equal or higher than (major, minor)"""
+ from cloudinit.osys.windows.util import kernel32
version_info = kernel32.Win32_OSVERSIONINFOEX_W()
version_info.dwOSVersionInfoSize = ctypes.sizeof(
diff --git a/cloudinit/osys/windows/network.py b/cloudinit/osys/windows/network.py
index 9e980a3..8333b42 100644
--- a/cloudinit/osys/windows/network.py
+++ b/cloudinit/osys/windows/network.py
@@ -7,15 +7,18 @@
import contextlib
import ctypes
-from ctypes import wintypes
import logging
import subprocess
from cloudinit import exceptions
from cloudinit.osys import network
-from cloudinit.osys.windows.util import iphlpapi
-from cloudinit.osys.windows.util import kernel32
-from cloudinit.osys.windows.util import ws2_32
+
+
+def _do_imports():
+ from cloudinit.osys.windows.util import iphlpapi
+ from cloudinit.osys.windows.util import kernel32
+ from cloudinit.osys.windows.util import ws2_32
+ return iphlpapi, kernel32, ws2_32
MIB_IPPROTO_NETMGMT = 3
@@ -30,6 +33,7 @@ LOG = logging.getLogger(__file__)
def _heap_alloc(heap, size):
+ _, kernel32, _ = _do_imports()
table_mem = kernel32.HeapAlloc(heap, 0, ctypes.c_size_t(size.value))
if not table_mem:
raise exceptions.CloudInitError(
@@ -43,6 +47,8 @@ class Network(network.Network):
@staticmethod
@contextlib.contextmanager
def _get_forward_table():
+ from ctypes import wintypes
+ iphlpapi, kernel32, _ = _do_imports()
heap = kernel32.GetProcessHeap()
forward_table_size = ctypes.sizeof(iphlpapi.Win32_MIB_IPFORWARDTABLE)
size = wintypes.ULONG(forward_table_size)
@@ -73,6 +79,7 @@ class Network(network.Network):
def routes(self):
"""Get a collection of the available routes."""
+ iphlpapi, _, ws2_32 = _do_imports()
routing_table = []
with self._get_forward_table() as p_forward_table:
forward_table = p_forward_table.contents
diff --git a/setup.cfg b/setup.cfg
index c48cd53..d0929e9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -38,5 +38,5 @@ build-dir = doc/build
[pbr]
autodoc_index_modules = 1
autodoc_exclude_modules =
- cloudinit.osys.windows.*
+ cloudinit.osys.windows.util.*
warnerrors = 1