diff options
author | Chad Smith <chad.smith@canonical.com> | 2018-11-26 17:37:31 +0000 |
---|---|---|
committer | Server Team CI Bot <josh.powers+server-team-bot@canonical.com> | 2018-11-26 17:37:31 +0000 |
commit | ef0611a51a98a273cfa37b0daeb3e9d151888b88 (patch) | |
tree | 45711efe40a511d0168c4cb16de6665da1492997 /cloudinit/net/dhcp.py | |
parent | 8f812a15fde01173c0dd5b7e1a77b61031fd93e4 (diff) | |
download | vyos-cloud-init-ef0611a51a98a273cfa37b0daeb3e9d151888b88.tar.gz vyos-cloud-init-ef0611a51a98a273cfa37b0daeb3e9d151888b88.zip |
net: Ephemeral*Network: add connectivity check via URL
We add a new Optional parameter: connectivity_url
This is used in __enter__ to verify if a connection already exists.
If it does exist, no operations are performed.
Diffstat (limited to 'cloudinit/net/dhcp.py')
-rw-r--r-- | cloudinit/net/dhcp.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py index bdc5799f..0db991db 100644 --- a/cloudinit/net/dhcp.py +++ b/cloudinit/net/dhcp.py @@ -11,7 +11,8 @@ import re import signal from cloudinit.net import ( - EphemeralIPv4Network, find_fallback_nic, get_devicelist) + EphemeralIPv4Network, find_fallback_nic, get_devicelist, + has_url_connectivity) from cloudinit.net.network_state import mask_and_ipv4_to_bcast_addr as bcip from cloudinit import temp_utils from cloudinit import util @@ -37,13 +38,21 @@ class NoDHCPLeaseError(Exception): class EphemeralDHCPv4(object): - def __init__(self, iface=None): + def __init__(self, iface=None, connectivity_url=None): self.iface = iface self._ephipv4 = None self.lease = None + self.connectivity_url = connectivity_url def __enter__(self): - """Setup sandboxed dhcp context.""" + """Setup sandboxed dhcp context, unless connectivity_url can already be + reached.""" + if self.connectivity_url: + if has_url_connectivity(self.connectivity_url): + LOG.debug( + 'Skip ephemeral DHCP setup, instance has connectivity' + ' to %s', self.connectivity_url) + return return self.obtain_lease() def __exit__(self, excp_type, excp_value, excp_traceback): @@ -86,6 +95,8 @@ class EphemeralDHCPv4(object): kwargs = dict([(k, self.lease.get(v)) for k, v in nmap.items()]) if not kwargs['broadcast']: kwargs['broadcast'] = bcip(kwargs['prefix_or_mask'], kwargs['ip']) + if self.connectivity_url: + kwargs['connectivity_url'] = self.connectivity_url ephipv4 = EphemeralIPv4Network(**kwargs) ephipv4.__enter__() self._ephipv4 = ephipv4 |