cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #05883
[Merge] ~bewiwi-9/cloud-init:scaleway_add_sshkey_tag into cloud-init:master
bewiwi has proposed merging ~bewiwi-9/cloud-init:scaleway_add_sshkey_tag into cloud-init:master.
Commit message:
DataSourceScaleway add ssh keys provide in instance tag
This will enable ssh keys that are available in tag instance with format ^AUTHORIZED_KEY=(.+)$
Requested reviews:
cloud-init commiters (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~bewiwi-9/cloud-init/+git/cloud-init/+merge/361008
--
Your team cloud-init commiters is requested to review the proposed merge of ~bewiwi-9/cloud-init:scaleway_add_sshkey_tag into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceScaleway.py b/cloudinit/sources/DataSourceScaleway.py
index 9dc4ab2..b5e36f3 100644
--- a/cloudinit/sources/DataSourceScaleway.py
+++ b/cloudinit/sources/DataSourceScaleway.py
@@ -7,6 +7,7 @@
import json
import os
+import re
import socket
import time
@@ -253,7 +254,14 @@ class DataSourceScaleway(sources.DataSource):
return self.metadata['id']
def get_public_ssh_keys(self):
- return [key['key'] for key in self.metadata['ssh_public_keys']]
+ ssh_keys = [key['key'] for key in self.metadata['ssh_public_keys']]
+
+ for tag in self.metadata.get('tags'):
+ result = re.search('^AUTHORIZED_KEY=(.+)$', tag)
+ if result:
+ ssh_keys.append(result.group(1).replace("_", " "))
+
+ return ssh_keys
def get_hostname(self, fqdn=False, resolve_ip=False, metadata_only=False):
return self.metadata['hostname']
diff --git a/tests/unittests/test_datasource/test_scaleway.py b/tests/unittests/test_datasource/test_scaleway.py
index c2bc7a0..40b5708 100644
--- a/tests/unittests/test_datasource/test_scaleway.py
+++ b/tests/unittests/test_datasource/test_scaleway.py
@@ -49,6 +49,9 @@ class MetadataResponses(object):
FAKE_METADATA = {
'id': '00000000-0000-0000-0000-000000000000',
'hostname': 'scaleway.host',
+ 'tags': [
+ "AUTHORIZED_KEY=ssh-rsa_AAAAB3NzaC1yc2EAAAADAQABDDDDD",
+ ],
'ssh_public_keys': [{
'key': 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
'fingerprint': '2048 06:ae:... login (RSA)'
@@ -204,10 +207,11 @@ class TestDataSourceScaleway(HttprettyTestCase):
self.assertEqual(self.datasource.get_instance_id(),
MetadataResponses.FAKE_METADATA['id'])
- self.assertEqual(self.datasource.get_public_ssh_keys(), [
- elem['key'] for elem in
- MetadataResponses.FAKE_METADATA['ssh_public_keys']
- ])
+ self.assertEqual(self.datasource.get_public_ssh_keys().sort(), [
+ u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABCCCCC',
+ u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABDDDDD',
+ u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA',
+ ].sort())
self.assertEqual(self.datasource.get_hostname(),
MetadataResponses.FAKE_METADATA['hostname'])
self.assertEqual(self.datasource.get_userdata_raw(),