2222 PrivacyProtocolType ,
2323)
2424from cmk .gui .logged_in import user
25- from cmk .gui .openapi .framework .model import api_field , ApiOmitted
25+ from cmk .gui .openapi .framework .model import api_field , api_model , ApiOmitted
2626from cmk .gui .openapi .framework .model .common_fields import IPv4String , RegexString
2727from cmk .gui .openapi .framework .model .converter import (
2828 GroupConverter ,
4343from cmk .utils .translations import TranslationOptionsSpec
4444
4545
46- @dataclass ( kw_only = True , slots = True )
46+ @api_model
4747class HostContactGroupModel :
4848 groups : list [Annotated [str , AfterValidator (GroupConverter (group_type = "host" ).exists )]] = (
4949 api_field (description = "A list of contact groups." , example = "all" )
@@ -79,13 +79,13 @@ def to_internal(self) -> HostContactGroupSpec:
7979 }
8080
8181
82- @dataclass ( kw_only = True , slots = True )
82+ @api_model
8383class SNMPCommunityModel :
8484 type : Literal ["v1_v2_community" ] = api_field (description = "SNMP v1 or v2 with community" )
8585 community : str = api_field (description = "SNMP community (SNMP Versions 1 and 2c)" )
8686
8787
88- @dataclass ( kw_only = True , slots = True )
88+ @api_model
8989class SNMPv3NoAuthNoPrivacyModel :
9090 type : Literal ["noAuthNoPriv" ] = api_field (
9191 description = "SNMPv3 without authentication or privacy"
@@ -103,7 +103,7 @@ def to_internal(self) -> tuple[Literal["noAuthNoPriv"], str]:
103103 return self .type , self .security_name
104104
105105
106- @dataclass ( kw_only = True , slots = True )
106+ @api_model
107107class SNMPv3AuthNoPrivacyModel :
108108 type : Literal ["authNoPriv" ] = api_field (
109109 description = "SNMPv3 with authentication, but without privacy"
@@ -132,7 +132,7 @@ def to_internal(self) -> tuple[Literal["authNoPriv"], str, str, str]:
132132 )
133133
134134
135- @dataclass ( kw_only = True , slots = True )
135+ @api_model
136136class SNMPv3AuthPrivacyModel :
137137 type : Literal ["authPriv" ] = api_field (description = "SNMPv3 with authentication and privacy" )
138138 auth_protocol : AuthProtocolType = api_field (description = "Authentication protocol." )
@@ -211,7 +211,7 @@ def to_internal(field: SNMPCredentialsModel) -> str | tuple:
211211 raise ValueError (f"Unknown SNMP credentials type: { field .type !r} " )
212212
213213
214- @dataclass ( kw_only = True , slots = True )
214+ @api_model
215215class IPAddressRangeModel :
216216 type : Literal ["ip_range" ] = api_field (description = "Select a range of IP addresses" )
217217 from_address : IPv4String = api_field (description = "The first IPv4 address of this range." )
@@ -229,7 +229,7 @@ def to_internal(self) -> tuple[Literal["ip_range"], tuple[str, str]]:
229229 return self .type , (str (self .from_address ), str (self .to_address ))
230230
231231
232- @dataclass ( kw_only = True , slots = True )
232+ @api_model
233233class IPNetworkModel :
234234 type : Literal ["ip_network" ] = api_field (description = "Select an entire network" )
235235 network : IPv4Network = api_field (
@@ -248,7 +248,7 @@ def to_internal(self) -> tuple[Literal["ip_network"], tuple[str, int]]:
248248 return self .type , (str (self .network .network_address ), self .network .prefixlen )
249249
250250
251- @dataclass ( kw_only = True , slots = True )
251+ @api_model
252252class IPAddressesModel :
253253 type : Literal ["ip_list" ] = api_field (description = "Select multiple explicit IP addresses" )
254254 addresses : list [IPv4String ] = api_field (description = "List of IPv4 addresses" )
@@ -264,7 +264,7 @@ def to_internal(self) -> tuple[Literal["ip_list"], Sequence[HostAddress]]:
264264 return self .type , [HostAddress (x ) for x in self .addresses ]
265265
266266
267- @dataclass ( kw_only = True , slots = True )
267+ @api_model
268268class IPRegexpModel :
269269 type : Literal ["ip_regex_list" ] = api_field (description = "Deselect IP addresses with regexes" )
270270 regexp_list : list [RegexString ] = api_field (
@@ -306,7 +306,7 @@ def from_internal_exclude(value: ExcludeIPRange) -> IPRangeWithRegexpModel:
306306 return IPRangeConverter .from_internal (value )
307307
308308
309- @dataclass ( kw_only = True , slots = True )
309+ @api_model
310310class TimeAllowedRangeModel :
311311 start : dt .time = api_field (
312312 description = "The start time of day. Inclusive. Use ISO8601 format. Seconds are stripped."
@@ -334,7 +334,7 @@ def to_internal(self) -> tuple[_CheckmkTime, _CheckmkTime]:
334334 return (self .start .hour , self .start .minute ), (self .end .hour , self .end .minute )
335335
336336
337- @dataclass ( kw_only = True , slots = True )
337+ @api_model
338338class RegexpRewritesModel :
339339 search : Annotated [RegexString , MaxLen (30 )] = api_field (
340340 description = "The search regexp. May contain match-groups, conditional matches, etc. This follows the Python regular expression syntax.\n \n For details see:\n \n * https://docs.python.org/3/library/re.html"
@@ -373,7 +373,7 @@ def to_internal(self) -> tuple[str, str]:
373373 return str (self .search ), self .replace_with
374374
375375
376- @dataclass ( kw_only = True , slots = True )
376+ @api_model
377377class DirectMappingModel :
378378 hostname : str = api_field (description = "The host name to be replaced." )
379379 replace_with : str = api_field (description = "The replacement string." )
@@ -389,7 +389,7 @@ def to_internal(self) -> tuple[str, str]:
389389 return self .hostname , self .replace_with
390390
391391
392- @dataclass ( kw_only = True , slots = True )
392+ @api_model
393393class TranslateNamesModel :
394394 case : Literal ["nop" , "lower" , "upper" ] = api_field (
395395 serialization_alias = "convert_case" ,
@@ -480,7 +480,7 @@ def to_internal(self) -> TranslationOptionsSpec:
480480 return spec
481481
482482
483- @dataclass ( kw_only = True , slots = True )
483+ @api_model
484484class NetworkScanModel :
485485 ip_ranges : list [IPRangeModel ] = api_field (
486486 serialization_alias = "addresses" , description = "IPv4 addresses to include."
@@ -584,7 +584,7 @@ def to_internal(self) -> NetworkScanSpec:
584584 return spec
585585
586586
587- @dataclass ( kw_only = True , slots = True )
587+ @api_model
588588class IPMIParametersModel : # TODO: this is dumb (or at least the IPMICredentials are)
589589 username : str | ApiOmitted = api_field (description = "IPMI username" , default_factory = ApiOmitted )
590590 password : str | ApiOmitted = api_field (description = "IPMI password" , default_factory = ApiOmitted )
@@ -605,7 +605,7 @@ def to_internal(self) -> IPMICredentials:
605605 return spec
606606
607607
608- @dataclass ( kw_only = True , slots = True )
608+ @api_model
609609class NetworkScanResultModel :
610610 start : dt .datetime | None = api_field (
611611 description = "When the scan started" ,
@@ -640,7 +640,7 @@ def from_internal(cls, value: NetworkScanResult) -> "NetworkScanResultModel":
640640 )
641641
642642
643- @dataclass ( kw_only = True , slots = True )
643+ @api_model
644644class MetaDataModel :
645645 created_at : dt .datetime | ApiOmitted = api_field (
646646 description = "When has this object been created." ,
@@ -668,7 +668,7 @@ def from_internal(cls, value: MetaData) -> Self:
668668 )
669669
670670
671- @dataclass ( kw_only = True , slots = True )
671+ @api_model
672672class LockedByModel :
673673 site_id : str = api_field (description = "Site ID" )
674674 program_id : str = api_field (description = "Program ID" )
@@ -689,7 +689,7 @@ def to_internal(self) -> Sequence[str]:
689689 return [self .site_id , self .program_id , self .instance_id ]
690690
691691
692- @dataclass ( kw_only = True )
692+ @api_model
693693class FolderCustomHostAttributesAndTagGroupsModel (WithDynamicFields ):
694694 """Class for custom host attributes and tag groups."""
695695
0 commit comments