summaryrefslogtreecommitdiff
path: root/cloudinit/sources/helpers/azure.py
diff options
context:
space:
mode:
authorDaniel Watkins <daniel.watkins@canonical.com>2015-10-09 14:01:11 +0100
committerDaniel Watkins <daniel.watkins@canonical.com>2015-10-09 14:01:11 +0100
commitd78ea2f8191847242b639f23fe085a5dd8b36014 (patch)
tree2db5493f23bfe16f30ae2545882f93b7a24181b9 /cloudinit/sources/helpers/azure.py
parenta9f5d20bc55abc5ff12a5ce1cec1125173f11c7b (diff)
downloadvyos-cloud-init-d78ea2f8191847242b639f23fe085a5dd8b36014.tar.gz
vyos-cloud-init-d78ea2f8191847242b639f23fe085a5dd8b36014.zip
Refactor WALinuxAgentShim.find_endpoint to use a helper method for IP address unpacking.
Diffstat (limited to 'cloudinit/sources/helpers/azure.py')
-rw-r--r--cloudinit/sources/helpers/azure.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
index 21b4cd21..fd08be16 100644
--- a/cloudinit/sources/helpers/azure.py
+++ b/cloudinit/sources/helpers/azure.py
@@ -216,16 +216,8 @@ class WALinuxAgentShim(object):
self.openssl_manager.clean_up()
@staticmethod
- def find_endpoint():
- LOG.debug('Finding Azure endpoint...')
- content = util.load_file('/var/lib/dhcp/dhclient.eth0.leases')
- value = None
- for line in content.splitlines():
- if 'unknown-245' in line:
- value = line.strip(' ').split(' ', 2)[-1].strip(';\n"')
- if value is None:
- raise Exception('No endpoint found in DHCP config.')
- unescaped_value = value.replace('\\', '')
+ def get_ip_from_lease_value(lease_value):
+ unescaped_value = lease_value.replace('\\', '')
if len(unescaped_value) > 4:
hex_string = ''
for hex_pair in unescaped_value.split(':'):
@@ -236,7 +228,19 @@ class WALinuxAgentShim(object):
'>L', int(hex_string.replace(':', ''), 16))
else:
packed_bytes = unescaped_value.encode('utf-8')
- endpoint_ip_address = socket.inet_ntoa(packed_bytes)
+ return socket.inet_ntoa(packed_bytes)
+
+ @staticmethod
+ def find_endpoint():
+ LOG.debug('Finding Azure endpoint...')
+ content = util.load_file('/var/lib/dhcp/dhclient.eth0.leases')
+ value = None
+ for line in content.splitlines():
+ if 'unknown-245' in line:
+ value = line.strip(' ').split(' ', 2)[-1].strip(';\n"')
+ if value is None:
+ raise Exception('No endpoint found in DHCP config.')
+ endpoint_ip_address = WALinuxAgentShim.get_ip_from_lease_value(value)
LOG.debug('Azure endpoint found at %s', endpoint_ip_address)
return endpoint_ip_address