pubsub: split channels into two classes

This commit is contained in:
Dan Bungert 2021-09-08 17:33:15 -06:00 committed by Dan Bungert
parent bc8fda47f6
commit a005418cde
9 changed files with 31 additions and 26 deletions

View File

@ -25,6 +25,7 @@ from typing import Dict, List, Optional, Union
import attr
from subiquitycore.models.network import NetDevInfo
from subiquitycore.pubsub import CoreChannels
class ErrorReportState(enum.Enum):
@ -337,6 +338,12 @@ class ShutdownMode(enum.Enum):
POWEROFF = enum.auto()
class InstallerChannels(CoreChannels):
NETWORK_PROXY_SET = 'network-proxy-set'
SNAPD_NETWORK_CHANGE = 'snapd-network-change'
GEOIP = 'geoip'
@attr.s(auto_attribs=True)
class WSLConfigurationBase:
custom_path: str = attr.ib(default='/mnt/')

View File

@ -19,9 +19,9 @@ import logging
from curtin.config import merge_config
from subiquitycore.context import with_context
from subiquitycore.pubsub import MessageChannels
from subiquity.common.apidef import API
from subiquity.common.types import InstallerChannels
from subiquity.server.controller import SubiquityController
log = logging.getLogger('subiquity.server.controllers.mirror')
@ -46,7 +46,7 @@ class MirrorController(SubiquityController):
def __init__(self, app):
super().__init__(app)
self.geoip_enabled = True
self.app.hub.subscribe(MessageChannels.GEOIP, self.on_geoip)
self.app.hub.subscribe(InstallerChannels.GEOIP, self.on_geoip)
self.cc_event = asyncio.Event()
def load_autoinstall_data(self, data):

View File

@ -17,9 +17,9 @@ import logging
import os
from subiquitycore.context import with_context
from subiquitycore.pubsub import MessageChannels
from subiquity.common.apidef import API
from subiquity.common.types import InstallerChannels
from subiquity.server.controller import SubiquityController
log = logging.getLogger('subiquity.server.controllers.proxy')
@ -46,7 +46,7 @@ class ProxyController(SubiquityController):
os.environ['http_proxy'] = os.environ['https_proxy'] = \
self.model.proxy
self._set_task = self.app.hub.broadcast(
MessageChannels.NETWORK_PROXY_SET)
InstallerChannels.NETWORK_PROXY_SET)
@with_context()
async def apply_autoinstall_config(self, context=None):
@ -68,5 +68,5 @@ class ProxyController(SubiquityController):
async def POST(self, data: str):
self.model.proxy = data
os.environ['http_proxy'] = os.environ['https_proxy'] = data
self.app.hub.broadcast(MessageChannels.NETWORK_PROXY_SET)
self.app.hub.broadcast(InstallerChannels.NETWORK_PROXY_SET)
self.configured()

View File

