Skip to content

Commit 4e70611

Browse files
authored
NAS-135127 / 25.10 / Convert remaining system.advanced namespace (#16169)
http://jenkins.eng.ixsystems.net:8080/job/tests/job/api_tests/3792/
1 parent ad90b29 commit 4e70611

File tree

4 files changed

+156
-87
lines changed

4 files changed

+156
-87
lines changed

src/middlewared/middlewared/api/v25_10_0/system_advanced.py

+117-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,67 @@
1-
from middlewared.api.base import BaseModel
1+
from typing import Literal
22

3-
__all__ = (
4-
"SystemAdvancedGpuChoicesArgs",
5-
"SystemAdvancedGpuChoicesResult",
6-
"SystemAdvancedUpdateGpuPciIdArgs",
7-
"SystemAdvancedUpdateGpuPciIdResult",
3+
from pydantic import Field, PositiveInt, NonNegativeInt, Secret
4+
5+
from middlewared.api.base import (
6+
BaseModel, NotRequired, ForUpdateMetaclass, Excluded, excluded_field, NonEmptyString, EmptyDict
87
)
98

109

10+
__all__ = [
11+
"SystemAdvancedEntry", "SystemAdvancedGpuChoicesArgs", "SystemAdvancedGpuChoicesResult",
12+
"SystemAdvancedLoginBannerArgs", "SystemAdvancedLoginBannerResult", "SystemAdvancedSEDGlobalPasswordArgs",
13+
"SystemAdvancedSEDGlobalPasswordResult", "SystemAdvancedSEDGlobalPasswordIsSetArgs",
14+
"SystemAdvancedSEDGlobalPasswordIsSetResult", "SystemAdvancedSerialPortChoicesArgs",
15+
"SystemAdvancedSerialPortChoicesResult", "SystemAdvancedSyslogCertificateAuthorityChoicesArgs",
16+
"SystemAdvancedSyslogCertificateAuthorityChoicesResult", "SystemAdvancedSyslogCertificateChoicesArgs",
17+
"SystemAdvancedSyslogCertificateChoicesResult", "SystemAdvancedUpdateArgs", "SystemAdvancedUpdateResult",
18+
"SystemAdvancedUpdateGpuPciIdArgs", "SystemAdvancedUpdateGpuPciIdResult",
19+
]
20+
21+
22+
class SystemAdvancedEntry(BaseModel):
23+
id: int
24+
advancedmode: bool
25+
autotune: bool
26+
"""Execute autotune script which attempts to optimize the system based on the installed hardware."""
27+
kdump_enabled: bool
28+
boot_scrub: PositiveInt
29+
consolemenu: bool
30+
"""Enable console menu. Default to standard login in the console if disabled."""
31+
consolemsg: bool
32+
"""Deprecated: Please use `consolemsg` attribute in the `system.general` plugin instead."""
33+
debugkernel: bool
34+
fqdn_syslog: bool
35+
motd: str
36+
login_banner: str = Field(max_length=4096)
37+
powerdaemon: bool
38+
serialconsole: bool
39+
serialport: str
40+
anonstats_token: str
41+
serialspeed: Literal['9600', '19200', '38400', '57600', '115200']
42+
overprovision: NonNegativeInt | None
43+
traceback: bool
44+
uploadcrash: bool
45+
anonstats: bool
46+
sed_user: Literal['USER', 'MASTER']
47+
sysloglevel: Literal['F_EMERG', 'F_ALERT', 'F_CRIT', 'F_ERR', 'F_WARNING', 'F_NOTICE', 'F_INFO', 'F_DEBUG']
48+
syslogserver: str = NotRequired
49+
"""When defined, logs of `sysloglevel` or higher are sent."""
50+
syslog_transport: Literal['UDP', 'TCP', 'TLS']
51+
syslog_tls_certificate: int | None
52+
syslog_audit: bool = NotRequired
53+
"""The remote syslog server will also receive audit messages."""
54+
isolated_gpu_pci_ids: list[str]
55+
kernel_extra_options: str
56+
57+
58+
class SystemAdvancedUpdate(SystemAdvancedEntry, metaclass=ForUpdateMetaclass):
59+
id: Excluded = excluded_field()
60+
anonstats_token: Excluded = excluded_field()
61+
isolated_gpu_pci_ids: Excluded = excluded_field()
62+
sed_passwd: Secret[str]
63+
64+
1165
class SystemAdvancedGpuChoicesArgs(BaseModel):
1266
pass
1367

@@ -16,6 +70,63 @@ class SystemAdvancedGpuChoicesResult(BaseModel):
1670
result: dict
1771

1872

73+
class SystemAdvancedLoginBannerArgs(BaseModel):
74+
pass
75+
76+
77+
class SystemAdvancedLoginBannerResult(BaseModel):
78+
result: str
79+
80+
81+
class SystemAdvancedSEDGlobalPasswordArgs(BaseModel):
82+
pass
83+
84+
85+
class SystemAdvancedSEDGlobalPasswordResult(BaseModel):
86+
result: Secret[str]
87+
88+
89+
class SystemAdvancedSEDGlobalPasswordIsSetArgs(BaseModel):
90+
pass
91+
92+
93+
class SystemAdvancedSEDGlobalPasswordIsSetResult(BaseModel):
94+
result: bool
95+
96+
97+
class SystemAdvancedSerialPortChoicesArgs(BaseModel):
98+
pass
99+
100+
101+
class SystemAdvancedSerialPortChoicesResult(BaseModel):
102+
result: dict[str, str]
103+
104+
105+
class SystemAdvancedSyslogCertificateAuthorityChoicesArgs(BaseModel):
106+
pass
107+
108+
109+
class SystemAdvancedSyslogCertificateAuthorityChoicesResult(BaseModel):
110+
result: EmptyDict
111+
112+
113+
class SystemAdvancedSyslogCertificateChoicesArgs(BaseModel):
114+
pass
115+
116+
117+
class SystemAdvancedSyslogCertificateChoicesResult(BaseModel):
118+
result: dict[int, NonEmptyString]
119+
"""IDs of certificates mapped to their names."""
120+
121+
122+
class SystemAdvancedUpdateArgs(BaseModel):
123+
data: SystemAdvancedUpdate
124+
125+
126+
class SystemAdvancedUpdateResult(BaseModel):
127+
result: SystemAdvancedEntry
128+
129+
19130
class SystemAdvancedUpdateGpuPciIdArgs(BaseModel):
20131
data: list[str]
21132

src/middlewared/middlewared/plugins/system_advanced/config.py

+21-67
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
import middlewared.sqlalchemy as sa
99

10-
from middlewared.schema import accepts, Bool, Dict, Int, List, Patch, Password, returns, Str
11-
from middlewared.service import ConfigService, private, no_auth_required
12-
from middlewared.validators import Range
10+
from middlewared.api import api_method
11+
from middlewared.api.current import (
12+
SystemAdvancedEntry, SystemAdvancedLoginBannerArgs, SystemAdvancedLoginBannerResult,
13+
SystemAdvancedSEDGlobalPasswordArgs, SystemAdvancedSEDGlobalPasswordResult,
14+
SystemAdvancedSEDGlobalPasswordIsSetArgs, SystemAdvancedSEDGlobalPasswordIsSetResult, SystemAdvancedUpdateArgs,
15+
SystemAdvancedUpdateResult
16+
)
17+
from middlewared.service import ConfigService, private
1318
from middlewared.utils import run
1419
from middlewared.utils.service.settings import SettingsHelper
1520

@@ -59,40 +64,7 @@ class Config:
5964
namespace = 'system.advanced'
6065
cli_namespace = 'system.advanced'
6166
role_prefix = 'SYSTEM_ADVANCED'
62-
63-
ENTRY = Dict(
64-
'system_advanced_entry',
65-
Bool('advancedmode', required=True),
66-
Bool('autotune', required=True),
67-
Bool('kdump_enabled', required=True),
68-
Int('boot_scrub', validators=[Range(min_=1)], required=True),
69-
Bool('consolemenu', required=True),
70-
Bool('consolemsg', required=True),
71-
Bool('debugkernel', required=True),
72-
Bool('fqdn_syslog', required=True),
73-
Str('motd', required=True),
74-
Str('login_banner', required=True, max_length=4096),
75-
Bool('powerdaemon', required=True),
76-
Bool('serialconsole', required=True),
77-
Str('serialport', required=True),
78-
Str('anonstats_token', required=True),
79-
Str('serialspeed', enum=['9600', '19200', '38400', '57600', '115200'], required=True),
80-
Int('overprovision', validators=[Range(min_=0)], null=True, required=True),
81-
Bool('traceback', required=True),
82-
Bool('uploadcrash', required=True),
83-
Bool('anonstats', required=True),
84-
Str('sed_user', enum=['USER', 'MASTER'], required=True),
85-
Str('sysloglevel', enum=[
86-
'F_EMERG', 'F_ALERT', 'F_CRIT', 'F_ERR', 'F_WARNING', 'F_NOTICE', 'F_INFO', 'F_DEBUG',
87-
], required=True),
88-
Str('syslogserver'),
89-
Str('syslog_transport', enum=['UDP', 'TCP', 'TLS'], required=True),
90-
Int('syslog_tls_certificate', null=True, required=True),
91-
Bool('syslog_audit'),
92-
List('isolated_gpu_pci_ids', items=[Str('pci_id')], required=True),
93-
Str('kernel_extra_options', required=True),
94-
Int('id', required=True),
95-
)
67+
entry = SystemAdvancedEntry
9668

9769
@private
9870
async def system_advanced_extend(self, data):
@@ -180,32 +152,10 @@ async def _validate_kernel_extra_options(self, verrors, kernel_extra_options):
180152
# foot-shooting
181153
verrors.add('kernel_extra_options', f'Modifying {invalid_param!r} is not allowed')
182154

183-
@accepts(
184-
Patch(
185-
'system_advanced_entry', 'system_advanced_update',
186-
('rm', {'name': 'id'}),
187-
('rm', {'name': 'anonstats_token'}),
188-
('rm', {'name': 'isolated_gpu_pci_ids'}),
189-
('add', Password('sed_passwd')),
190-
('attr', {'update': True}),
191-
),
192-
audit='System advanced update'
193-
)
155+
@api_method(SystemAdvancedUpdateArgs, SystemAdvancedUpdateResult, audit='System advanced update')
194156
async def do_update(self, data):
195157
"""
196158
Update System Advanced Service Configuration.
197-
198-
`consolemenu` should be disabled if the menu at console is not desired. It will default to standard login
199-
in the console if disabled.
200-
201-
`autotune` when enabled executes autotune script which attempts to optimize the system based on the installed
202-
hardware.
203-
204-
When `syslogserver` is defined, logs of `sysloglevel` or above are sent. If syslog_audit is also set
205-
then the remote syslog server will also receive audit messages.
206-
207-
`consolemsg` is a deprecated attribute and will be removed in further releases. Please, use `consolemsg`
208-
attribute in the `system.general` plugin.
209159
"""
210160
consolemsg = None
211161
if 'consolemsg' in data:
@@ -291,15 +241,21 @@ async def do_update(self, data):
291241

292242
return await self.config()
293243

294-
@accepts(roles=['SYSTEM_ADVANCED_READ'])
295-
@returns(Bool('sed_global_password_is_set'))
244+
@api_method(
245+
SystemAdvancedSEDGlobalPasswordIsSetArgs,
246+
SystemAdvancedSEDGlobalPasswordIsSetResult,
247+
roles=['SYSTEM_ADVANCED_READ']
248+
)
296249
async def sed_global_password_is_set(self):
297250
"""Returns a boolean identifying whether or not a global
298251
SED password has been set"""
299252
return bool(await self.sed_global_password())
300253

301-
@accepts(roles=['SYSTEM_ADVANCED_READ'])
302-
@returns(Password('sed_global_password'))
254+
@api_method(
255+
SystemAdvancedSEDGlobalPasswordArgs,
256+
SystemAdvancedSEDGlobalPasswordResult,
257+
roles=['SYSTEM_ADVANCED_READ']
258+
)
303259
async def sed_global_password(self):
304260
"""Returns configured global SED password in clear-text if one
305261
is configured, otherwise an empty string"""
@@ -308,9 +264,7 @@ async def sed_global_password(self):
308264
))['sed_passwd']
309265
return passwd if passwd else await self.middleware.call('kmip.sed_global_password')
310266

