summaryrefslogtreecommitdiff
path: root/cloudinit/sources/__init__.py
diff options
context:
space:
mode:
authorRyan Harper <ryan.harper@canonical.com>2017-08-16 16:50:07 -0500
committerScott Moser <smoser@brickies.net>2017-08-30 21:10:08 -0400
commit7e76c57b590c7c2c13f7b1a2a8b5b7d4f2d18396 (patch)
treef0eb82212d46bc6373e104c864ab9810663a7417 /cloudinit/sources/__init__.py
parent300e4516f78dbb0a9533749aa84f7e366b023d04 (diff)
downloadvyos-cloud-init-7e76c57b590c7c2c13f7b1a2a8b5b7d4f2d18396.tar.gz
vyos-cloud-init-7e76c57b590c7c2c13f7b1a2a8b5b7d4f2d18396.zip
distro: allow distro to specify a default locale
Currently the cloud-init default locale (en_US.UTF-8) is set by the base datasource class. This patch allows a distro to overide the fallback value with one that's available in the distro but continues to respect an image which has preconfigured a locale. - Distro object now has a get_locale method which will return a preconfigure locale setting by checking the distros locale system configuration file. If not set or not present, return the default locale of en_US.UTF-8 which retains behavior of all previous cloud-init releases. - Apply locale now handles regenerating locales or system configuration files as needed. - Adjust apply_locale logic to skip locale-regen if the specified LANG value is C.UTF-8,C, or POSIX; they do not require regeneration. - Further add unittests to exercise the default paths for Ubuntu and non-ubuntu paths to validate they get the LANG expected.
Diffstat (limited to 'cloudinit/sources/__init__.py')
-rw-r--r--cloudinit/sources/__init__.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 952caf35..9a43fbee 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -44,6 +44,7 @@ class DataSourceNotFoundException(Exception):
class DataSource(object):
dsmode = DSMODE_NETWORK
+ default_locale = 'en_US.UTF-8'
def __init__(self, sys_cfg, distro, paths, ud_proc=None):
self.sys_cfg = sys_cfg
@@ -150,7 +151,13 @@ class DataSource(object):
return None
def get_locale(self):
- return 'en_US.UTF-8'
+ """Default locale is en_US.UTF-8, but allow distros to override"""
+ locale = self.default_locale
+ try:
+ locale = self.distro.get_locale()
+ except NotImplementedError:
+ pass
+ return locale
@property
def availability_zone(self):