~oddbloke/cloud-init/lp1506187

« back to all changes in this revision

Viewing changes to cloudinit/sources/helpers/azure.py

  • Committer: Daniel Watkins
  • Date: 2015-10-30 16:26:31 UTC
  • Revision ID: daniel.watkins@canonical.com-20151030162631-xmsz2bdgf25zb6d1
Use DMI data to find Azure instance IDs.

This replaces the use of SharedConfig.xml in both the walinuxagent case,
and the case where we communicate with the Azure fabric ourselves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
            './Container/RoleInstanceList/RoleInstance/InstanceId')
80
80
 
81
81
    @property
82
 
    def shared_config_xml(self):
83
 
        url = self._text_from_xpath('./Container/RoleInstanceList/RoleInstance'
84
 
                                    '/Configuration/SharedConfig')
85
 
        return self.http_client.get(url).contents
86
 
 
87
 
    @property
88
82
    def certificates_xml(self):
89
83
        if self._certificates_xml is None:
90
84
            url = self._text_from_xpath(
172
166
        return keys
173
167
 
174
168
 
175
 
def iid_from_shared_config_content(content):
176
 
    """
177
 
    find INSTANCE_ID in:
178
 
    <?xml version="1.0" encoding="utf-8"?>
179
 
    <SharedConfig version="1.0.0.0" goalStateIncarnation="1">
180
 
    <Deployment name="INSTANCE_ID" guid="{...}" incarnation="0">
181
 
        <Service name="..." guid="{00000000-0000-0000-0000-000000000000}"/>
182
 
    """
183
 
    root = ElementTree.fromstring(content)
184
 
    depnode = root.find('Deployment')
185
 
    return depnode.get('name')
186
 
 
187
 
 
188
169
class WALinuxAgentShim(object):
189
170
 
190
171
    REPORT_READY_XML_TEMPLATE = '\n'.join([
263
244
            public_keys = self.openssl_manager.parse_certificates(
264
245
                goal_state.certificates_xml)
265
246
        data = {
266
 
            'instance-id': iid_from_shared_config_content(
267
 
                goal_state.shared_config_xml),
268
247
            'public-keys': public_keys,
269
248
        }
270
249
        self._report_ready(goal_state, http_client)