Merge pull request #445 from mwhudson/hostname-once

configure hostname directly
This commit is contained in:
Dimitri John Ledkov 2019-04-09 10:46:38 +01:00 committed by GitHub
commit 2edf1497dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 1 deletions

View File

@ -44,6 +44,18 @@ def setup_yaml():
setup_yaml() setup_yaml()
HOSTS_CONTENT = """\
127.0.0.1 localhost
127.0.1.1 {hostname}
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
"""
class SubiquityModel: class SubiquityModel:
"""The overall model for subiquity.""" """The overall model for subiquity."""
@ -81,6 +93,7 @@ class SubiquityModel:
def _cloud_init_config(self): def _cloud_init_config(self):
user = self.identity.user user = self.identity.user
hostname = self.identity.hostname.strip()
users_and_groups_path = ( users_and_groups_path = (
os.path.join(os.environ.get("SNAP", "."), os.path.join(os.environ.get("SNAP", "."),
"users-and-groups")) "users-and-groups"))
@ -105,10 +118,23 @@ class SubiquityModel:
'growpart': { 'growpart': {
'mode': 'off', 'mode': 'off',
}, },
'hostname': self.identity.hostname,
'locale': self.locale.selected_language + '.UTF-8', 'locale': self.locale.selected_language + '.UTF-8',
'resize_rootfs': False, 'resize_rootfs': False,
'users': [user_info], 'users': [user_info],
'write_files': [
{
'path': '/etc/hostname',
'content': hostname + '\n',
'permissions': 0o644,
'owner': 'root:root',
},
{
'path': '/etc/hosts',
'content': HOSTS_CONTENT.format(hostname=hostname),
'permissions': 0o644,
'owner': 'root:root',
},
],
} }
if self.ssh.install_server: if self.ssh.install_server:
config['ssh_pwauth'] = self.ssh.pwauth config['ssh_pwauth'] = self.ssh.pwauth