Skip to content

feat: find_ssh_public_key() utility and MultipassClient.ensure_running() — v0.4.0 - #8

Open
miciav wants to merge 24 commits into
okyanusoz:mainfrom
miciav:main
Open

feat: find_ssh_public_key() utility and MultipassClient.ensure_running() — v0.4.0#8
miciav wants to merge 24 commits into
okyanusoz:mainfrom
miciav:main

Conversation

@miciav

@miciav miciav commented Apr 7, 2026

Copy link
Copy Markdown

Summary

  • find_ssh_public_key() — new src/multipass/utils.py utility that scans ~/.ssh/ for the first available SSH public key (priority: ed25519 → rsa → ecdsa → dsa); returns stripped str or None; exported from the top-level package
  • MultipassClient.ensure_running() — idempotent VM lifecycle method: launches if not found, purges+relaunches if deleted, starts if stopped/suspended, no-ops if already running; accepts the same parameters as launch()
  • v0.4.0 version bump + README documentation for both features, including a combined usage example

Test Plan

  • uv run pytest tests/unit/ -v — 79 tests, 0 failures
  • find_ssh_public_key() returns correct key content, strips whitespace, respects priority order, returns None when no keys or no ~/.ssh/ dir
  • ensure_running() covers all state transitions: not found, running (no-op), stopped, suspended, deleted (purge+launch)
  • ensure_running() forwards all launch params (cpus, memory, disk, image, cloud_init_config)

🤖 Generated with Claude Code

miciav and others added 24 commits April 5, 2026 17:09
- Fix SnapshotInfo.from_snapshots_json to match actual Multipass CLI format
  (nested dict info.{instance}.{snap_name} instead of flat list)
- Fix cpu_count parsing to handle empty string on stopped VMs
- Update integration tests disk size 3G→5G (Ubuntu 22.04 minimum)
- Add 8 new integration test scenarios: resources, suspend/resume,
  file transfer, snapshot/restore, clone, cloud-init, error handling
- Update unit test fixtures to use correct snapshot JSON format

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds cloud_init_config to launch() accepting a dict (serialized to JSON)
or a raw YAML string. Temp files are written to Path.home() instead of
/tmp so Multipass installed via snap can access them. File is deleted
automatically after launch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a new find_ssh_public_key() helper that searches ~/.ssh/ for public
keys in priority order (ed25519, rsa, ecdsa, dsa) and returns the stripped
key string ready for cloud-init ssh_authorized_keys, or None if absent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…thod

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cloud-init requires the user-data file to start with '#cloud-config' to
process it as cloud-config. Using json.dumps() produced JSON without that
header, so cloud-init silently ignored the file and SSH keys were never
injected into the VM's authorized_keys.

Add pyyaml>=6.0 as a dependency and use yaml.dump() to produce valid
cloud-config YAML. Update the test to assert the header is present and
the serialized content parses back correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds exec_structured(argv, *, env, cwd) to MultipassVM. The method builds
the bash prologue (cd + export) from structured parameters internally, so
callers above the SDK never need to construct shell strings.

Bumps version to 0.5.0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… sibling SDKs

- Add VmConfig dataclass for reusable launch configuration (mirrors azure-vm-sdk, proxmox-sdk)
- Add CloudInitConfig dataclass with to_dict() serialization
- Add MultipassClient.launch_many() with parallel launch and rollback
- MultipassClient.launch() now accepts VmConfig or inline params
- Add e2e.py CLI script (multipass-vm-e2e) for lifecycle testing
- Add testing.py module re-exporting FakeBackend
- Enhance CommandBackend protocol and FakeBackend with cwd/env support
- Fix exec_structured() to include set -e for shell safety
- Fix snapshots() to filter by current VM
- Bump version to 0.6.0

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add feature tests: exec_structured, stop/start, restart, transfer,
clone, snapshot/restore. Each is individually skippable via --skip.
Feature tests only run on single-VM mode (--count 1) by default.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…_structured, e2e, testing.py

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant