diff --git a/po/POTFILES.in b/po/POTFILES.in index 7fbee7d7..ff5af63f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -10,6 +10,7 @@ subiquity/client/controllers/network.py subiquity/client/controllers/progress.py subiquity/client/controllers/proxy.py subiquity/client/controllers/refresh.py +subiquity/client/controllers/ssh.py subiquity/client/controllers/welcome.py subiquity/client/controllers/zdev.py subiquity/client/__init__.py @@ -42,7 +43,6 @@ subiquity/controller.py subiquity/controllers/__init__.py subiquity/controllers/reboot.py subiquity/controllers/snaplist.py -subiquity/controllers/ssh.py subiquitycore/async_helpers.py subiquitycore/contextlib38.py subiquitycore/context.py @@ -131,6 +131,7 @@ subiquity/server/controllers/package.py subiquity/server/controllers/proxy.py subiquity/server/controllers/refresh.py subiquity/server/controllers/reporting.py +subiquity/server/controllers/ssh.py subiquity/server/controllers/userdata.py subiquity/server/controllers/zdev.py subiquity/server/dryrun.py diff --git a/subiquity/client/client.py b/subiquity/client/client.py index 9e7d1858..927a3edc 100644 --- a/subiquity/client/client.py +++ b/subiquity/client/client.py @@ -100,6 +100,7 @@ class SubiquityClient(TuiApplication): "Refresh", "Filesystem", "Identity", + "SSH", "Progress", ] diff --git a/subiquity/client/controllers/__init__.py b/subiquity/client/controllers/__init__.py index 3af77208..41492eb8 100644 --- a/subiquity/client/controllers/__init__.py +++ b/subiquity/client/controllers/__init__.py @@ -22,6 +22,7 @@ from .network import NetworkController from .progress import ProgressController from .proxy import ProxyController from .refresh import RefreshController +from .ssh import SSHController from .welcome import WelcomeController from .zdev import ZdevController @@ -35,6 +36,7 @@ __all__ = [ 'ProxyController', 'RefreshController', 'RepeatedController', + 'SSHController', 'WelcomeController', 'ZdevController', ] diff --git a/subiquity/controllers/ssh.py b/subiquity/client/controllers/ssh.py similarity index 74% rename from subiquity/controllers/ssh.py rename to subiquity/client/controllers/ssh.py index 476ffeb7..45915533 100644 --- a/subiquity/controllers/ssh.py +++ b/subiquity/client/controllers/ssh.py @@ -20,11 +20,11 @@ from subiquitycore.async_helpers import schedule_task from subiquitycore.context import with_context from subiquitycore import utils +from subiquity.client.controller import SubiquityTuiController from subiquity.common.types import SSHData -from subiquity.controller import SubiquityTuiController from subiquity.ui.views.ssh import SSHView -log = logging.getLogger('subiquity.controllers.ssh') +log = logging.getLogger('subiquity.client.controllers.ssh') class FetchSSHKeysFailure(Exception): @@ -35,18 +35,7 @@ class FetchSSHKeysFailure(Exception): class SSHController(SubiquityTuiController): - autoinstall_key = model_name = "ssh" - autoinstall_schema = { - 'type': 'object', - 'properties': { - 'install-server': {'type': 'boolean'}, - 'authorized-keys': { - 'type': 'array', - 'items': {'type': 'string'}, - }, - 'allow-pw': {'type': 'boolean'}, - }, - } + endpoint_name = 'ssh' def __init__(self, app): super().__init__(app) @@ -57,19 +46,8 @@ class SSHController(SubiquityTuiController): self.answers['ssh-import-id'] = identity_answers[ 'ssh-import-id'] - def load_autoinstall_data(self, data): - if data is None: - return - self.model.install_server = data.get('install-server', False) - self.model.authorized_keys = data.get( - 'authorized-keys', []) - self.model.pwauth = data.get( - 'allow-pw', not self.model.authorized_keys) - - def make_ui(self): - ssh_data = SSHData( - install_server=self.model.install_server, - allow_pw=self.model.pwauth) + async def make_ui(self): + ssh_data = await self.endpoint.GET() return SSHView(self, ssh_data) def run_answers(self): @@ -141,16 +119,6 @@ class SSHController(SubiquityTuiController): self._fetch_ssh_keys( ssh_import_id=ssh_import_id, ssh_data=ssh_data)) - def done(self, data: SSHData): - self.model.install_server = data.install_server - self.model.authorized_keys = data.authorized_keys - self.model.pwauth = data.allow_pw - self.configured() - self.app.next_screen() - - def make_autoinstall(self): - return { - 'install-server': self.model.install_server, - 'authorized-keys': self.model.authorized_keys, - 'allow-pw': self.model.pwauth, - } + def done(self, result): + log.debug("SSHController.done next_screen result=%s", result) + self.app.next_screen(self.endpoint.POST(result)) diff --git a/subiquity/common/apidef.py b/subiquity/common/apidef.py index fb86ff64..17da6052 100644 --- a/subiquity/common/apidef.py +++ b/subiquity/common/apidef.py @@ -32,6 +32,7 @@ from subiquity.common.types import ( InstallState, InstallStatus, RefreshStatus, + SSHData, StorageResponse, ZdevInfo, ) @@ -45,6 +46,7 @@ class API: proxy = simple_endpoint(str) mirror = simple_endpoint(str) identity = simple_endpoint(IdentityData) + ssh = simple_endpoint(SSHData) class meta: class status: diff --git a/subiquity/controllers/__init__.py b/subiquity/controllers/__init__.py index f1f5b454..8ecae971 100644 --- a/subiquity/controllers/__init__.py +++ b/subiquity/controllers/__init__.py @@ -15,10 +15,8 @@ from .reboot import RebootController from .snaplist import SnapListController -from .ssh import SSHController __all__ = [ 'RebootController', 'SnapListController', - 'SSHController', ] diff --git a/subiquity/server/controllers/__init__.py b/subiquity/server/controllers/__init__.py index 379928d0..f8492bd8 100644 --- a/subiquity/server/controllers/__init__.py +++ b/subiquity/server/controllers/__init__.py @@ -26,6 +26,7 @@ from .package import PackageController from .proxy import ProxyController from .refresh import RefreshController from .reporting import ReportingController +from .ssh import SSHController from .userdata import UserdataController from .zdev import ZdevController @@ -45,6 +46,7 @@ __all__ = [ 'ProxyController', 'RefreshController', 'ReportingController', + 'SSHController', 'UserdataController', 'ZdevController', ] diff --git a/subiquity/server/controllers/ssh.py b/subiquity/server/controllers/ssh.py new file mode 100644 index 00000000..8bff00a6 --- /dev/null +++ b/subiquity/server/controllers/ssh.py @@ -0,0 +1,66 @@ +# Copyright 2018 Canonical, Ltd. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import logging + +from subiquity.common.apidef import API +from subiquity.common.types import SSHData +from subiquity.server.controller import SubiquityController + +log = logging.getLogger('subiquity.server.controllers.ssh') + + +class SSHController(SubiquityController): + + endpoint = API.ssh + + autoinstall_key = model_name = "ssh" + autoinstall_schema = { + 'type': 'object', + 'properties': { + 'install-server': {'type': 'boolean'}, + 'authorized-keys': { + 'type': 'array', + 'items': {'type': 'string'}, + }, + 'allow-pw': {'type': 'boolean'}, + }, + } + + def load_autoinstall_data(self, data): + if data is None: + return + self.model.install_server = data.get('install-server', False) + self.model.authorized_keys = data.get('authorized-keys', []) + self.model.pwauth = data.get( + 'allow-pw', not self.model.authorized_keys) + + def make_autoinstall(self): + return { + 'install-server': self.model.install_server, + 'authorized-keys': self.model.authorized_keys, + 'allow-pw': self.model.pwauth, + } + + async def GET(self) -> SSHData: + return SSHData( + install_server=self.model.install_server, + allow_pw=self.model.pwauth) + + async def POST(self, data: SSHData): + self.model.install_server = data.install_server + self.model.authorized_keys = data.authorized_keys + self.model.pwauth = data.allow_pw + self.configured() diff --git a/subiquity/server/server.py b/subiquity/server/server.py index b50f0640..565e8df1 100644 --- a/subiquity/server/server.py +++ b/subiquity/server/server.py @@ -127,6 +127,7 @@ class SubiquityServer(Application): "Mirror", "Filesystem", "Identity", + "SSH", "Install", "Late", ]