File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ uv tool install 'datamodel-code-generator[http]'
99To generate a model:
1010
1111``` bash
12+ # core
13+ datamodel-codegen --url https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/core/core.json \
14+ --output-model-type pydantic_v2.BaseModel \
15+ --use-annotated \
16+ --enum-field-as-literal all \
17+ --output models/core.py
18+
1219# interfaces
1320datamodel-codegen --url https://raw.githubusercontent.com/eda-labs/openapi/refs/heads/main/apps/interfaces.eda.nokia.com/v1alpha1/interfaces.json \
1421--output-model-type pydantic_v2.BaseModel \
Original file line number Diff line number Diff line change 66 Metadata ,
77 SpecModel ,
88)
9+ from src .banner import banner
910from src .client import Client
1011
1112logging .basicConfig (
@@ -19,6 +20,10 @@ def main():
1920 c .auth ()
2021 logger .info (f"Access Token: { c .token } " )
2122
23+ my_banner = banner ("This is a test banner" )
24+ # print(my_banner.model_dump())
25+ c .add_to_transaction_create (my_banner )
26+
2227 # iface = Interface(
2328 # apiVersion="interfaces.eda.nokia.com/v1alpha1",
2429 # kind="Interface",
Original file line number Diff line number Diff line change 1- def set_banner (banner ):
1+ from models .com .nokia .eda .siteinfo .v1alpha1 import Banner , Metadata , Spec
2+
3+
4+ def banner (motd_text : str ) -> Banner :
25 """
3- Set the banner for the SSH session.
6+ Create a banner
47 """
8+
9+ banner = Banner (
10+ apiVersion = "siteinfo.eda.nokia.com/v1alpha1" ,
11+ kind = "Banner" ,
12+ metadata = Metadata (
13+ name = "banner" ,
14+ namespace = "clab-vlan" ,
15+ labels = {"app" : "banner" },
16+ ),
17+ spec = Spec (
18+ motd = motd_text ,
19+ ),
20+ )
21+
22+ return banner
Original file line number Diff line number Diff line change 1+ from typing import Any , Optional
2+
13import httpx
4+ from pydantic import BaseModel
5+
6+ from models .com .nokia .eda .siteinfo .v1alpha1 import Banner
7+ from models .core import (
8+ Transaction ,
9+ TransactionContent ,
10+ TransactionCr ,
11+ TransactionType ,
12+ TransactionValue ,
13+ )
214
315EDA_VERSION = "v24.12.1"
416
@@ -15,11 +27,31 @@ def __init__(self, base_url: str):
1527 self .base_url = base_url
1628 self .kc_url = f"{ self .base_url } /core/httpproxy/v1/keycloak/"
1729 self .token = ""
30+ self .transaction : Optional [Transaction ] = None
1831
1932 def auth (self ) -> None :
2033 """Authenticate and get access token"""
2134 self .token = _get_access_token (self )
2235
36+ def add_to_transaction_create (self , resource : BaseModel ) -> None :
37+ """Add resource to transaction"""
38+ content = TransactionContent (
39+ ** resource .model_dump (exclude_unset = True , exclude_defaults = True )
40+ )
41+
42+ if self .transaction is None :
43+ self .transaction = Transaction (
44+ crs = [
45+ TransactionCr (
46+ type = TransactionType (create = TransactionValue (value = content ))
47+ )
48+ ],
49+ description = "" ,
50+ dryRun = False ,
51+ )
52+ # else:
53+ # self.transaction.resources.append(resource)
54+
2355
2456def _get_client_secret (kc_url : str ) -> str :
2557 with httpx .Client (verify = False ) as client :
You can’t perform that action at this time.
0 commit comments