MCPcopy Create free account
hub / github.com/canonical/cloud-init / wait_on_network

Function wait_on_network

cloudinit/sources/DataSourceVMware.py:1209–1262  ·  view source on GitHub ↗
(metadata)

Source from the content-addressed store, hash-verified

1207
1208
1209def wait_on_network(metadata):
1210 # Determine whether we need to wait on the network coming online.
1211 wait_on_ipv4 = False
1212 wait_on_ipv6 = False
1213 if WAIT_ON_NETWORK in metadata:
1214 wait_on_network = metadata[WAIT_ON_NETWORK]
1215 if WAIT_ON_NETWORK_IPV4 in wait_on_network:
1216 wait_on_ipv4_val = wait_on_network[WAIT_ON_NETWORK_IPV4]
1217 if isinstance(wait_on_ipv4_val, bool):
1218 wait_on_ipv4 = wait_on_ipv4_val
1219 else:
1220 wait_on_ipv4 = util.translate_bool(wait_on_ipv4_val)
1221 if WAIT_ON_NETWORK_IPV6 in wait_on_network:
1222 wait_on_ipv6_val = wait_on_network[WAIT_ON_NETWORK_IPV6]
1223 if isinstance(wait_on_ipv6_val, bool):
1224 wait_on_ipv6 = wait_on_ipv6_val
1225 else:
1226 wait_on_ipv6 = util.translate_bool(wait_on_ipv6_val)
1227
1228 # Get information about the host.
1229 host_info, ipv4_ready, ipv6_ready = None, False, False
1230 while host_info is None:
1231 # This loop + sleep results in two logs every second while waiting
1232 # for either ipv4 or ipv6 up. Do we really need to log each iteration
1233 # or can we log once and log on successful exit?
1234 host_info = get_host_info()
1235
1236 network = host_info.get("network") or {}
1237 interfaces = network.get("interfaces") or {}
1238 by_ipv4 = interfaces.get("by-ipv4") or {}
1239 by_ipv6 = interfaces.get("by-ipv6") or {}
1240
1241 if wait_on_ipv4:
1242 ipv4_ready = len(by_ipv4) > 0 if by_ipv4 else False
1243 if not ipv4_ready:
1244 host_info = None
1245
1246 if wait_on_ipv6:
1247 ipv6_ready = len(by_ipv6) > 0 if by_ipv6 else False
1248 if not ipv6_ready:
1249 host_info = None
1250
1251 if host_info is None:
1252 LOG.debug(
1253 "waiting on network: wait4=%s, ready4=%s, wait6=%s, ready6=%s",
1254 wait_on_ipv4,
1255 ipv4_ready,
1256 wait_on_ipv6,
1257 ipv6_ready,
1258 )
1259 time.sleep(1)
1260
1261 LOG.debug("waiting on network complete")
1262 return host_info
1263
1264
1265def main():

Callers 2

setupMethod · 0.85
mainFunction · 0.85

Calls 2

get_host_infoFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected