Skip to content

Collapse ApiCustomVmRequest onto the shared CustomVmSpec #338

Description

@v0l

lnvps_api_common::CustomVmSpec (lnvps_api_common/src/model.rs:741-802) and ApiCustomVmRequest (lnvps_api/src/api/model.rs:747-791) are two wire types for the same custom-VM body, each with its own conversion to VmCustomTemplate. Two conversions for one shape will drift.

Collapse the customer one onto CustomVmSpec: POST /api/v1/vm/custom-template deserializes CustomVmSpec and calls to_template(), and the From<ApiCustomVmRequest> for VmCustomTemplate impl goes away (~45 lines).

This also fixes silent defaulting on the customer path. Today ApiCustomVmRequest uses filter_map(|s| s.parse().ok()) for cpu_feature and unwrap_or_default() for cpu_mfg/cpu_arch (lnvps_api/src/api/model.rs:768-787), so a typo'd cpu_arch becomes "any" and the customer gets a machine they did not ask for. CustomVmSpec::to_template() errors instead, which the route should surface as a 400.

Behaviour change to call out: requests that today succeed with a misspelled enum value would start failing with 400. Worth a note in API_CHANGELOG.md, and Marta should know if the site ever sends anything other than the exact enum spellings.

Found in review of #335 / PR 337.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiUser-facing or admin API changesrefactorInternal restructuring without behaviour change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions