Mtconnect Connector Schemas#
MTConnect Connector Schemas
This module provides Pydantic models to define and validate configuration schemas for MTConnect adapters and agents within OpenFactory.
Key Models:#
Adapter: Configuration for MTConnect adapters, supporting either direct IP-based connection or container image deployment. Validates that exactly one of ip or image is specified and applies deployment defaults.
Agent: Configuration for MTConnect agents, which may be external (specified by ip) or embedded with an Adapter and device XML file. Validates the correct mutual exclusivity and presence of ip, device_xml, and adapter fields.
MTConnectConnectorSchema: Wrapper schema with a discriminator type=’mtconnect’ that encapsulates the Agent configuration.
Validation Features:#
Ensures mutual exclusivity of critical fields (ip vs. image for adapters; ip vs. adapter and device_xml for agents).
Provides default deployment settings (deploy.replicas = 1) if unspecified.
Forbids unknown fields to ensure strict schema conformance.
YAML Example:#
type: mtconnect
agent:
port: 7878
device_xml: /path/to/device.xml
adapter:
ip: 192.168.0.201
port: 7879
See also
The runtime class of the MTConnect schema is openfactory.connectors.mtconnect.mtc_connector.MTConnectConnector.
- class openfactory.schemas.connectors.mtconnect.Adapter(**data)[source]#
Bases:
BaseModelMTConnect Adapter Schema.
- model_config = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- set_deploy_defaults()[source]#
Ensures deploy is set and deploy.replicas has default value 1 if missing.
- classmethod validate_adapter(values)[source]#
Validates the adapter configuration.
- Return type:
- Parameters:
values (Dict) – Dictionary of values to validate.
- Returns:
Dict – Validated values.
- Raises:
ValueError – If ‘ip’ or ‘image’ is missing or incorrectly defined.
Note
Either ‘ip’ or ‘image’ must be specified, but not both.
- class openfactory.schemas.connectors.mtconnect.Agent(**data)[source]#
Bases:
BaseModelMTConnect Agent Schema.
- model_config = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- set_deploy_defaults()[source]#
Sets default deployment configuration values after model initialization.
- Return type:
- Parameters:
values (Agent) – The Agent instance after initial validation.
- Returns:
Agent – The Agent instance with default values set for deploy if missing.
Notes
If ‘deploy’ is None, it will be set to a Deploy instance with replicas=1.
If ‘deploy’ exists but ‘replicas’ is None, replicas will be set to 1.
- classmethod validate_agent(values)[source]#
Validates the agent configuration.
- Return type:
- Parameters:
values (Dict) – Dictionary of values to validate.
- Returns:
Dict – Validated values.
- Raises:
ValueError – If ‘device_xml’ or ‘adapter’ is missing or incorrectly defined.
Note
If ‘ip’ is None, both ‘device_xml’ and ‘adapter’ must be defined.
If ‘ip’ is set, ‘device_xml’ and ‘adapter’ must NOT be defined.
- class openfactory.schemas.connectors.mtconnect.MTConnectConnectorSchema(**data)[source]#
Bases:
BaseModelMTConnect Connector schema that wraps the Agent configuration.
The type field is a discriminator for Pydantic to select this schema.
See also
The runtime class of the MTConnect schema is
openfactory.connectors.mtconnect.mtc_connector.MTConnectConnector.- model_config = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].