Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tenant control-plane URL (no trailing path required)
ZEDCLOUD_BASE_URL=https://zedcontrol.zededa.net

# Session / API token — sent as Authorization: Bearer <token>
ZEDCLOUD_TOKEN=

# Optional; Kubernetes/ZKS service also accepts X-API-KEY (defaults to ZEDCLOUD_TOKEN)
# ZEDCLOUD_API_KEY=

# Optional tuning
# ZEDCLOUD_TIMEOUT=30
# ZEDCLOUD_MAX_RETRIES=3
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Sync workspace
run: uv sync --all-packages --group dev

- name: Verify OpenAPI codegen is current
run: |
uv run python scripts/generate_from_openapi.py
git diff --exit-code -- packages/zedcloud/src/zedcloud/_generated

- name: Ruff
run: |
uv run ruff check packages scripts
uv run ruff format --check packages scripts

- name: Unit tests
run: uv run pytest -q -m "not needs_cloud"

- name: MCP tool list
run: uv run python -c "from zedcloud_mcp.server import list_tool_names; print(list_tool_names())"
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Byte-compiled / cache
__pycache__/
*.py[cod]
*$py.class
*.egg-info/
.eggs/
dist/
build/
.pytest_cache/
.ruff_cache/
.mypy_cache/
.coverage
htmlcov/

# Virtualenvs / uv
.venv/
uv.lock.bak

# Secrets & local env
.env
.env.*
!.env.example
*.pem
*.key

# Editors / OS
.DS_Store
.idea/
.vscode/

# Generated scratch
/tmp/
*.oa3.json
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 vignesh-zededa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY: generate install test lint mcp-list sync

UV ?= uv

sync:
$(UV) sync --all-packages --group dev

generate:
$(UV) run python scripts/generate_from_openapi.py

install: sync generate

test:
$(UV) run pytest -q -m "not needs_cloud"

lint:
$(UV) run ruff check packages scripts
$(UV) run ruff format --check packages scripts

format:
$(UV) run ruff format packages scripts
$(UV) run ruff check --fix packages scripts

mcp-list:
$(UV) run python -c "from zedcloud_mcp.server import list_tool_names; print('\n'.join(list_tool_names()))"
179 changes: 177 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,177 @@
# zedcloud-sdk
Python SDK, automation framework, and MCP server for ZEDEDA Zedcloud APIs
# Zedcloud Python SDK

