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: BaseModel

MTConnect Adapter Schema.

deploy: Optional[Deploy]#
environment: Optional[List[str]]#
image: Optional[str]#
ip: Optional[str]#
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

port: int#
classmethod set_deploy_defaults(values)[source]#

Ensures deploy is set and deploy.replicas has default value 1 if missing.

Return type:

Adapter

Parameters:

values (Adapter) – Adapter instance after initial validation.

Returns:

Adapter – Adapter instance with defaults set.

classmethod validate_adapter(values)[source]#

Validates the adapter configuration.

Return type:

Dict

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: BaseModel

MTConnect Agent Schema.

adapter: Optional[Adapter]#
deploy: Optional[Deploy]#
device_xml: Optional[str]#
ip: Optional[str]#
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

port: int#
classmethod set_deploy_defaults(values)[source]#

Sets default deployment configuration values after model initialization.

Return type:

Agent

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:

Dict

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: BaseModel

MTConnect 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.

agent: Agent#
model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

type: Literal['mtconnect']#