4967065a |
import os |
86dce272 |
import random |
a5a8bd39 |
import commons |
4967065a |
install_phase = commons.POST_INSTALL
enabled = True
|
a5a8bd39 |
def execute(config, root): |
4967065a |
hostname = config['hostname']
hostname_file = os.path.join(root, 'etc/hostname') |
0c250142 |
hosts_file = os.path.join(root, 'etc/hosts') |
4967065a |
|
0c250142 |
with open(hostname_file, 'wb') as outfile: |
a672bd24 |
outfile.write(hostname.encode()) |
4967065a |
|
a672bd24 |
pattern = r'(127\.0\.0\.1)(\s+)(localhost)\s*\Z'
replace = r'\1\2\3\n\1\2' + hostname
commons.replace_string_in_file(hosts_file, pattern, replace) |