forked from canonical/charm-relation-interfaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.py
80 lines (66 loc) · 2.05 KB
/
schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""This file defines the schemas for the provider and requirer sides of the `ip_router` interface.
It exposes two interfaces.schema_base.DataBagSchema subclasses called:
- ProviderSchema
- RequirerSchema
Examples:
ProviderSchema:
unit: <empty>
app: {
"networks": [
{
"network": "192.168.250.0/24",
"gateway": "192.168.250.1",
"routes": [
{
"destination": "172.250.0.0/16",
"gateway": "192.168.250.3"
}
]
},
{
"network": "192.168.252.0/24",
"gateway": "192.168.252.1",
},
{
"network": "192.168.251.0/24",
"gateway": "192.168.251.1/24"
}
]
}
RequirerSchema:
unit: <empty>
app: {
"networks": [
{
"network": "192.168.250.0/24",
"gateway": "192.168.250.1",
"routes": [
{
"destination": "172.250.0.0/16",
"gateway": "192.168.250.3"
}
]
}
]
}
"""
from pydantic import BaseModel, IPvAnyAddress, IPvAnyNetwork
from typing import Optional, List
from interface_tester.schema_base import DataBagSchema
class Route(BaseModel):
destination: IPvAnyAddress
gateway: IPvAnyAddress
class IPNetwork(BaseModel):
network: IPvAnyNetwork
gateway: IPvAnyAddress
routes: Optional[List[Route]]
class IPRouterProviderAppData(BaseModel):
networks: List[IPNetwork]
class IPRouterRequirerAppData(BaseModel):
networks: List[IPNetwork]
class ProviderSchema(DataBagSchema):
"""Provider schema for ip_router."""
app: IPRouterProviderAppData
class RequirerSchema(DataBagSchema):
"""Requirer schema for ip_router."""
app: IPRouterRequirerAppData