311-
@no_auth_required
312-
@accepts()
313-
@returns(Str())
267+
@api_method(SystemAdvancedLoginBannerArgs, SystemAdvancedLoginBannerResult, authentication_required=False)
314268
def login_banner(self):
315269
"""Returns user set login banner"""
316270
# NOTE: This endpoint doesn't require authentication because

src/middlewared/middlewared/plugins/system_advanced/serial.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from middlewared.schema import accepts, Dict, returns
1+
from middlewared.api import api_method
2+
from middlewared.api.current import SystemAdvancedSerialPortChoicesArgs, SystemAdvancedSerialPortChoicesResult
23
from middlewared.service import private, Service
34
from middlewared.utils import run
45

@@ -9,8 +10,7 @@ class Config:
910
namespace = 'system.advanced'
1011
cli_namespace = 'system.advanced'
1112

12-
@accepts()
13-
@returns(Dict('serial_port_choices', additional_attrs=True))
13+
@api_method(SystemAdvancedSerialPortChoicesArgs, SystemAdvancedSerialPortChoicesResult, roles=['READONLY_ADMIN'])
1414
async def serial_port_choices(self):
1515
"""
1616
Get available choices for `serialport`.

src/middlewared/middlewared/plugins/system_advanced/syslog.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from middlewared.schema import accepts, Dict, returns
1+
from middlewared.api import api_method
2+
from middlewared.api.current import (
3+
SystemAdvancedSyslogCertificateChoicesArgs, SystemAdvancedSyslogCertificateChoicesResult,
4+
SystemAdvancedSyslogCertificateAuthorityChoicesArgs, SystemAdvancedSyslogCertificateAuthorityChoicesResult
5+
)
26
from middlewared.service import Service
37

48

@@ -8,11 +12,11 @@ class Config:
812
namespace = 'system.advanced'
913
cli_namespace = 'system.advanced'
1014

11-
@accepts()
12-
@returns(Dict(
13-
additional_attrs=True,
14-
title='Syslog Certificate Choices',
15-
))
15+
@api_method(
16+
SystemAdvancedSyslogCertificateChoicesArgs,
17+
SystemAdvancedSyslogCertificateChoicesResult,
18+
roles=['READONLY_ADMIN']
19+
)
1620
async def syslog_certificate_choices(self):
1721
"""
1822
Return choices of certificates which can be used for `syslog_tls_certificate`.
@@ -24,11 +28,11 @@ async def syslog_certificate_choices(self):
2428
)
2529
}
2630

27-
@accepts()
28-
@returns(Dict(
29-
additional_attrs=True,
30-
title='Syslog Certificate Authority Choices',
31-
))
31+
@api_method(
32+
SystemAdvancedSyslogCertificateAuthorityChoicesArgs,
33+
SystemAdvancedSyslogCertificateAuthorityChoicesResult,
34+
authorization_required=False
35+
)
3236
async def syslog_certificate_authority_choices(self):
3337
"""
3438
Return choices of certificate authorities which can be used for `syslog_tls_certificate_authority`.

0 commit comments

Comments
 (0)