summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-01-15 10:23:47 -0500
committerScott Moser <smoser@ubuntu.com>2015-01-15 10:23:47 -0500
commita61ec07ed02d725a004ec17b4ae5257c89d67987 (patch)
tree8008a8901b3d01d0a822358cae4a0dabae39cfda
parent62e9e73e3ed8467fc4d4d95f76ed0443c50f176c (diff)
parentbd0c29c2f298ad060bba88ddbb4d2d11ab07cafe (diff)
downloadvyos-cloud-init-a61ec07ed02d725a004ec17b4ae5257c89d67987.tar.gz
vyos-cloud-init-a61ec07ed02d725a004ec17b4ae5257c89d67987.zip
Use the GCE short hostname.
Google Compute Engine fqdn hostnames are usually longer than 64 characters. This causes issues with many tools (often Java based). Note that per gethostname(2): POSIX.1-2001 guarantees that "Host names (not including the terminating null byte) are limed to HOST_NAME_MAX bytes". On Linux, HOST_NAME_MAX is defined with the value 64. LP: #1383794
-rw-r--r--ChangeLog1
-rw-r--r--cloudinit/sources/DataSourceGCE.py3
-rw-r--r--tests/unittests/test_datasource/test_gce.py7
3 files changed, 7 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index bd209fce..400e51f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@
types
- Update to use newer/better OMNIBUS_URL for chef module
- GCE: Allow base64 encoded user-data (LP: #1404311) [Wayne Witzell III]
+ - GCE: use short hostname rather than fqdn (LP: #1383794) [Ben Howard]
0.7.6:
- open 0.7.6
- Enable vendordata on CloudSigma datasource (LP: #1303986)
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py
index 92e5a28e..f877b3d1 100644
--- a/cloudinit/sources/DataSourceGCE.py
+++ b/cloudinit/sources/DataSourceGCE.py
@@ -124,7 +124,8 @@ class DataSourceGCE(sources.DataSource):
return self.metadata['public-keys']
def get_hostname(self, fqdn=False, _resolve_ip=False):
- return self.metadata['local-hostname']
+ # GCE has long FDQN's and has asked for short hostnames
+ return self.metadata['local-hostname'].split('.')[0]
def get_userdata_raw(self):
return self.metadata['user-data']
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index 89251b0e..06050bb1 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -99,7 +99,8 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
body=_new_request_callback())
self.ds.get_data()
- self.assertEqual(GCE_META.get('instance/hostname'),
+ shostname = GCE_META.get('instance/hostname').split('.')[0]
+ self.assertEqual(shostname,
self.ds.get_hostname())
self.assertEqual(GCE_META.get('instance/id'),
@@ -126,8 +127,8 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
self.assertEqual(GCE_META_PARTIAL.get('instance/id'),
self.ds.get_instance_id())
- self.assertEqual(GCE_META_PARTIAL.get('instance/hostname'),
- self.ds.get_hostname())
+ shostname = GCE_META_PARTIAL.get('instance/hostname').split('.')[0]
+ self.assertEqual(shostname, self.ds.get_hostname())
@httpretty.activate
def test_metadata_encoding(self):