Skip to content

feat(image): --image accepts name & substring, not just UUID (closes #190)#201

Merged
crowdy merged 2 commits into
mainfrom
fix/issue-190-image-name-resolve
May 9, 2026
Merged

feat(image): --image accepts name & substring, not just UUID (closes #190)#201
crowdy merged 2 commits into
mainfrom
fix/issue-190-image-name-resolve

Conversation

@crowdy
Copy link
Copy Markdown
Owner

@crowdy crowdy commented May 9, 2026

Summary

  • README/sample suggestions like `--image ubuntu-24.04` previously failed because the CLI only accepted UUIDs and the ConoHa3 catalog ships VMI variants (`vmi-docker-29.2-ubuntu-24.04-amd64` etc.) instead of a plain `ubuntu-24.04` entry.
  • New `ImageAPI.FindImage(nameOrID)` resolves UUID → exact-name → unambiguous-substring (case-insensitive) and surfaces a candidate list when the substring is ambiguous.
  • `server create --image` now calls `FindImage` instead of `GetImage`, so the README example finally Just Works when exactly one VMI matches.

Resolution behaviour

Input Result
`12345678-...` (UUID-shaped) direct `GetImage`
`vmi-docker-29.2-ubuntu-24.04-amd64` (exact match) that image
`ubuntu-24.04` matching 2+ VMIs error listing candidates
`centos` matching exactly 1 active image that image
`22.04` matching only `status=killed` not-found
`nonexistent-os` not-found, hint: `conoha image list`

Test plan

  • `go test ./internal/api/... -run Image` — six `TestImageFindImage` subtests cover all five branches plus killed-status filtering
  • `go test ./...` — full suite green
  • Live verify: `conoha server create --image ubuntu-24.04 ...` resolves to the catalog's matching VMI when there's exactly one
  • Live verify: ambiguous case prints the candidate list

Out of scope

This PR does not surface a plain `ubuntu-24.04` base entry in `image list` — that catalog content is owned by ConoHa, not the CLI. The samples README pattern of `--image ubuntu-24.04` will still need an actual matching catalog entry to succeed; this change just makes name-based resolution feasible when one exists.

🤖 Generated with Claude Code

t-kim-planitai and others added 2 commits May 9, 2026 17:43
…190)

ConoHa3's image catalog ships VMI variants (vmi-docker-29.2-ubuntu-...
-amd64 etc.) but no plain ubuntu-24.04, so README/sample suggestions
like '--image ubuntu-24.04' previously failed with the user holding a
36-char UUID requirement.

Add ImageAPI.FindImage(nameOrID):
- UUID-shaped input → GetImage
- Exact name match → that image (regardless of status)
- Single substring match against active image names → that image
- Multiple substring matches → error listing candidates
- No match → "image %q not found, try `conoha image list`"

Substring matching restricts to status=active so we don't surface
half-baked uploads. Plug it into 'server create' so '--image
ubuntu-24.04' resolves automatically when there is exactly one
matching VMI in the user's catalog.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code review of #190 surfaced two consistency gaps:

1. Exact-name match was status-blind: an image stuck in queued/saving/
   killed state could be returned to a caller (e.g. server create) that
   would then fail with an opaque API error mid-flow. Restrict the
   exact-name loop to active images so the error happens at resolution
   time with a clear "not found" instead.

2. FindImage("") fell through to substring matching where strings.Contains
   returns true against every name. A multi-image tenant got an
   "ambiguous" error; a single-image tenant got that one image silently.
   Reject the empty string up front with an actionable hint.

Add image_edgecase_test.go covering: case-insensitive substring,
exact-vs-substring precedence, empty rejection, and the killed-image
guard. Existing TestImageFindImage continues to pass — its "exact name"
case used an active image already.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@crowdy crowdy merged commit 18e6b94 into main May 9, 2026
5 checks passed
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.

2 participants