Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to pydantic v2.1 #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netpalm/backend/core/calls/scriptrunner/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def script_kiddy(**kwargs):

try:
log.debug(f"script_kiddy: attempting to run script {script_path_full_name}")
if not model_is_defined or model_mode is "legacy":
if not model_is_defined or model_mode == "legacy":
result = runscrp(kwargs=arg)
else:
data_to_send = model_to_validate(**kwarg)
Expand Down
10 changes: 5 additions & 5 deletions netpalm/backend/core/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SetConfig(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library":
"napalm",
Expand Down Expand Up @@ -109,7 +109,7 @@ class CacheConfig(BaseModel):
poison: Optional[bool] = False

class Config:
schema_extra = {
json_schema_extra = {
'example': {
'enabled': True,
'ttl': 300,
Expand All @@ -126,7 +126,7 @@ class Script(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"script": "hello_world",
"args": {
Expand All @@ -144,7 +144,7 @@ class ScriptCustom(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"script": "hello_world",
"queue_strategy": "fifo"
Expand All @@ -163,7 +163,7 @@ class GetConfig(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "netmiko",
"connection_args": {
Expand Down
4 changes: 2 additions & 2 deletions netpalm/backend/core/models/napalm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NapalmGetConfig(BaseModel):
cache: Optional[CacheConfig] = {}

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "napalm",
"connection_args": {
Expand All @@ -72,7 +72,7 @@ class NapalmSetConfig(BaseModel):
post_checks: Optional[List[GenericPrePostCheck]] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "napalm",
"connection_args": {
Expand Down
9 changes: 5 additions & 4 deletions netpalm/backend/core/models/ncclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NcclientGetRpcArgs(BaseModel):
capabilities: Optional[bool] = False


class NcclientDeviceDrivers(str):
class NcclientDeviceDrivers(str, Enum):
default = "default"
hpcomware = "hpcomware"
h3c = "h3c"
Expand All @@ -46,6 +46,7 @@ class NcclientDeviceDrivers(str):
class NcclientDeviceParams(BaseModel):
name: NcclientDeviceDrivers


class NcclientManagerParams(BaseModel):
timeout: int

Expand Down Expand Up @@ -74,7 +75,7 @@ class NcclientSetConfig(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "ncclient",
"connection_args": {
Expand Down Expand Up @@ -104,7 +105,7 @@ class NcclientGetConfig(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "ncclient",
"connection_args": {
Expand Down Expand Up @@ -139,7 +140,7 @@ class NcclientGet(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "ncclient",
"connection_args": {
Expand Down
6 changes: 3 additions & 3 deletions netpalm/backend/core/models/netmiko.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NetmikoConnectionArgs(BaseModel):
serial_settings: Optional[str] = None
fast_cli: Optional[bool] = False
session_log: Optional[str] = None
session_log_record_writes = False
session_log_record_writes: Optional[bool] = False
session_log_file_mode: Optional[str] = "write"
allow_auto_change: Optional[bool] = False
encoding: Optional[str] = "ascii"
Expand All @@ -78,7 +78,7 @@ class NetmikoGetConfig(BaseModel):
enable_mode: Optional[bool] = False

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "netmiko",
"connection_args": {
Expand Down Expand Up @@ -114,7 +114,7 @@ class NetmikoSetConfig(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "netmiko",
"connection_args": {
Expand Down
2 changes: 1 addition & 1 deletion netpalm/backend/core/models/puresnmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PureSNMPGetConfig(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "puresnmp",
"connection_args": {
Expand Down
2 changes: 1 addition & 1 deletion netpalm/backend/core/models/restconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Restconf(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"library": "restconf",
"connection_args": {
Expand Down
12 changes: 3 additions & 9 deletions netpalm/backend/core/models/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ServiceModel(BaseModel):
ttl: Optional[int] = None

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"operation": "retrieve",
"args": {
Expand All @@ -52,24 +52,18 @@ class Config:
}
}


# now redundant
class ServiceModelMethods(BaseModel):
operation: ServiceLifecycle
path: Optional[str] = None
payload: dict


# now redundant
class ServiceModelSupportedMethods(BaseModel):
supported_methods: List[ServiceModelMethods] = None

# now redundant
class ServiceModelTemplate(BaseModel):
__root__: List[ServiceModelSupportedMethods]


class ServiceInventorySchema(BaseModel):
service_meta: dict


class ServiceInventoryResponse(BaseModel):
__root__: List[ServiceInventorySchema]
10 changes: 5 additions & 5 deletions netpalm/backend/core/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TaskMetaData(BaseModel):
enqueued_at: Optional[str]
started_at: Optional[str]
ended_at: Optional[str]
enqueued_elapsed_seconds: Optional[str]
total_elapsed_seconds: Optional[str]
enqueued_elapsed_seconds: Optional[int]
total_elapsed_seconds: Optional[int]
assigned_worker: Optional[str]

class TaskError(BaseModel):
Expand Down Expand Up @@ -56,7 +56,7 @@ class Response(BaseModel):
data: TaskResponse

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"status": "success",
"data": {
Expand Down Expand Up @@ -99,7 +99,7 @@ class ServiceResponse(BaseModel):
data: ServiceTaskResponse

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"status": "success",
"data": {
Expand Down Expand Up @@ -133,7 +133,7 @@ class ResponseBasic(BaseModel):

class WorkerResponse(BaseModel):
hostname: Optional[Any] = None
pid: str
pid: int
name: Optional[Any] = None
last_heartbeat: Optional[Any] = None
birth_date: Optional[Any] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class hello_world_model(BaseModel):

class Config:
# add an example payload under the "example" dict
schema_extra = {
json_schema_extra = {
"example": {
"script": "hello_world",
"args": {
Expand Down
2 changes: 1 addition & 1 deletion netpalm/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ filelock
jsonpath_ng
apscheduler==3.6.3
puresnmp==1.9.1
pydantic
pydantic>=2.1
names_generator==0.1.0
2 changes: 1 addition & 1 deletion netpalm/routers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from netpalm.backend.core.confload.confload import config

# load models
from netpalm.backend.core.models.service import ServiceModel, ServiceInventoryResponse
from netpalm.backend.core.models.service import ServiceModel
from netpalm.backend.core.models.task import ServiceResponse, Response, ResponseBasic

from netpalm.backend.core.manager import ntplm
Expand Down
Loading