make the netplan file name and path depend (very slightly) on subiquity vs console-conf

This commit is contained in:
Michael Hudson-Doyle 2017-03-16 22:52:05 +13:00
parent 31d270c6c1
commit 3f425c9e05
2 changed files with 21 additions and 11 deletions

View File

@ -17,7 +17,6 @@ import copy
from functools import partial
import logging
import os
import queue
import random
import select
import socket
@ -213,8 +212,6 @@ class TaskSequence:
self.watcher.task_error(self.stage, info)
netplan_config_file_name = '00-snapd-config.yaml'
def sanitize_config(config):
"""Return a copy of config with passwords redacted."""
config = copy.deepcopy(config)
@ -321,12 +318,15 @@ class NetworkController(BaseController):
def __init__(self, common):
super().__init__(common)
if self.opts.dry_run:
import atexit, shutil, tempfile
self.root = tempfile.mkdtemp()
self.root = os.path.abspath(".subiquity")
self.tried_once = False
atexit.register(shutil.rmtree, self.root)
os.makedirs(os.path.join(self.root, 'etc/netplan'))
with open(os.path.join(self.root, 'etc/netplan', netplan_config_file_name), 'w') as fp:
netplan_path = self.netplan_path
netplan_dir = os.path.dirname(netplan_path)
if os.path.exists(netplan_dir):
import shutil
shutil.rmtree(netplan_dir)
os.makedirs(netplan_dir)
with open(netplan_path, 'w') as fp:
fp.write(default_netplan)
self.model = NetworkModel(self.root)
@ -357,10 +357,18 @@ class NetworkController(BaseController):
self.ui.set_footer(footer, 20)
self.ui.set_body(NetworkView(self.model, self))
@property
def netplan_path(self):
if self.opts.project == "subiquity":
netplan_config_file_name = '00-installer-config.yaml'
else:
netplan_config_file_name = '00-snapd-config.yaml'
return os.path.join(self.root, 'etc/netplan', netplan_config_file_name)
def network_finish(self, config):
log.debug("network config: \n%s", yaml.dump(sanitize_config(config), default_flow_style=False))
netplan_path = os.path.join(self.root, 'etc/netplan', netplan_config_file_name)
netplan_path = self.netplan_path
while True:
try:
tmppath = '%s.%s' % (netplan_path, random.randrange(0, 1000))
@ -371,7 +379,7 @@ class NetworkController(BaseController):
break
w = os.fdopen(fd, 'w')
with w:
w.write("# This is the network config written by 'console-conf'\n")
w.write("# This is the network config written by '{}'\n".format(self.opts.project))
w.write(yaml.dump(config))
os.rename(tmppath, netplan_path)
self.model.parse_netplan_configs()
@ -413,9 +421,9 @@ class NetworkController(BaseController):
self.ui.frame.body.show_network_error(stage, info)
def tasks_finished(self):
self.signal.emit_signal('network-config-written', self.netplan_path)
self.signal.emit_signal('next-screen')
@view
def set_default_v4_route(self):
self.ui.set_header("Default route")

View File

@ -56,6 +56,8 @@ class Application:
log.exception(err)
raise ApplicationError(err)
opts.project = self.project
self.common = {
"ui": ui,
"opts": opts,