Coverage for src/otg_mcp/models/router_models.py: 0%

1"""Models for OTG router and API responses."""

2

3 from datetime import datetime

4 from typing import Any, Dict, List, Optional

5

6 from pydantic import BaseModel, Field

7

8

9 class ApiResponse(BaseModel):

10 """Generic API response model."""

11

12 status: str = "success"

13 message: Optional[str] = None

14 data: Optional[Dict[str, Any]] = None

15 timestamp: datetime = Field(default_factory=datetime.now)

16

17

18 class ConfigResponse(BaseModel):

19 """Response model for configuration operations."""

20

21 status: str = "success"

22 config: Dict[str, Any] = Field(default_factory=dict)

23

24

25 class MetricsResponse(BaseModel):

26 """Response model for metrics operations."""

27

28 status: str = "success"

29 metrics: Dict[str, Any] = Field(default_factory=dict)

30

31

32 class CaptureResponse(BaseModel):

33 """Response model for capture operations."""

34

35 status: str = "success"

36 port: Optional[str] = None

37 capture_id: Optional[str] = None

38 data: Optional[Dict[str, Any]] = None

39

40

41 class ControlResponse(BaseModel):

42 """Response model for traffic control operations."""

43

44 status: str = "success"

45 action: Optional[str] = None

46 timestamp: datetime = Field(default_factory=datetime.now)

47

48

49 class TrafficGeneratorStatus(BaseModel):

50 """Status information for all traffic generators."""

51

52 traffic_generators: List[Dict[str, Any]] = Field(default_factory=list)

53 error: Optional[str] = None

54 timestamp: float = Field(default_factory=datetime.now().timestamp)

55

56 @classmethod

57 def create_error_status(cls, error: str) -> "TrafficGeneratorStatus":

58 """Create a status with an error.

59

60 Args:

61 error: Error message

62

63 Returns:

64 TrafficGeneratorStatus with the error

65 """

66 return cls(

67 traffic_generators=[], error=error, timestamp=datetime.now().timestamp()

68 )

69

70 class SnappiError(BaseModel):

71 """Error model for snappi errors."""

72

73 error: str

74 detail: Optional[str] = None

75 code: Optional[int] = None