File tree Expand file tree Collapse file tree 4 files changed +47
-0
lines changed
Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ from yeti_switch_api .orm import PackageCounter , OrmClient
2+
3+ API_ROOT = "http://127.0.0.1:3000/api/rest/admin"
4+ USERNAME = "admin"
5+ PASSWORD = "111111"
6+
7+ config = {
8+ "API_ROOT" : API_ROOT ,
9+ "AUTH_CREDS" : {"login" : USERNAME , "password" : PASSWORD }
10+ }
11+
12+ # Initialize ORM client (registers models)
13+ OrmClient (config )
14+
15+ # Fetch list of package counters
16+ counters = PackageCounter .get_list ()
17+ print (f"Total counters: { len (counters )} " )
18+ for counter in counters :
19+ print (f"ID: { counter .id } , Prefix: { counter .prefix } , Duration: { counter .duration } " )
20+
21+ # Fetch first counter by ID (if any exist)
22+ if counters :
23+ first_id = counters [0 ].id
24+ counter = PackageCounter .find_by_id (first_id )
25+ print ("\n First counter details:" )
26+ print (f"ID: { counter .id } " )
27+ print (f"Attributes: { counter .raw_object .attributes } " )
28+ print (f"Relationships: { counter .raw_object .relationships } " )
29+ else :
30+ print ("No package counters found." )
Original file line number Diff line number Diff line change 2525from .network import Network # noqa: F401
2626from .network_type import NetworkType # noqa: F401
2727from .timezone import Timezone # noqa: F401
28+ from .package_counter import PackageCounter # noqa: F401
Original file line number Diff line number Diff line change 2828from .network import Network
2929from .network_type import NetworkType
3030from .timezone import Timezone
31+ from .package_counter import PackageCounter
3132
3233
3334class OrmClient :
@@ -67,6 +68,7 @@ def __register_models(cls):
6768 cls .__register_model (Network )
6869 cls .__register_model (NetworkType )
6970 cls .__register_model (Timezone )
71+ cls .__register_model (PackageCounter )
7072
7173 @classmethod
7274 def __register_model (cls , model_class ):
Original file line number Diff line number Diff line change 1+ from .base_model import BaseModel , AttributeField , RelationField
2+
3+ class PackageCounter (BaseModel ):
4+ class Meta :
5+ path = "package-counters"
6+ type = "package-counters"
7+
8+ duration = AttributeField ("duration" )
9+ exclude = AttributeField ("exclude" )
10+ prefix = AttributeField ("prefix" )
11+ service_id = AttributeField ("service-id" )
12+
13+ account = RelationField ("account" )
14+ service = RelationField ("service" )
You can’t perform that action at this time.
0 commit comments