Ubuntu Pastebin

Paste from daniel at Mon, 15 Jun 2015 11:36:02 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
Download as text