Metadata-Version: 2.4
Name: exordos_metapaas
Version: 1.3.3
Summary: MetaPaaS runtime for Exordos Core — single control-plane hosting many PaaS types as plugins
Author-email: Genesis Corporation <mail@gmelikov.ru>
License: Apache-2.0
Project-URL: homepage, https://github.com/exordos/exordos_metapaas/
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: oslo.config<10.0.0,>=3.22.2
Requires-Dist: restalchemy<17.0.0,>=16.0.1
Requires-Dist: gcl_iam<2.0.0,>=1.4.0
Requires-Dist: gcl_sdk<4.0.0,>=3.7.7
Requires-Dist: gcl_looper<2.0.0,>=1.3.2
Requires-Dist: bjoern>=3.2.2
Requires-Dist: PyYAML<7.0.0,>=6.0.0
Requires-Dist: requests<3.0.0,>=2.28.0
Provides-Extra: dev
Requires-Dist: tox>=4.0.0; extra == "dev"
Requires-Dist: tox-uv; extra == "dev"
Requires-Dist: pytest>=7.0.0; extra == "dev"
Provides-Extra: test
Requires-Dist: coverage>=4.0; extra == "test"
Requires-Dist: pytest<10.0.0,>=8.0.0; extra == "test"
Requires-Dist: pytest-timer<2.0.0,>=1.0.0; extra == "test"
Requires-Dist: mock<6.0.0,>=3.0.5; extra == "test"
Provides-Extra: ruff
Requires-Dist: ruff; extra == "ruff"
Provides-Extra: mypy
Requires-Dist: mypy; extra == "mypy"

# Exordos MetaPaaS

**Single control-plane runtime hosting many PaaS types as installable plugins.**

Instead of deploying a new VM + database for each PaaS service (s3, mail, database, etc.), MetaPaaS runs one shared control-plane that manages them all. A new PaaS is an installable plugin, not a new control-plane node — only data-plane instances are launched per service instance.

## Quick Start

### Build

```bash
make build
# Produces: output/exordos-metapaas.raw.zst, output/manifests/metapaas.yaml
```

### Install to Exordos Core

```bash
exordos -e http://10.20.0.2:11010 -u admin -p <password> \
  ee install metapaas --version <version>
```

The element is resolved by name across the repositories registered in the
core (the official one is registered at bootstrap). To install from another
repository (e.g. a local mirror), register it first with a higher priority:

```bash
exordos -e http://10.20.0.2:11010 -u admin -p <password> \
  repo add -p <project-uuid> -n local-mirror \
  --repo-url http://10.20.0.1:8081/exordos-elements/ --priority 4096
```

### Create a PaaS Instance

Once metapaas is deployed, install a plugin (e.g., s3aas):

```bash
exordos -e http://10.20.0.2:11010 -u admin -p <password> \
  ee install s3aas --version 0.0.5
```

Then create an instance via the metapaas-cp REST API:

```bash
curl -X POST http://metapaas-cp:8080/v1/types/s3/instances \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <token>' \
  -d '{
    "name": "s3-prod",
    "version": "0.0.1",
    "bucket_name": "data",
    "encryption": "aes256"
  }'
```

## Documentation

### For Platform Users
- **[DESIGN.md](DESIGN.md)** — Architecture, why this approach, solved decisions

### For PaaS Plugin Developers
- **[HOW_TO_BUILD_NEW_PAAS.md](HOW_TO_BUILD_NEW_PAAS.md)** — Complete guide: 9 steps from architecture to deployment
  - Control Plane (CP): SQLAlchemy models, REST controllers, IAM setup
  - Data Plane (DP): Packer image config, health checks, systemd units
  - Build config, manifest template, tests, CI/CD
  - Examples: mail-aas (Postfix+Dovecot), database-aas patterns
  - Checklist + troubleshooting

### Reference Plugins
- **[../exordos_s3/](../exordos_s3/)** — Production s3aas plugin (validated, fully featured)
- **[../exordos_mail/](../exordos_mail/)** — Blueprint mail-aas plugin (validates framework is service-agnostic)
- **[./metapaas_demo/](./metapaas_demo/)** — Demo plugin (bundled in runtime, minimal example)

## Architecture