@ -24,10 +24,10 @@ from subiquitycore.async_helpers import (
SingleInstanceTask,
)
from subiquitycore.context import with_context
from subiquitycore.pubsub import MessageChannels
from subiquity.common.apidef import API
from subiquity.common.types import (
InstallerChannels,
RefreshCheckState,
RefreshStatus,
)
@ -60,7 +60,7 @@ class RefreshController(SubiquityController):
self.configure_task = None
self.check_task = None
self.status = RefreshStatus(availability=RefreshCheckState.UNKNOWN)
self.app.hub.subscribe(MessageChannels.SNAPD_NETWORK_CHANGE,
self.app.hub.subscribe(InstallerChannels.SNAPD_NETWORK_CHANGE,
self.snapd_network_changed)
def load_autoinstall_data(self, data):

View File

@ -24,10 +24,10 @@ from subiquitycore.async_helpers import (
schedule_task,
)
from subiquitycore.context import with_context
from subiquitycore.pubsub import MessageChannels
from subiquity.common.apidef import API
from subiquity.common.types import (
InstallerChannels,
SnapCheckState,
SnapInfo,
SnapListResponse,
@ -139,7 +139,7 @@ class SnapListController(SubiquityController):
def __init__(self, app):
super().__init__(app)
self.loader = self._make_loader()
self.app.hub.subscribe(MessageChannels.SNAPD_NETWORK_CHANGE,
self.app.hub.subscribe(InstallerChannels.SNAPD_NETWORK_CHANGE,
self.snapd_network_changed)
def load_autoinstall_data(self, ai_data):

View File

@ -22,7 +22,8 @@ from subiquitycore.async_helpers import (
run_in_thread,
SingleInstanceTask,
)
from subiquitycore.pubsub import MessageChannels
from subiquity.common.types import InstallerChannels
log = logging.getLogger('subiquity.common.geoip')
@ -42,9 +43,9 @@ class GeoIP:
self.tz = None
self.check_state = CheckState.NOT_STARTED
self.lookup_task = SingleInstanceTask(self.lookup)
self.app.hub.subscribe(MessageChannels.NETWORK_UP,
self.app.hub.subscribe(InstallerChannels.NETWORK_UP,
self.maybe_start_check)
self.app.hub.subscribe(MessageChannels.NETWORK_PROXY_SET,
self.app.hub.subscribe(InstallerChannels.NETWORK_PROXY_SET,
self.maybe_start_check)
def maybe_start_check(self):
@ -97,7 +98,7 @@ class GeoIP:
self.tz = tz.text
if changed:
self.app.hub.broadcast(MessageChannels.GEOIP)
self.app.hub.broadcast(InstallerChannels.GEOIP)
return True

View File

@ -37,7 +37,6 @@ from subiquitycore.async_helpers import run_in_thread
from subiquitycore.context import with_context
from subiquitycore.core import Application
from subiquitycore.prober import Prober
from subiquitycore.pubsub import MessageChannels
from subiquitycore.ssh import (
host_key_fingerprints,
user_key_fingerprints,
@ -58,6 +57,7 @@ from subiquity.common.types import (
ApplicationState,
ApplicationStatus,
ErrorReportRef,
InstallerChannels,
KeyFingerprint,
LiveSessionSSHInfo,
PasswordKind,
@ -281,8 +281,9 @@ class SubiquityServer(Application):
self.note_data_for_apport("SnapUpdated", str(self.updated))
self.event_listeners = []
self.autoinstall_config = None
self.hub.subscribe(MessageChannels.NETWORK_UP, self._network_change)
self.hub.subscribe(MessageChannels.NETWORK_PROXY_SET, self._proxy_set)
self.hub.subscribe(InstallerChannels.NETWORK_UP, self._network_change)
self.hub.subscribe(InstallerChannels.NETWORK_PROXY_SET,
self._proxy_set)
self.geoip = GeoIP(self)
def load_serialized_state(self):
@ -581,14 +582,14 @@ class SubiquityServer(Application):
def _network_change(self):
if not self.snapd:
return
self.hub.broadcast(MessageChannels.SNAPD_NETWORK_CHANGE)
self.hub.broadcast(InstallerChannels.SNAPD_NETWORK_CHANGE)
async def _proxy_set(self):
if not self.snapd:
return
await run_in_thread(
self.snapd.connection.configure_proxy, self.base_model.proxy)
self.hub.broadcast(MessageChannels.SNAPD_NETWORK_CHANGE)
self.hub.broadcast(InstallerChannels.SNAPD_NETWORK_CHANGE)
def restart(self):
if not self.snapd:

View File

@ -36,7 +36,7 @@ from subiquitycore.models.network import (
)
from subiquitycore import netplan
from subiquitycore.controller import BaseController
from subiquitycore.pubsub import MessageChannels
from subiquitycore.pubsub import CoreChannels
from subiquitycore.tuicontroller import TuiController
from subiquitycore.ui.stretchy import StretchyOverlay
from subiquitycore.ui.views.network import (
@ -480,7 +480,7 @@ class BaseNetworkController(BaseController):
@abc.abstractmethod
def update_default_routes(self, routes):
if routes:
self.app.hub.broadcast(MessageChannels.NETWORK_UP)
self.app.hub.broadcast(CoreChannels.NETWORK_UP)
@abc.abstractmethod
def new_link(self, netdev):

View File

@ -14,15 +14,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import enum
import inspect
class MessageChannels(enum.IntEnum):
NETWORK_UP = enum.auto()
NETWORK_PROXY_SET = enum.auto()
SNAPD_NETWORK_CHANGE = enum.auto()
GEOIP = enum.auto()
class CoreChannels:
NETWORK_UP = 'network-up'
class MessageHub: