pa_api.xmlapi.types.config.rules.nat
1import typing 2from itertools import chain 3from typing import Optional, Union 4 5from pydantic import AliasPath, Field 6 7from pa_api.xmlapi.types.utils import List, String, XMLBaseModel 8 9 10class DynamicIPAndPort(XMLBaseModel): 11 translated_address: List[String] = Field( 12 validation_alias="translated-address", default=None 13 ) 14 ip: Optional[String] = Field( 15 validation_alias=AliasPath("interface-address", "ip"), default=None 16 ) 17 interface: Optional[String] = Field( 18 validation_alias=AliasPath("interface-address", "interface"), default=None 19 ) 20 21 22class DynamicIP(XMLBaseModel): 23 translated_address: List[String] = Field( 24 validation_alias="translated-address", default=None 25 ) 26 27 28class StaticIP(XMLBaseModel): 29 translated_address: String = Field(validation_alias="translated-address") 30 31 32class SourceTranslation(XMLBaseModel): 33 dynamic_ip_and_port: Optional[DynamicIPAndPort] = Field( 34 validation_alias="dynamic-ip-and-port", default=None 35 ) 36 dynamic_ip: Optional[DynamicIP] = Field(validation_alias="dynamic-ip", default=None) 37 static_ip: Optional[StaticIP] = Field(validation_alias="static-ip", default=None) 38 39 @property 40 def translation(self) -> Union[DynamicIPAndPort, DynamicIP, StaticIP]: 41 for trans in (self.dynamic_ip_and_port, self.dynamic_ip, self.static_ip): 42 if trans is not None: 43 return trans 44 raise Exception("Invalid sourc translation") 45 46 @property 47 def translated_address(self) -> typing.List[str]: 48 trans = self.translation.translated_address 49 if isinstance(trans, str): 50 return [trans] 51 return trans 52 53 @property 54 def type(self) -> str: 55 if self.static_ip is not None: 56 return "static-ip" 57 if self.dynamic_ip is not None: 58 return "dynamic-ip" 59 if self.dynamic_ip_and_port is not None: 60 return "dynamic-ip-and-port" 61 raise Exception("Invalid sourc translation") 62 63 64class DestinationTranslation(XMLBaseModel): 65 translated_address: Optional[String] = Field( 66 validation_alias=AliasPath("translated-address", "#text"), default=None 67 ) 68 translated_port: Optional[int] = Field( 69 validation_alias=AliasPath("translated-port", "#text"), default=None 70 ) 71 72 73class NAT(XMLBaseModel): 74 name: String = Field(validation_alias="@name") 75 uuid: String = Field(validation_alias="@uuid") 76 disabled: Optional[bool] = None 77 description: String = "" 78 group_tag: Optional[String] = Field(validation_alias="group-tag", default=None) 79 tags: List[String] = Field( 80 validation_alias="tag", 81 default_factory=list, 82 ) 83 services: List[String] = Field(validation_alias="service", default_factory=list) 84 85 source_translation: Optional[SourceTranslation] = Field( 86 validation_alias="source-translation", default=None 87 ) 88 destination_translation: Optional[DestinationTranslation] = Field( 89 validation_alias="destination-translation", default=None 90 ) 91 92 sources: List[String] = Field( 93 validation_alias="source", 94 default_factory=list, 95 ) 96 destinations: List[String] = Field( 97 validation_alias="destination", 98 default_factory=list, 99 ) 100 to: List[String] = Field( 101 validation_alias="to", 102 default_factory=list, 103 ) 104 from_: List[String] = Field( 105 validation_alias="from", 106 default_factory=list, 107 ) 108 109 @property 110 def translated_src_address(self) -> typing.List[str]: 111 if not self.source_translation: 112 return [] 113 return self.source_translation.translated_address 114 115 @property 116 def translated_dst_address(self) -> typing.List[str]: 117 if not self.destination_translation: 118 return [] 119 translated = self.destination_translation.translated_address 120 if not translated: 121 return [] 122 return [translated] 123 124 @property 125 def members(self): 126 return set( 127 chain( 128 self.to, 129 self.from_, 130 self.sources, 131 self.destination_translation, 132 self.translated_src_address, 133 self.translated_dst_address, 134 ) 135 )
11class DynamicIPAndPort(XMLBaseModel): 12 translated_address: List[String] = Field( 13 validation_alias="translated-address", default=None 14 ) 15 ip: Optional[String] = Field( 16 validation_alias=AliasPath("interface-address", "ip"), default=None 17 ) 18 interface: Optional[String] = Field( 19 validation_alias=AliasPath("interface-address", "interface"), default=None 20 )
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
23class DynamicIP(XMLBaseModel): 24 translated_address: List[String] = Field( 25 validation_alias="translated-address", default=None 26 )
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
29class StaticIP(XMLBaseModel): 30 translated_address: String = Field(validation_alias="translated-address")
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
33class SourceTranslation(XMLBaseModel): 34 dynamic_ip_and_port: Optional[DynamicIPAndPort] = Field( 35 validation_alias="dynamic-ip-and-port", default=None 36 ) 37 dynamic_ip: Optional[DynamicIP] = Field(validation_alias="dynamic-ip", default=None) 38 static_ip: Optional[StaticIP] = Field(validation_alias="static-ip", default=None) 39 40 @property 41 def translation(self) -> Union[DynamicIPAndPort, DynamicIP, StaticIP]: 42 for trans in (self.dynamic_ip_and_port, self.dynamic_ip, self.static_ip): 43 if trans is not None: 44 return trans 45 raise Exception("Invalid sourc translation") 46 47 @property 48 def translated_address(self) -> typing.List[str]: 49 trans = self.translation.translated_address 50 if isinstance(trans, str): 51 return [trans] 52 return trans 53 54 @property 55 def type(self) -> str: 56 if self.static_ip is not None: 57 return "static-ip" 58 if self.dynamic_ip is not None: 59 return "dynamic-ip" 60 if self.dynamic_ip_and_port is not None: 61 return "dynamic-ip-and-port" 62 raise Exception("Invalid sourc translation")
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
65class DestinationTranslation(XMLBaseModel): 66 translated_address: Optional[String] = Field( 67 validation_alias=AliasPath("translated-address", "#text"), default=None 68 ) 69 translated_port: Optional[int] = Field( 70 validation_alias=AliasPath("translated-port", "#text"), default=None 71 )
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
74class NAT(XMLBaseModel): 75 name: String = Field(validation_alias="@name") 76 uuid: String = Field(validation_alias="@uuid") 77 disabled: Optional[bool] = None 78 description: String = "" 79 group_tag: Optional[String] = Field(validation_alias="group-tag", default=None) 80 tags: List[String] = Field( 81 validation_alias="tag", 82 default_factory=list, 83 ) 84 services: List[String] = Field(validation_alias="service", default_factory=list) 85 86 source_translation: Optional[SourceTranslation] = Field( 87 validation_alias="source-translation", default=None 88 ) 89 destination_translation: Optional[DestinationTranslation] = Field( 90 validation_alias="destination-translation", default=None 91 ) 92 93 sources: List[String] = Field( 94 validation_alias="source", 95 default_factory=list, 96 ) 97 destinations: List[String] = Field( 98 validation_alias="destination", 99 default_factory=list, 100 ) 101 to: List[String] = Field( 102 validation_alias="to", 103 default_factory=list, 104 ) 105 from_: List[String] = Field( 106 validation_alias="from", 107 default_factory=list, 108 ) 109 110 @property 111 def translated_src_address(self) -> typing.List[str]: 112 if not self.source_translation: 113 return [] 114 return self.source_translation.translated_address 115 116 @property 117 def translated_dst_address(self) -> typing.List[str]: 118 if not self.destination_translation: 119 return [] 120 translated = self.destination_translation.translated_address 121 if not translated: 122 return [] 123 return [translated] 124 125 @property 126 def members(self): 127 return set( 128 chain( 129 self.to, 130 self.from_, 131 self.sources, 132 self.destination_translation, 133 self.translated_src_address, 134 self.translated_dst_address, 135 ) 136 )
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