~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to cloudinit/sources/DataSourceAzure.py

  • Committer: Scott Moser
  • Date: 2015-10-15 00:27:07 UTC
  • mfrom: (1147.2.1 cloud-init)
  • Revision ID: smoser@ubuntu.com-20151015002707-lplv0v7qzzga9li1
azure: support extracting SSH key values from ovf-env.xml

Azure has or will be offering shortly the ability to directly define the SSH
key value instead of a fingerprint in the ovf-env.xml file. This patch
favors defined SSH keys over the fingerprint method (LP: #1506244).

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
            wait_for = [shcfgxml]
149
149
 
150
150
            fp_files = []
 
151
            key_value = None
151
152
            for pk in self.cfg.get('_pubkeys', []):
152
 
                bname = str(pk['fingerprint'] + ".crt")
153
 
                fp_files += [os.path.join(ddir, bname)]
 
153
                if pk.get('value', None):
 
154
                    key_value = pk['value']
 
155
                    LOG.debug("ssh authentication: using value from fabric")
 
156
                else:
 
157
                    bname = str(pk['fingerprint'] + ".crt")
 
158
                    fp_files += [os.path.join(ddir, bname)]
 
159
                    LOG.debug("ssh authentication: using fingerprint from fabirc")
154
160
 
155
161
            missing = util.log_time(logfunc=LOG.debug, msg="waiting for files",
156
162
                                    func=wait_for_files,
166
172
                metadata['instance-id'] = iid_from_shared_config(shcfgxml)
167
173
            except ValueError as e:
168
174
                LOG.warn("failed to get instance id in %s: %s", shcfgxml, e)
169
 
        metadata['public-keys'] = pubkeys_from_crt_files(fp_files)
 
175
 
 
176
        metadata['public-keys'] = key_value or pubkeys_from_crt_files(fp_files)
170
177
        return metadata
171
178
 
172
179
    def get_data(self):
497
504
    for pk_node in pubkeys:
498
505
        if not pk_node.hasChildNodes():
499
506
            continue
500
 
        cur = {'fingerprint': "", 'path': ""}
 
507
 
 
508
        cur = {'fingerprint': "", 'path': "", 'value': ""}
501
509
        for child in pk_node.childNodes:
502
510
            if child.nodeType == text_node or not child.localName:
503
511
                continue