```
exordos_core (user-facing)
    ↓
exordos_metapaas-cp (single shared control-plane)
    ├─ user-api       (REST endpoints: /v1/types/<slug>/instances)
    ├─ orch-api       (orchestration, node lifecycle)
    ├─ status-api     (monitoring, node status)
    └─ PostgreSQL     (shared database for all plugins)
        ├─ s3_instances, s3_buckets, ...
        ├─ mail_instances, mail_users, ...
        └─ plugin_migrations (each plugin versions independently)
    ↓
data-plane nodes (s3-dp, mail-dp, db-dp, ...)
    ↓
actual services (RustFS, Postfix, PostgreSQL, ...)
```

**Key insight:** Plugin = pip package with CP code + manifest + DP image. No new CP VM, no new database — just install and go.

## Building Your First Plugin

1. **Read** [HOW_TO_BUILD_NEW_PAAS.md](HOW_TO_BUILD_NEW_PAAS.md)
2. **Copy** structure from [../exordos_mail/](../exordos_mail/) (simple, well-commented)
3. **Follow** the 9 steps: models → controllers → IAM → DP image → manifest → build → tests
4. **Validate** against the checklist
5. **Deploy** and test

## Development

### API reload

All three APIs use a supervisor that preloads a fresh generation and forks its
workers. `systemctl reload` waits for the replacement result. In development,
send SIGHUP directly or enable the Python source watcher.
The reload supervisor requires `gcl_looper` 1.3.2 or newer. Install the
published dependency in the development environment:

```bash
uv venv .venv
uv pip install --python .venv/bin/python -e '.[dev]'
.venv/bin/exordos-metapaas-user-api --config-file ./dev.conf --user_api-autoreload
```

Autoreload is disabled by default. Enable it to watch local application sources
and installed editable projects (including SDKs and lazily imported plugins):

```ini
[user_api]
workers = 1
autoreload = true
```

Use the same options under `[status_api]` or `[orch_api]` for those services.
The watcher in `ReloadableProcessHubService` polls `.py` timestamps with
nanosecond precision once per second,
including on container mounts. No source paths are required. Install plugins in
editable mode so discovery includes their repositories and replacement generations
import the edited code. Use `reload-dirs` only for additional source directories;
hidden directories, virtual environments and build outputs are skipped.
A failed replacement leaves the current generation serving; correcting the source
triggers another attempt. Watch settings are read at startup; restart the supervisor
after changing them. The watcher uses only the standard library and adds no
threads or processes. A production wheel requires a published supervisor-enabled
`gcl_looper` satisfying the dependency bound; uv source overrides are not embedded
in wheels.

### Unit Tests

```bash
tox -e py312
```

### Linting & Type Checking

```bash
tox -e ruff-check
tox -e mypy
```

### Full Test Matrix

```bash
tox
```

## Plugin Installation Mechanism

When a PaaS element is installed in exordos_core:

1. **PluginReconciler** (running on metapaas-cp) detects new element
2. **Fetches** the CP wheel from the pip index (registry URL from element spec)
3. **Installs** wheel on metapaas-cp with `pip install --upgrade`
4. **Discovers** the plugin via entry-point: `[project.entry-points."exordos_metapaas.plugins"]`
5. **Registers** REST routes, models, migrations
6. **Applies** any pending database migrations (cross-project safe via UUID-keyed tracking)
7. **Reloads** metapaas-cp services to pick up new routes

Data-plane nodes are provisioned per instance as the plugin's CP controllers orchestrate them.

## Troubleshooting

### Plugin not appearing in API

Check PluginReconciler logs on metapaas-cp:

```bash
exordos -e http://10.20.0.2:11010 -u admin -p <pass> \
  cn exec metapaas-cp -- \
  journalctl -u metapaas-plugin-reconciler -f
```

### Cannot create instance

Verify metapaas-cp is reachable and user has credentials:

```bash
curl -s http://metapaas-cp:8080/v1/types/ -H 'Authorization: Bearer <token>' | jq .
```

### Data-plane nodes stuck in CREATING

Check orchestration (orch-api) and agent logs on metapaas-cp:

```bash
exordos -e http://10.20.0.2:11010 -u admin -p <pass> \
  cn exec metapaas-cp -- \
  tail -f /var/log/orch-api.log
```

## Standards

- **Python:** 3.10+
- **Testing:** pytest, tox, coverage
- **Code style:** ruff (fmt + check), mypy
- **Database:** SQLAlchemy 2.0+, PostgreSQL 13+
- **Container format:** Packer → Zstandard-compressed raw image

## License

Proprietary — Exordos
