pa_api.xmlapi.types.statistics
1from datetime import datetime 2from typing import Any, List, Literal, Optional, Union 3 4from pydantic import AliasChoices, BaseModel, ConfigDict, Field, field_validator 5 6from pa_api.xmlapi.utils import el2dict as xml2dict 7 8 9class RuleHit(BaseModel): 10 name: str = Field(validation_alias=AliasChoices("@name", "name")) 11 device_group: str = Field(alias="device-group") 12 rulebase: Literal["pre-rulebase", "post-rulebase"] = Field(alias="rulebase") 13 type: str = Field(alias="type") 14 state: Optional[str] = Field(alias="rule-state") 15 modification: datetime = Field(alias="rule-modification-timestamp") 16 creation: datetime = Field(alias="rule-creation-timestamp") 17 all_connected: bool = Field(alias="all-connected") 18 19 @field_validator("modification", "creation", mode="before") 20 @classmethod 21 def ensure_datetime(cls, v: Any): 22 if not isinstance(v, int): 23 v = int(v) 24 return datetime.fromtimestamp(v) 25 26 @staticmethod 27 def from_tuple(t): 28 device_group, rulebase, rule_type, xml = t 29 return RuleHit.model_validate( 30 { 31 "device-group": device_group, 32 "rulebase": rulebase, 33 "type": rule_type, 34 **xml2dict(xml)["entry"], 35 } 36 ) 37 38 39class RuleUse(BaseModel): 40 model_config = ConfigDict(extra="allow") 41 name: str = Field(validation_alias=AliasChoices("@name", "name")) 42 description: Optional[str] = Field(default=None) 43 uuid: str = Field(validation_alias=AliasChoices("@uuid", "uuid")) 44 state: Optional[str] = Field(alias="rule-state") 45 bytes: Optional[int] = Field(default=None) 46 group_tag: Optional[str] = Field(alias="group-tag", default=None) 47 tag: Optional[List[str]] = Field(default=None) 48 disabled: Optional[bool] = Field(default=None) 49 rule_type: Optional[Literal["interzone", "universal"]] = Field( 50 alias="rule-type", default=None 51 ) 52 nat_type: Optional[Literal["ipv4", "ipv6"]] = Field(alias="nat-type", default=None) 53 modification: datetime = Field(alias="rule-modification-timestamp") 54 creation: datetime = Field(alias="rule-creation-timestamp") 55 56 action: Optional[Union[Literal["allow", "deny", "reset-client"], dict]] = Field( 57 default=None 58 ) 59 to_interface: str = Field(alias="to-interface", default=None) 60 protocol: Optional[Literal["tcp", "udp"]] = Field(default=None) 61 port: Optional[str] = Field(default=None) # Can be a port range 62 63 to_: Optional[List[str]] = Field(alias="from", default=None) 64 from_: Optional[List[str]] = Field(alias="to", default=None) 65 source: Optional[List[str]] = Field(default=None) 66 destination: Optional[List[str]] = Field(default=None) 67 source_translation: Optional[List[str]] = Field( 68 alias="source-translation", default=None 69 ) 70 destination_translation: Optional[List[str]] = Field( 71 alias="destination-translation", default=None 72 ) 73 74 source_user: Optional[List[str]] = Field(alias="source-user", default=None) 75 application: Optional[List[str]] = Field(default=None) 76 category: Optional[List[str]] = Field(default=None) 77 service: Optional[List[str]] = Field(default=None) 78 79 icmp_unreachable: Optional[bool] = Field(alias="icmp-unreachable", default=None) 80 log_start: Optional[bool] = Field(alias="log-start", default=None) 81 log_end: Optional[bool] = Field(alias="log-end", default=None) 82 negate_source: Optional[bool] = Field(alias="negate-source", default=None) 83 negate_destination: Optional[bool] = Field(alias="negate-destination", default=None) 84 85 @field_validator( 86 "tag", 87 "to_", 88 "from_", 89 "source", 90 "destination", 91 "source_translation", 92 "destination_translation", 93 "source_user", 94 "application", 95 "category", 96 "service", 97 mode="before", 98 ) 99 @classmethod 100 def ensure_membership(cls, v: Any): 101 if v is None: 102 return None 103 members = v.get("member") if isinstance(v, dict) else v 104 if isinstance(members, str): 105 members = [members] 106 return members
10class RuleHit(BaseModel): 11 name: str = Field(validation_alias=AliasChoices("@name", "name")) 12 device_group: str = Field(alias="device-group") 13 rulebase: Literal["pre-rulebase", "post-rulebase"] = Field(alias="rulebase") 14 type: str = Field(alias="type") 15 state: Optional[str] = Field(alias="rule-state") 16 modification: datetime = Field(alias="rule-modification-timestamp") 17 creation: datetime = Field(alias="rule-creation-timestamp") 18 all_connected: bool = Field(alias="all-connected") 19 20 @field_validator("modification", "creation", mode="before") 21 @classmethod 22 def ensure_datetime(cls, v: Any): 23 if not isinstance(v, int): 24 v = int(v) 25 return datetime.fromtimestamp(v) 26 27 @staticmethod 28 def from_tuple(t): 29 device_group, rulebase, rule_type, xml = t 30 return RuleHit.model_validate( 31 { 32 "device-group": device_group, 33 "rulebase": rulebase, 34 "type": rule_type, 35 **xml2dict(xml)["entry"], 36 } 37 )
Usage docs: https://docs.pydantic.dev/2.9/concepts/models/
A base class for creating Pydantic models.
Attributes:
__class_vars__: The names of the class variables defined on the model.
__private_attributes__: Metadata about the private attributes of the model.
__signature__: The synthesized __init__
[Signature
][inspect.Signature] of the model.
__pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
__pydantic_core_schema__: The core schema of the model.
__pydantic_custom_init__: Whether the model has a custom `__init__` function.
__pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
__pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
__args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__: The name of the post-init method for the model, if defined.
__pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
__pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
__pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.
__pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
is set to `'allow'`.
__pydantic_fields_set__: The names of fields explicitly set during instantiation.
__pydantic_private__: Values of private attributes set on the model instance.
Configuration for the model, should be a dictionary conforming to [ConfigDict
][pydantic.config.ConfigDict].
Metadata about the fields defined on the model,
mapping of field names to [FieldInfo
][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__
from Pydantic V1.
A dictionary of computed field names and their corresponding ComputedFieldInfo
objects.
Inherited Members
- pydantic.main.BaseModel
- BaseModel
- model_extra
- model_fields_set
- model_construct
- model_copy
- model_dump
- model_dump_json
- model_json_schema
- model_parametrized_name
- model_post_init
- model_rebuild
- model_validate
- model_validate_json
- model_validate_strings
- dict
- json
- parse_obj
- parse_raw
- parse_file
- from_orm
- construct
- copy
- schema
- schema_json
- validate
- update_forward_refs
40class RuleUse(BaseModel): 41 model_config = ConfigDict(extra="allow") 42 name: str = Field(validation_alias=AliasChoices("@name", "name")) 43 description: Optional[str] = Field(default=None) 44 uuid: str = Field(validation_alias=AliasChoices("@uuid", "uuid")) 45 state: Optional[str] = Field(alias="rule-state") 46 bytes: Optional[int] = Field(default=None) 47 group_tag: Optional[str] = Field(alias="group-tag", default=None) 48 tag: Optional[List[str]] = Field(default=None) 49 disabled: Optional[bool] = Field(default=None) 50 rule_type: Optional[Literal["interzone", "universal"]] = Field( 51 alias="rule-type", default=None 52 ) 53 nat_type: Optional[Literal["ipv4", "ipv6"]] = Field(alias="nat-type", default=None) 54 modification: datetime = Field(alias="rule-modification-timestamp") 55 creation: datetime = Field(alias="rule-creation-timestamp") 56 57 action: Optional[Union[Literal["allow", "deny", "reset-client"], dict]] = Field( 58 default=None 59 ) 60 to_interface: str = Field(alias="to-interface", default=None) 61 protocol: Optional[Literal["tcp", "udp"]] = Field(default=None) 62 port: Optional[str] = Field(default=None) # Can be a port range 63 64 to_: Optional[List[str]] = Field(alias="from", default=None) 65 from_: Optional[List[str]] = Field(alias="to", default=None) 66 source: Optional[List[str]] = Field(default=None) 67 destination: Optional[List[str]] = Field(default=None) 68 source_translation: Optional[List[str]] = Field( 69 alias="source-translation", default=None 70 ) 71 destination_translation: Optional[List[str]] = Field( 72 alias="destination-translation", default=None 73 ) 74 75 source_user: Optional[List[str]] = Field(alias="source-user", default=None) 76 application: Optional[List[str]] = Field(default=None) 77 category: Optional[List[str]] = Field(default=None) 78 service: Optional[List[str]] = Field(default=None) 79 80 icmp_unreachable: Optional[bool] = Field(alias="icmp-unreachable", default=None) 81 log_start: Optional[bool] = Field(alias="log-start", default=None) 82 log_end: Optional[bool] = Field(alias="log-end", default=None) 83 negate_source: Optional[bool] = Field(alias="negate-source", default=None) 84 negate_destination: Optional[bool] = Field(alias="negate-destination", default=None) 85 86 @field_validator( 87 "tag", 88 "to_", 89 "from_", 90 "source", 91 "destination", 92 "source_translation", 93 "destination_translation", 94 "source_user", 95 "application", 96 "category", 97 "service", 98 mode="before", 99 ) 100 @classmethod 101 def ensure_membership(cls, v: Any): 102 if v is None: 103 return None 104 members = v.get("member") if isinstance(v, dict) else v 105 if isinstance(members, str): 106 members = [members] 107 return members
Usage docs: https://docs.pydantic.dev/2.9/concepts/models/
A base class for creating Pydantic models.
Attributes:
__class_vars__: The names of the class variables defined on the model.
__private_attributes__: Metadata about the private attributes of the model.
__signature__: The synthesized __init__
[Signature
][inspect.Signature] of the model.
__pydantic_complete__: Whether model building is completed, or if there are still undefined fields.
__pydantic_core_schema__: The core schema of the model.
__pydantic_custom_init__: Whether the model has a custom `__init__` function.
__pydantic_decorators__: Metadata containing the decorators defined on the model.
This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1.
__pydantic_generic_metadata__: Metadata for generic models; contains data used for a similar purpose to
__args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__: The name of the post-init method for the model, if defined.
__pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel].
__pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model.
__pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model.
__pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra]
is set to `'allow'`.
__pydantic_fields_set__: The names of fields explicitly set during instantiation.
__pydantic_private__: Values of private attributes set on the model instance.
Configuration for the model, should be a dictionary conforming to [ConfigDict
][pydantic.config.ConfigDict].
86 @field_validator( 87 "tag", 88 "to_", 89 "from_", 90 "source", 91 "destination", 92 "source_translation", 93 "destination_translation", 94 "source_user", 95 "application", 96 "category", 97 "service", 98 mode="before", 99 ) 100 @classmethod 101 def ensure_membership(cls, v: Any): 102 if v is None: 103 return None 104 members = v.get("member") if isinstance(v, dict) else v 105 if isinstance(members, str): 106 members = [members] 107 return members
Metadata about the fields defined on the model,
mapping of field names to [FieldInfo
][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__
from Pydantic V1.
A dictionary of computed field names and their corresponding ComputedFieldInfo
objects.
Inherited Members
- pydantic.main.BaseModel
- BaseModel
- model_extra
- model_fields_set
- model_construct
- model_copy
- model_dump
- model_dump_json
- model_json_schema
- model_parametrized_name
- model_post_init
- model_rebuild
- model_validate
- model_validate_json
- model_validate_strings
- dict
- json
- parse_obj
- parse_raw
- parse_file
- from_orm
- construct
- copy
- schema
- schema_json
- validate
- update_forward_refs