Skip to content

Commit b5438da

Browse files
committed
refactor: rename utils to device_utils and adopt camelCase public API
refactor: rename utils to device_utils and adopt camelCase public API Reorganize device utility modules from `mistapi.utils` to `mistapi.device_utils` with a clean separation between internal implementations (`__tools/`) and public-facing device modules (ap, ex, srx, ssr). Public function names now use camelCase (e.g. retrieveArpTable, monitorTraffic) for consistency with the auto-generated REST API. Also adds comprehensive unit tests for api_request, api_response, api_session, models, pagination, logger, init, and websocket_client.
1 parent ff8bf6f commit b5438da

52 files changed

Lines changed: 6283 additions & 633 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 133 additions & 42 deletions
Large diffs are not rendered by default.

src/mistapi/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@
1212

1313
# isort: skip_file
1414
from mistapi.__api_session import APISession as APISession
15-
from mistapi import api as api
16-
from mistapi import cli as cli
17-
from mistapi import websockets as websockets
18-
from mistapi import utils as utils
1915
from mistapi.__pagination import get_all as get_all
2016
from mistapi.__pagination import get_next as get_next
2117
from mistapi.__version import __author__ as __author__
2218
from mistapi.__version import __version__ as __version__
2319

20+
from typing import TYPE_CHECKING
21+
22+
if TYPE_CHECKING:
23+
from mistapi import api as api
24+
from mistapi import cli as cli
25+
from mistapi import device_utils as device_utils
26+
from mistapi import websockets as websockets
27+
2428
_LAZY_SUBPACKAGES = {
2529
"api": "mistapi.api",
2630
"cli": "mistapi.cli",
31+
"websockets": "mistapi.websockets",
32+
"device_utils": "mistapi.device_utils",
2733
}
2834

2935

src/mistapi/api/v1/sites/devices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,7 @@ def getSiteDeviceZtpPassword(
23802380

23812381

23822382
def testSiteSsrDnsResolution(
2383-
mist_session: _APISession, site_id: str, device_id: str
2383+
mist_session: _APISession, site_id: str, device_id: str, body: dict | list
23842384
) -> _APIResponse:
23852385
"""
23862386
API doc: https://www.juniper.net/documentation/us/en/software/mist/api/http/api/utilities/wan/test-site-ssr-dns-resolution
@@ -2402,7 +2402,7 @@ def testSiteSsrDnsResolution(
24022402
"""
24032403

24042404
uri = f"/api/v1/sites/{site_id}/devices/{device_id}/resolve_dns"
2405-
resp = mist_session.mist_post(uri=uri)
2405+
resp = mist_session.mist_post(uri=uri, body=body)
24062406
return resp
24072407

24082408

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
from mistapi.utils import ap, ex, srx, ssr
2222
2323
# Use device-specific utilities
24-
await ap.ping(session, site_id, device_id, host)
25-
await ex.cable_test(session, site_id, device_id, port_id)
26-
await ssr.show_service_path(session, site_id, device_id)
24+
ap.ping(session, site_id, device_id, host)
25+
ex.cableTest(session, site_id, device_id, port_id)
26+
ssr.showServicePath(session, site_id, device_id)
2727
2828
Supported Devices:
2929
- ap: Mist Access Points
@@ -44,26 +44,11 @@
4444
# Device-specific modules (recommended)
4545
# Function-based modules (legacy, still supported)
4646
# Internal modules
47-
from mistapi.utils import (
48-
__ws_wrapper,
47+
from mistapi.device_utils import (
4948
ap,
50-
arp,
51-
bgp,
52-
bpdu,
53-
dhcp,
54-
dns,
55-
dot1x,
5649
ex,
57-
mac,
58-
ospf,
59-
policy,
60-
port,
61-
routes,
62-
service_path,
63-
sessions,
6450
srx,
6551
ssr,
66-
tools,
6752
)
6853

6954
__all__ = [
@@ -72,21 +57,4 @@
7257
"ex",
7358
"srx",
7459
"ssr",
75-
# Function-based modules (legacy)
76-
"arp",
77-
"bgp",
78-
"bpdu",
79-
"dhcp",
80-
"dns",
81-
"dot1x",
82-
"mac",
83-
"ospf",
84-
"policy",
85-
"port",
86-
"routes",
87-
"service_path",
88-
"sessions",
89-
"tools",
90-
# Internal
91-
"__ws_wrapper",
9260
]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
--------------------------------------------------------------------------------
3+
------------------------- Mist API Python CLI Session --------------------------
4+
5+
Written by: Thomas Munzer (tmunzer@juniper.net)
6+
Github : https://github.com/tmunzer/mistapi_python
7+
8+
This package is licensed under the MIT License.
9+
10+
--------------------------------------------------------------------------------
11+
12+
Mist API Utilities
13+
==================
14+
15+
This package provides utility functions for interacting with Mist devices.
16+
17+
Device-Specific Modules (Recommended)
18+
--------------------------------------
19+
Import device-specific modules for a clean, organized API:
20+
21+
from mistapi.utils import ap, ex, srx, ssr
22+
23+
# Use device-specific utilities
24+
ap.ping(session, site_id, device_id, host)
25+
ex.cable_test(session, site_id, device_id, port_id)
26+
ssr.show_service_path(session, site_id, device_id)
27+
28+
Supported Devices:
29+
- ap: Mist Access Points
30+
- ex: Juniper EX Switches
31+
- srx: Juniper SRX Firewalls
32+
- ssr: Juniper Session Smart Routers
33+
34+
Function-Based Modules (Legacy)
35+
---------------------------------
36+
Original organization by function type (still available):
37+
38+
from mistapi.utils import arp, bgp, dhcp, mac, port, routes, tools
39+
40+
Available modules: arp, bgp, bpdu, dhcp, dns, dot1x, mac, policy, port, routes,
41+
service_path, tools
42+
"""

0 commit comments

Comments
 (0)