feat(managed-database): add network update support to edit command - #283
Merged
Merged
Conversation
Add --network-id and --subnet-id flags to the managed-database edit command, enabling in-place network switching between public and private networks. Usage: - Switch to private: --network-id <uuid> --subnet-id <uuid> - Switch to public: --network-id none --subnet-id none Network updates are sent as a separate PUT request to properly handle null values for the public network switch, since the OpenAPI spec filter in EditResource strips network fields. Signed-off-by: Achraf Hammouda <achraf.hammouda@ovhcloud.com>
AchrafHammouda
force-pushed
the
feat/network-update
branch
from
September 7, 2026 14:45
778b80e to
f58c4a8
Compare
amstuta
reviewed
Sep 21, 2026
- Inject network fields into EditResource via extraFields parameter instead of a separate PUT call - Replace --network-id none / --subnet-id none with --public-network flag, mutually exclusive with --network-id and --subnet-id - Add extraFields variadic parameter to common.EditResource to allow injecting fields that bypass the OpenAPI spec filter Signed-off-by: Achraf Hammouda <achraf.hammouda@ovhcloud.com>
amstuta
reviewed
Sep 21, 2026
| display.OutputError(&flags.OutputFormatConfig, "%s", err) | ||
| return | ||
| // Build extra network fields that bypass the OpenAPI filter | ||
| var networkFields map[string]any |
Contributor
There was a problem hiding this comment.
I don't get why you create an extra map of fields instead of using ManagedDatabaseSpec.CLIPublicNetwork to fill ManagedDatabaseSpec.NetworkID and ManagedDatabaseSpec.SubnetID ?
Contributor
Author
There was a problem hiding this comment.
The extraFields approach is needed for two reasons:
- OpenAPI filter strips networkId/subnetId — EditResource calls FilterEditableFields which removes any field not declared in the PUT schema. Even if we set ManagedDatabaseSpec.NetworkID and .SubnetID directly, they get filtered out before the PUT request is sent. The extraFields parameter injects them after the filter, in a single PUT call.
- null vs empty string — When switching to public network, the API expects "networkId": null. But NetworkID is a Go string with omitempty — an empty string is omitted from the JSON entirely, not serialized as null. The map[string]any with nil values is the only way to produce proper JSON null.
Contributor
There was a problem hiding this comment.
For your point 1), I don't see why the API-accepted fields would be dropped before the request is sent, we already do this kind of thing here: https://github.com/ovh/ovhcloud-cli/blob/main/internal/services/cloud/cloud_managed_database.go#L235
Anyway, your solution works even if I'm not a big fan of the code, so I'll merge it.
amstuta
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(managed-database): add network update support to edit command
Description
Add
--network-id,--subnet-id, and--public-networkflags to themanaged-database editcommand, enabling in-place network switching between public and private networks.Usage:
--network-id <uuid> --subnet-id <uuid>--public-networkThe
--public-networkflag is mutually exclusive with--network-idand--subnet-id.Network fields are injected into the
EditResourcebody via a newextraFieldsvariadic parameter, bypassing the OpenAPI spec filter in a single PUT call.Changes:
--network-id,--subnet-id, and--public-networkflags to the edit commandextraFieldsvariadic parameter tocommon.EditResourceto inject fields after the OpenAPI filterHow Has This Been Tested?
Manually tested against a live PostgreSQL production cluster on OVH EU:
--network-id <uuid> --subnet-id <uuid>) — cluster switched to private successfully--public-network) — cluster switched to public successfully--public-network --network-id <uuid>) — properly rejected by cobra--description "...") — no network change triggered--description "...") — no network change triggeredType of change
Checklist:
go mod tidy