Typed Python client, pytest automation helpers, and MCP server for
[ZEDEDA Zedcloud](https://zededa.com/) control-plane APIs.

OpenAPI specs are committed under [`openapi/`](openapi/) (mirrors of the
Swagger UI at `https://zedcontrol.zededa.net/api/v1/docs/`).

## Packages

| Package | Description |
|---------|-------------|
| [`zedcloud`](packages/zedcloud) | Typed sync SDK (`httpx` + Pydantic v2) |
| [`zedcloud-automation`](packages/zedcloud-automation) | Pytest fixtures, markers, resource cleanup |
| [`zedcloud-mcp`](packages/zedcloud-mcp) | MCP server (stdio) exposing high-value tools |

## Requirements

- Python 3.10+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip

## Install

```bash
# clone
git clone https://github.com/vignesh-zededa/zedcloud-sdk.git
cd zedcloud-sdk

# workspace (SDK + automation + MCP + dev tools)
uv sync --all-packages --group dev

# regenerate models/services from openapi/*.swagger.json
uv run python scripts/generate_from_openapi.py
# or: make generate
```

Editable install of just the SDK:

```bash
uv pip install -e packages/zedcloud
# or: pip install -e packages/zedcloud
```

## Auth

Copy [`.env.example`](.env.example) and export:

```bash
export ZEDCLOUD_BASE_URL=https://zedcontrol.zededa.net
export ZEDCLOUD_TOKEN=YOUR_SESSION_TOKEN
# optional — Kubernetes/ZKS also sends X-API-KEY (defaults to the bearer token)
# export ZEDCLOUD_API_KEY=…
```

Most services use `Authorization: Bearer <token>`. The Kubernetes / ZKS service
uses `ApiKeyAuth` (`X-API-KEY`); the client sends both headers for that namespace.

## SDK quickstart

```python
from zedcloud import ZedcloudClient
from zedcloud.pagination import collect_all

with ZedcloudClient.from_env() as client:
apps = client.apps.query_edge_application_bundles(next_page_size=25, summary=True)
for app in apps.list_ or []: # OpenAPI field ``list`` is exposed as ``list_``
print(app.id, app.name)

nodes = collect_all(client.nodes.query_edge_nodes, page_size=50, summary=True)
print(f"{len(nodes)} nodes")

# Kubernetes / ZKS (ApiKeyAuth)
clusters = client.k8s.list_zks_instances()
```

Service namespaces map to OpenAPI specs:

`apps`, `nodes`, `networks`, `iam`, `k8s`, `storage`, `jobs`, `orchestration`,
`diag`, `app_profiles`, `node_clusters`.

Methods are generated from swagger `operationId` values (snake_case). Each
method docstring includes the HTTP verb/path.

## Codegen

```bash
make generate
# equivalent:
uv run python scripts/generate_from_openapi.py
```

Pipeline:

1. Convert each Swagger 2.0 `definitions` map → OpenAPI 3 `components/schemas`
2. Run `datamodel-code-generator` → Pydantic v2 models
3. Emit typed service wrappers under `zedcloud._generated.services`

Do not hand-edit `_generated/`; change swagger or the generator script instead.

## Automation

```bash
# mocked / offline unit tests
uv run pytest -q -m "not needs_cloud"

# live read-only smoke (requires credentials)
uv run pytest -q -m "smoke and needs_cloud"
```

Fixtures (`zedcloud_client`, `resource_tracker`) are registered via the
`zedcloud-automation` pytest plugin.

## MCP server

```bash
uv run zedcloud-mcp
```

Focused tools (not the full ~470 endpoints): nodes, apps, networks, ZKS/k8s, jobs.

### Cursor

Add to MCP settings (`.cursor/mcp.json` or Cursor Settings → MCP):

```json
{
"mcpServers": {
"zedcloud": {
"command": "uv",
"args": ["run", "--directory", "/absolute/path/to/zedcloud-sdk", "zedcloud-mcp"],
"env": {
"ZEDCLOUD_BASE_URL": "https://zedcontrol.zededa.net",
"ZEDCLOUD_TOKEN": "YOUR_SESSION_TOKEN"
}
}
}
}
```

### Claude Desktop

```json
{
"mcpServers": {
"zedcloud": {
"command": "uv",
"args": ["run", "--directory", "/absolute/path/to/zedcloud-sdk", "zedcloud-mcp"],
"env": {
"ZEDCLOUD_BASE_URL": "https://zedcontrol.zededa.net",
"ZEDCLOUD_TOKEN": "YOUR_SESSION_TOKEN"
}
}
}
}
```

List tools without starting a session:

```bash
make mcp-list
```

## Development

```bash
make sync # uv sync --all-packages --group dev
make generate # regenerate from openapi/
make test # unit tests (skips needs_cloud)
make lint # ruff
```

CI (`.github/workflows/ci.yml`) runs lint, verifies codegen is clean, and executes
mocked unit tests on Python 3.10 and 3.12.

## License

MIT — see [LICENSE](LICENSE).
38 changes: 38 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Architecture

```
openapi/*.swagger.json # committed Swagger 2.0 specs (11 services)
│
▼
scripts/generate_from_openapi.py
│
├─► zedcloud._generated.models.* # Pydantic v2 models
└─► zedcloud._generated.services.* # typed method wrappers
│
▼
ZedcloudClient
├── apps / nodes / networks / …
└── k8s (ApiKeyAuth transport)
│
┌───────┴────────┐
▼ ▼
zedcloud-automation zedcloud-mcp
(pytest fixtures) (stdio MCP tools)
```

## Auth

| Mechanism | Header | Used by |
|-----------|--------|---------|
| BearerToken | `Authorization: Bearer <token>` | All services except Kubernetes |
| ApiKeyAuth | `X-API-KEY: <key>` | `zedge_kubernetes_service` |

`ZedcloudClient` keeps two transports sharing one `httpx.Client`. The k8s
namespace sends both headers (API key defaults to the bearer token).

## Pagination

List endpoints commonly accept `next.pageToken`, `next.pageNum`,
`next.pageSize`, `next.totalPages` and return a `next` Cursor plus a `list`
array. Use `zedcloud.pagination.iter_pages` / `collect_all` with any generated
query method.
16 changes: 16 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Getting started

1. Install [uv](https://docs.astral.sh/uv/).
2. `uv sync --all-packages --group dev`
3. `make generate` (if `_generated` is missing or specs changed)
4. Copy `.env.example` → export `ZEDCLOUD_BASE_URL` and `ZEDCLOUD_TOKEN`
5. Try:

```python
from zedcloud import ZedcloudClient

with ZedcloudClient.from_env() as c:
print(c.apps.query_edge_application_bundles(next_page_size=5, summary=True))
```

See the root [README](../README.md) for MCP config and automation markers.
Loading
Loading