summaryrefslogtreecommitdiff
path: root/cloudinit/sources/helpers/azure.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/sources/helpers/azure.py')
-rw-r--r--cloudinit/sources/helpers/azure.py47
1 files changed, 16 insertions, 31 deletions
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
index 281d733e..018cac6d 100644
--- a/cloudinit/sources/helpers/azure.py
+++ b/cloudinit/sources/helpers/azure.py
@@ -79,12 +79,6 @@ class GoalState(object):
'./Container/RoleInstanceList/RoleInstance/InstanceId')
@property
- def shared_config_xml(self):
- url = self._text_from_xpath('./Container/RoleInstanceList/RoleInstance'
- '/Configuration/SharedConfig')
- return self.http_client.get(url).contents
-
- @property
def certificates_xml(self):
if self._certificates_xml is None:
url = self._text_from_xpath(
@@ -172,19 +166,6 @@ class OpenSSLManager(object):
return keys
-def iid_from_shared_config_content(content):
- """
- find INSTANCE_ID in:
- <?xml version="1.0" encoding="utf-8"?>
- <SharedConfig version="1.0.0.0" goalStateIncarnation="1">
- <Deployment name="INSTANCE_ID" guid="{...}" incarnation="0">
- <Service name="..." guid="{00000000-0000-0000-0000-000000000000}"/>
- """
- root = ElementTree.fromstring(content)
- depnode = root.find('Deployment')
- return depnode.get('name')
-
-
class WALinuxAgentShim(object):
REPORT_READY_XML_TEMPLATE = '\n'.join([
@@ -216,6 +197,21 @@ class WALinuxAgentShim(object):
self.openssl_manager.clean_up()
@staticmethod
+ 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(':'):
+ if len(hex_pair) == 1:
+ hex_pair = '0' + hex_pair
+ hex_string += hex_pair
+ packed_bytes = struct.pack(
+ '>L', int(hex_string.replace(':', ''), 16))
+ else:
+ packed_bytes = unescaped_value.encode('utf-8')
+ 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')
@@ -225,16 +221,7 @@ class WALinuxAgentShim(object):
value = line.strip(' ').split(' ', 2)[-1].strip(';\n"')
if value is None:
raise Exception('No endpoint found in DHCP config.')
- if ':' in value:
- hex_string = ''
- for hex_pair in value.split(':'):
- if len(hex_pair) == 1:
- hex_pair = '0' + hex_pair
- hex_string += hex_pair
- value = struct.pack('>L', int(hex_string.replace(':', ''), 16))
- else:
- value = value.encode('utf-8')
- endpoint_ip_address = socket.inet_ntoa(value)
+ endpoint_ip_address = WALinuxAgentShim.get_ip_from_lease_value(value)
LOG.debug('Azure endpoint found at %s', endpoint_ip_address)
return endpoint_ip_address
@@ -263,8 +250,6 @@ class WALinuxAgentShim(object):
public_keys = self.openssl_manager.parse_certificates(
goal_state.certificates_xml)
data = {
- 'instance-id': iid_from_shared_config_content(
- goal_state.shared_config_xml),
'public-keys': public_keys,
}
self._report_ready(goal_state, http_client)