move ssh controller to new world

This commit is contained in:
Michael Hudson-Doyle 2020-10-12 13:15:44 +13:00
parent bd69f2a746
commit 4ab676d984
9 changed files with 84 additions and 43 deletions

View File

@ -10,6 +10,7 @@ subiquity/client/controllers/network.py
subiquity/client/controllers/progress.py subiquity/client/controllers/progress.py
subiquity/client/controllers/proxy.py subiquity/client/controllers/proxy.py
subiquity/client/controllers/refresh.py subiquity/client/controllers/refresh.py
subiquity/client/controllers/ssh.py
subiquity/client/controllers/welcome.py subiquity/client/controllers/welcome.py
subiquity/client/controllers/zdev.py subiquity/client/controllers/zdev.py
subiquity/client/__init__.py subiquity/client/__init__.py
@ -42,7 +43,6 @@ subiquity/controller.py
subiquity/controllers/__init__.py subiquity/controllers/__init__.py
subiquity/controllers/reboot.py subiquity/controllers/reboot.py
subiquity/controllers/snaplist.py subiquity/controllers/snaplist.py
subiquity/controllers/ssh.py
subiquitycore/async_helpers.py subiquitycore/async_helpers.py
subiquitycore/contextlib38.py subiquitycore/contextlib38.py
subiquitycore/context.py subiquitycore/context.py
@ -131,6 +131,7 @@ subiquity/server/controllers/package.py
subiquity/server/controllers/proxy.py subiquity/server/controllers/proxy.py
subiquity/server/controllers/refresh.py subiquity/server/controllers/refresh.py
subiquity/server/controllers/reporting.py subiquity/server/controllers/reporting.py
subiquity/server/controllers/ssh.py
subiquity/server/controllers/userdata.py subiquity/server/controllers/userdata.py
subiquity/server/controllers/zdev.py subiquity/server/controllers/zdev.py
subiquity/server/dryrun.py subiquity/server/dryrun.py

View File

@ -100,6 +100,7 @@ class SubiquityClient(TuiApplication):
"Refresh", "Refresh",
"Filesystem", "Filesystem",
"Identity", "Identity",
"SSH",
"Progress", "Progress",
] ]

View File

@ -22,6 +22,7 @@ from .network import NetworkController
from .progress import ProgressController from .progress import ProgressController
from .proxy import ProxyController from .proxy import ProxyController
from .refresh import RefreshController from .refresh import RefreshController
from .ssh import SSHController
from .welcome import WelcomeController from .welcome import WelcomeController
from .zdev import ZdevController from .zdev import ZdevController
@ -35,6 +36,7 @@ __all__ = [
'ProxyController', 'ProxyController',
'RefreshController', 'RefreshController',
'RepeatedController', 'RepeatedController',
'SSHController',
'WelcomeController', 'WelcomeController',
'ZdevController', 'ZdevController',
] ]

View File

@ -20,11 +20,11 @@ from subiquitycore.async_helpers import schedule_task
from subiquitycore.context import with_context from subiquitycore.context import with_context
from subiquitycore import utils from subiquitycore import utils
from subiquity.client.controller import SubiquityTuiController
from subiquity.common.types import SSHData from subiquity.common.types import SSHData
from subiquity.controller import SubiquityTuiController
from subiquity.ui.views.ssh import SSHView from subiquity.ui.views.ssh import SSHView
log = logging.getLogger('subiquity.controllers.ssh') log = logging.getLogger('subiquity.client.controllers.ssh')
class FetchSSHKeysFailure(Exception): class FetchSSHKeysFailure(Exception):
@ -35,18 +35,7 @@ class FetchSSHKeysFailure(Exception):
class SSHController(SubiquityTuiController): class SSHController(SubiquityTuiController):
autoinstall_key = model_name = "ssh" endpoint_name = 'ssh'
autoinstall_schema = {
'type': 'object',
'properties': {
'install-server': {'type': 'boolean'},
'authorized-keys': {
'type': 'array',
'items': {'type': 'string'},
},
'allow-pw': {'type': 'boolean'},
},
}
def __init__(self, app): def __init__(self, app):
super().__init__(app) super().__init__(app)
@ -57,19 +46,8 @@ class SSHController(SubiquityTuiController):
self.answers['ssh-import-id'] = identity_answers[ self.answers['ssh-import-id'] = identity_answers[
'ssh-import-id'] 'ssh-import-id']
def load_autoinstall_data(self, data): async def make_ui(self):
if data is None: ssh_data = await self.endpoint.GET()
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)
return SSHView(self, ssh_data) return SSHView(self, ssh_data)
def run_answers(self): def run_answers(self):
@ -141,16 +119,6 @@ class SSHController(SubiquityTuiController):
self._fetch_ssh_keys( self._fetch_ssh_keys(
ssh_import_id=ssh_import_id, ssh_data=ssh_data)) ssh_import_id=ssh_import_id, ssh_data=ssh_data))
def done(self, data: SSHData): def done(self, result):
self.model.install_server = data.install_server log.debug("SSHController.done next_screen result=%s", result)
self.model.authorized_keys = data.authorized_keys self.app.next_screen(self.endpoint.POST(result))
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,
}

View File

@ -32,6 +32,7 @@ from subiquity.common.types import (
InstallState, InstallState,
InstallStatus, InstallStatus,
RefreshStatus, RefreshStatus,
SSHData,
StorageResponse, StorageResponse,
ZdevInfo, ZdevInfo,
) )
@ -45,6 +46,7 @@ class API:
proxy = simple_endpoint(str) proxy = simple_endpoint(str)
mirror = simple_endpoint(str) mirror = simple_endpoint(str)
identity = simple_endpoint(IdentityData) identity = simple_endpoint(IdentityData)
ssh = simple_endpoint(SSHData)
class meta: class meta:
class status: class status:

View File

@ -15,10 +15,8 @@
from .reboot import RebootController from .reboot import RebootController
from .snaplist import SnapListController from .snaplist import SnapListController
from .ssh import SSHController
__all__ = [ __all__ = [
'RebootController', 'RebootController',
'SnapListController', 'SnapListController',
'SSHController',
] ]

View File

@ -26,6 +26,7 @@ from .package import PackageController
from .proxy import ProxyController from .proxy import ProxyController
from .refresh import RefreshController from .refresh import RefreshController
from .reporting import ReportingController from .reporting import ReportingController
from .ssh import SSHController
from .userdata import UserdataController from .userdata import UserdataController
from .zdev import ZdevController from .zdev import ZdevController
@ -45,6 +46,7 @@ __all__ = [
'ProxyController', 'ProxyController',
'RefreshController', 'RefreshController',
'ReportingController', 'ReportingController',
'SSHController',
'UserdataController', 'UserdataController',
'ZdevController', 'ZdevController',
] ]

View File

@ -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 <http://www.gnu.org/licenses/>.
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()

View File

@ -127,6 +127,7 @@ class SubiquityServer(Application):
"Mirror", "Mirror",
"Filesystem", "Filesystem",
"Identity", "Identity",
"SSH",
"Install", "Install",
"Late", "Late",
] ]