add a mode argument to shutdown to allow reboot or power off
This commit is contained in:
parent
a2675b6ca6
commit
7f1beb1d64
|
@ -21,7 +21,10 @@ import aiohttp
|
||||||
from subiquitycore.context import with_context
|
from subiquitycore.context import with_context
|
||||||
|
|
||||||
from subiquity.client.controller import SubiquityTuiController
|
from subiquity.client.controller import SubiquityTuiController
|
||||||
from subiquity.common.types import ApplicationState
|
from subiquity.common.types import (
|
||||||
|
ApplicationState,
|
||||||
|
ShutdownMode,
|
||||||
|
)
|
||||||
from subiquity.ui.views.installprogress import (
|
from subiquity.ui.views.installprogress import (
|
||||||
InstallRunning,
|
InstallRunning,
|
||||||
ProgressView,
|
ProgressView,
|
||||||
|
@ -65,7 +68,7 @@ class ProgressController(SubiquityTuiController):
|
||||||
|
|
||||||
async def send_reboot_and_wait(self):
|
async def send_reboot_and_wait(self):
|
||||||
try:
|
try:
|
||||||
await self.app.client.shutdown.POST()
|
await self.app.client.shutdown.POST(mode=ShutdownMode.REBOOT)
|
||||||
except aiohttp.ClientError:
|
except aiohttp.ClientError:
|
||||||
pass
|
pass
|
||||||
self.app.exit()
|
self.app.exit()
|
||||||
|
|
|
@ -37,6 +37,7 @@ from subiquity.common.types import (
|
||||||
IdentityData,
|
IdentityData,
|
||||||
NetworkStatus,
|
NetworkStatus,
|
||||||
RefreshStatus,
|
RefreshStatus,
|
||||||
|
ShutdownMode,
|
||||||
SnapInfo,
|
SnapInfo,
|
||||||
SnapListResponse,
|
SnapListResponse,
|
||||||
SnapSelection,
|
SnapSelection,
|
||||||
|
@ -236,7 +237,7 @@ class API:
|
||||||
def POST(tz: str): ...
|
def POST(tz: str): ...
|
||||||
|
|
||||||
class shutdown:
|
class shutdown:
|
||||||
def POST(immediate: bool = False): ...
|
def POST(mode: ShutdownMode, immediate: bool = False): ...
|
||||||
|
|
||||||
|
|
||||||
class LinkAction(enum.Enum):
|
class LinkAction(enum.Enum):
|
||||||
|
|
|
@ -330,3 +330,8 @@ class SnapListResponse:
|
||||||
class TimeZoneInfo:
|
class TimeZoneInfo:
|
||||||
timezone: str
|
timezone: str
|
||||||
from_geoip: bool
|
from_geoip: bool
|
||||||
|
|
||||||
|
|
||||||
|
class ShutdownMode(enum.Enum):
|
||||||
|
REBOOT = enum.auto()
|
||||||
|
POWEROFF = enum.auto()
|
||||||
|
|
|
@ -23,6 +23,7 @@ from subiquitycore.context import with_context
|
||||||
from subiquitycore.utils import arun_command, run_command
|
from subiquitycore.utils import arun_command, run_command
|
||||||
|
|
||||||
from subiquity.common.apidef import API
|
from subiquity.common.apidef import API
|
||||||
|
from subiquity.common.types import ShutdownMode
|
||||||
from subiquity.server.controller import SubiquityController
|
from subiquity.server.controller import SubiquityController
|
||||||
from subiquity.server.controllers.install import ApplicationState
|
from subiquity.server.controllers.install import ApplicationState
|
||||||
|
|
||||||
|
@ -43,8 +44,10 @@ class ShutdownController(SubiquityController):
|
||||||
self.user_shutdown_event = asyncio.Event()
|
self.user_shutdown_event = asyncio.Event()
|
||||||
self.server_reboot_event = asyncio.Event()
|
self.server_reboot_event = asyncio.Event()
|
||||||
self.shuttingdown_event = asyncio.Event()
|
self.shuttingdown_event = asyncio.Event()
|
||||||
|
self.mode = ShutdownMode.REBOOT
|
||||||
|
|
||||||
async def POST(self, immediate: bool = False):
|
async def POST(self, mode: ShutdownMode, immediate: bool = False):
|
||||||
|
self.mode = mode
|
||||||
self.app.controllers.Install.stop_uu()
|
self.app.controllers.Install.stop_uu()
|
||||||
self.user_shutdown_event.set()
|
self.user_shutdown_event.set()
|
||||||
if immediate:
|
if immediate:
|
||||||
|
@ -92,7 +95,7 @@ class ShutdownController(SubiquityController):
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception("saving journal failed")
|
log.exception("saving journal failed")
|
||||||
|
|
||||||
@with_context()
|
@with_context(description='mode={self.mode.name}')
|
||||||
def shutdown(self, context):
|
def shutdown(self, context):
|
||||||
self.shuttingdown_event.set()
|
self.shuttingdown_event.set()
|
||||||
if self.opts.dry_run:
|
if self.opts.dry_run:
|
||||||
|
@ -101,4 +104,7 @@ class ShutdownController(SubiquityController):
|
||||||
if self.app.state == ApplicationState.DONE:
|
if self.app.state == ApplicationState.DONE:
|
||||||
if platform.machine() == 's390x':
|
if platform.machine() == 's390x':
|
||||||
run_command(["chreipl", "/target/boot"])
|
run_command(["chreipl", "/target/boot"])
|
||||||
run_command(["/sbin/reboot"])
|
if self.mode == ShutdownMode.REBOOT:
|
||||||
|
run_command(["/sbin/reboot"])
|
||||||
|
elif self.mode == ShutdownMode.POWEROFF:
|
||||||
|
run_command(["/sbin/poweroff"])
|
||||||
|
|
|
@ -131,7 +131,7 @@ def with_context(name=None, description="", **context_kw):
|
||||||
context = self.context
|
context = self.context
|
||||||
kw['context'] = context.child(
|
kw['context'] = context.child(
|
||||||
name=name.format(**kw),
|
name=name.format(**kw),
|
||||||
description=description.format(**kw),
|
description=description.format(self=self, **kw),
|
||||||
**context_kw)
|
**context_kw)
|
||||||
return kw
|
return kw
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue