Skip to content

Commit 7bd63d9

Browse files
Merge pull request #11 from Ivanov-Anton/package-counters-entity
add package-counters entity for Admin API client
2 parents da9c727 + e528cb3 commit 7bd63d9

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

examples/package_counters.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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("\nFirst 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.")

yeti_switch_api/orm/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
from .network import Network # noqa: F401
2626
from .network_type import NetworkType # noqa: F401
2727
from .timezone import Timezone # noqa: F401
28+
from .package_counter import PackageCounter # noqa: F401

yeti_switch_api/orm/orm_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .network import Network
2929
from .network_type import NetworkType
3030
from .timezone import Timezone
31+
from .package_counter import PackageCounter
3132

3233

3334
class 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):
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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")

0 commit comments

Comments
 (0)