Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Each command directory has its own `CLAUDE.md` (domain knowledge) and `README.md
| `cmd/update/` | CLAUDE.md, README.md | CLI self-update |
| `cmd/settings/` | CLAUDE.md, README.md | CLI settings management |
| `cmd/objectstorage/` | CLAUDE.md, README.md | S3-style object storage: configure, mb/rb, cp/mv/sync/ls/rm, uploads, presign |
| `cmd/network/` | CLAUDE.md, README.md | Private networks (beta): list, create, delete; subnet list, create, delete |
| `cmd/serverless/` | CLAUDE.md, README.md | Serverless containers (beta: create, list, describe, scale, replicas, pause/resume/restart, purge-queue, delete) and batch jobs (hidden, gated by `VERDA_BATCHJOB_ENABLED`) |
| `cmd/doctor/` | — | Environment diagnostics |
| `cmd/availability/` | — | Instance availability by location |
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/verda-cloud/verda-cli

go 1.26.10
go 1.26.11

require (
charm.land/lipgloss/v2 v2.0.2
github.com/dustinkirkland/golang-petname v0.0.0-20260215035315-f0c533e9ce9b
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/spf13/viper v1.21.0
github.com/verda-cloud/verdacloud-sdk-go v1.7.1
go.yaml.in/yaml/v3 v3.0.4
github.com/verda-cloud/verdacloud-sdk-go v1.9.0
go.yaml.in/yaml/v3 v3.0.5
)

require (
Expand Down Expand Up @@ -93,13 +93,14 @@ require (
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
go.opentelemetry.io/otel v1.45.0 // indirect
go.opentelemetry.io/otel/metric v1.45.0 // indirect
go.opentelemetry.io/otel/sdk v1.45.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.45.0 // indirect
go.opentelemetry.io/otel/trace v1.45.0 // indirect
go.opentelemetry.io/otel v1.47.0 // indirect
go.opentelemetry.io/otel/log v1.47.0 // indirect
go.opentelemetry.io/otel/metric v1.47.0 // indirect
go.opentelemetry.io/otel/sdk v1.47.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.47.0 // indirect
go.opentelemetry.io/otel/trace v1.47.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/sys v0.48.0 // indirect
golang.org/x/text v0.41.0 // indirect
)
40 changes: 20 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ github.com/containerd/stargz-snapshotter/estargz v0.18.2 h1:yXkZFYIzz3eoLwlTUZKz
github.com/containerd/stargz-snapshotter/estargz v0.18.2/go.mod h1:XyVU5tcJ3PRpkA9XS2T5us6Eg35yM0214Y+wvrZTBrY=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
Expand Down Expand Up @@ -149,7 +148,6 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down Expand Up @@ -181,14 +179,15 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/vbatts/tar-split v0.12.2 h1:w/Y6tjxpeiFMR47yzZPlPj/FcPLpXbTUi/9H7d3CPa4=
github.com/vbatts/tar-split v0.12.2/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA=
github.com/verda-cloud/verdacloud-sdk-go v1.7.1 h1:rgYBNMWSJ9IZsZspdQF0TvWBXB2Td2v00d07TJqstCA=
github.com/verda-cloud/verdacloud-sdk-go v1.7.1/go.mod h1:1APG3X5TXhXpUp1dhgemElaj/6bw+OaKeQ+Ze/0/Cyc=
github.com/verda-cloud/verdacloud-sdk-go v1.9.0 h1:uKFMwgpHRheKurx0ANhxAsUe21znJn68ndN/MkpH/SQ=
github.com/verda-cloud/verdacloud-sdk-go v1.9.0/go.mod h1:va7s1wnZpFCqY/WVFxuUb66FpJzXgqHBYEWtEJTWx8o=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
Expand All @@ -197,39 +196,40 @@ go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q=
go.opentelemetry.io/otel v1.45.0 h1:pdrWmLHofpubmArBv1LgFSv1Z0Ie/ppdZzu+kUN5EeU=
go.opentelemetry.io/otel v1.45.0/go.mod h1:XZxIqPapzEYnhNSScF5DIqXhm/rYi0FzCe2XddAwZfQ=
go.opentelemetry.io/otel/metric v1.45.0 h1:7Eg1uH7CJ5cXv9is6tnBe1FI6rj1nwUdbFypRm3br/M=
go.opentelemetry.io/otel/metric v1.45.0/go.mod h1:HAPbm1nd3p1PmFH7v2dR+6BjXxw+Lq4a2+pndMAm08s=
go.opentelemetry.io/otel/sdk v1.45.0 h1:4VVSMgQ83dUgW2aoX5f6JgLvHwIvzcuLnF9lUdCSpCw=
go.opentelemetry.io/otel/sdk v1.45.0/go.mod h1:Sr40LgXV7DsKMMJMKOhUWOgMWTfAaqvm2kF0g7ilwuA=
go.opentelemetry.io/otel/sdk/metric v1.45.0 h1:oVFszMfyj1Am6s24Vtc7wBb8BKLcwepJjNEYILuiE3o=
go.opentelemetry.io/otel/sdk/metric v1.45.0/go.mod h1:vUWUxDZvu1WVRj8JA8S0AdhsPrZoDpA2DdZauIh4mDA=
go.opentelemetry.io/otel/trace v1.45.0 h1:l/mP6Uv7oNO7/TblbhpbgMidxhq1uO/rPsikOyVhxag=
go.opentelemetry.io/otel/trace v1.45.0/go.mod h1:qoJJA2xNMnxRrdISU/kLtfUH2wNeQbiv+jhs/CxI8bc=
go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM=
go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU=
go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI=
go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw=
go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY=
go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU=
go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I=
go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0=
go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw=
go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw=
go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM=
go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk=
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8=
golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M=
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=
gopkg.in/ini.v1 v1.67.1/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 2 additions & 0 deletions internal/verda-cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/instancetypes"
"github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/locations"
mcpcmd "github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/mcp"
"github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/network"
"github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/objectstorage"
"github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/registry"
"github.com/verda-cloud/verda-cli/internal/verda-cli/cmd/serverless"
Expand Down Expand Up @@ -135,6 +136,7 @@ func NewRootCommand(ioStreams cmdutil.IOStreams) (*cobra.Command, *clioptions.Op
images.NewCmdImages(f, ioStreams),
instancetypes.NewCmdInstanceTypes(f, ioStreams),
locations.NewCmdLocations(f, ioStreams),
network.NewCmdNetwork(f, ioStreams),
registry.NewCmdRegistry(f, ioStreams),
objectstorage.NewCmdObjectStorage(f, ioStreams),
sshkey.NewCmdSSHKey(f, ioStreams),
Expand Down
35 changes: 35 additions & 0 deletions internal/verda-cli/cmd/network/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Network Command Knowledge

> Go house style lives in the root `CLAUDE.md` § "Go House Style". This file carries private-network idioms only.

## Quick Reference

- Parent: `verda network` (aliases `networks`, `net`, `private-network`, `vpc`), tagged `(beta)` via `cmdutil.TagAnnotation`, registered under "Resource Commands:" in `cmd/cmd.go`.
- Verbs: `list` (`ls`), `create`, `delete` (`rm`); `subnet` (`subnets`) with `list` (`ls`), `create` and `delete` (`rm`).
- SDK: `client.PrivateNetworks` (experimental in the SDK).
- Files: one per verb; `cidr.go` (free /24), `views.go` (JSON/YAML shapes), `wizard.go` (create flows); tests use the in-memory API in `fake_test.go`.

## Domain-Specific Logic

- **A network is global; a subnet is per location.** Network names are unique in a project.
- **Default network.** A VM that does not name a network joins the default network. `create --default` makes the new network the default.
- **Mode.** `custom` (default): the user creates the subnets. `auto`: only for the project's default network, a deploy that names no subnet makes the API create one in its location, from the location's `private_network_auto_subnet` range. A deploy that names a non-default auto network gets a 400 if the location has no subnet.
- **Names** are trimmed on every path (flag and wizard) and limited to 64 characters, counted in runes, not bytes.
- **IDs only.** Arguments and `--network` take IDs, never names. `delete` reads the network with `GetByID`; `subnet delete` needs `--network` and reads the subnet with `GetSubnetByID`. An unknown ID is the API 404, which `ClassifyError` reports as `NOT_FOUND`. `subnet list` and `subnet create` match `--network` against the network list and return `NOT_FOUND` themselves. Subnet names are unique in a network: `subnet create` checks a new name against them.
- **Delete with instances: the API refuses (409) and changes nothing.** The CLI does not check first; `ClassifyError` reports the 409 as `API_ERROR` (exit 4). It never deletes instances.
- **Network delete removes its subnets.** The confirmation lists them (one extra `GetSubnets` call, skipped with `--yes`).
- **`is_default` on network create is only sent when true** (`CreatePrivateNetworkRequest.IsDefault` is `omitempty`); the test checks the exact body.
- **`is_default` on subnet create is a `*bool`.** The CLI sets it only when the user sets `--default` or answers the wizard step. `--default=false` sends `false`, and the API keeps it. With nil, the API makes the new subnet the default when the network has no default subnet in that location: no subnets yet, only `false` subnets, or the default was deleted (the API does not move the default on delete). The OpenAPI text ("the first subnet in a datacenter") is wrong; a production run confirmed this rule. For that reason, the wizard skips the step when the location has no default subnet, unless `--default` was given (a skipped step resets its value).
- **Subnet CIDR.** `freeSubnetCIDR` suggests the first free /24 in 10.0.0.0/16. The CLI does not check `--cidr`: the API decides which ranges it accepts. With `--network`, the command reads only that network's subnets.
- **Subnet locations.** Only locations with `IsPrivateNetworksEnabled`. Another location gives `VALIDATION_ERROR` that lists the allowed codes.

## Gotchas & Edge Cases

- **AgentErrors print as JSON outside agent mode too** (`main.go`): `create` without `--name`, `subnet create` without `--network` / `--location`, `delete` without a target, or `subnet delete` without a target or `--network`, on a pipe gives the `MISSING_REQUIRED_FLAGS` envelope with exit 2.
- **Agent mode without `--yes`** fails with `CONFIRMATION_REQUIRED` before any API call, for both deletes.
- **Pickers** run only on a terminal, outside agent mode, with table output. The `subnet delete` picker lists the subnets of `--network` when given, else of all networks. Cancel (the last row, Esc, Ctrl+C) prints `Canceled.` to stderr and exits cleanly, like a declined confirmation.

## Relationships

- `cmdutil` — `WithSpinner`, `RunWithSpinner`, `DebugJSON`, `WriteStructured`, `TimeColumn`, `TextColumn`, `NewMissingFlagsError`, `NewValidationError`, `NewConfirmationRequiredError`.
- `pkg/tui/wizard` — the create flows.
21 changes: 21 additions & 0 deletions internal/verda-cli/cmd/network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# verda network -- Manage private networks (beta)

Commands, flags and behavior: `verda network --help` and `verda network <command> --help`. Commands take IDs, not names.

## Workflow

```bash
NETWORK_ID=$(verda network create --name prod -o json | jq -r .id)
SUBNET_ID=$(verda network subnet create --network "$NETWORK_ID" -l FIN-03 -o json | jq -r .id)
verda network subnet list --network "$NETWORK_ID"
verda network subnet delete "$SUBNET_ID" --network "$NETWORK_ID"
verda network delete "$NETWORK_ID"
```

## Agent Mode

- Missing `--name`, `--network`, `--location` or an ID: `MISSING_REQUIRED_FLAGS` (exit 2).
- Bad input (mode, name, location): `VALIDATION_ERROR` (exit 2), before the create request. The API checks `--cidr`.
- Delete without `--yes`: `CONFIRMATION_REQUIRED` (exit 2).
- Unknown ID: `NOT_FOUND` (exit 5).
- Delete success: `{"resource", "id", "name", "action": "delete", "status": "completed"}`.
73 changes: 73 additions & 0 deletions internal/verda-cli/cmd/network/cidr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2026 Verda Cloud Oy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package network

import (
"fmt"
"net/netip"
"slices"

"github.com/verda-cloud/verdacloud-sdk-go/pkg/verda"
)

// defaultSubnetPool is where freeSubnetCIDR looks for a subnet range.
var defaultSubnetPool = netip.MustParsePrefix("10.0.0.0/16")

// defaultSubnetBits is the size of a suggested subnet (/24).
const defaultSubnetBits = 24

// checkCIDRFormat checks only that s is an IPv4 prefix, as the SDK does.
// The API decides which ranges it accepts.
func checkCIDRFormat(s string) error {
if p, err := netip.ParsePrefix(s); err != nil || !p.Addr().Is4() {
return fmt.Errorf("%q is not an IPv4 CIDR (example: 10.0.1.0/24)", s)
}
return nil
}

// freeSubnetCIDR returns the first /24 in 10.0.0.0/16 that overlaps none of taken.
func freeSubnetCIDR(taken []netip.Prefix) (netip.Prefix, error) {
for a := defaultSubnetPool.Addr(); defaultSubnetPool.Contains(a); {
block := netip.PrefixFrom(a, defaultSubnetBits)
if !slices.ContainsFunc(taken, block.Overlaps) {
return block, nil
}
for block.Contains(a) {
a = a.Next()
}
}
return netip.Prefix{}, fmt.Errorf("no free subnet range: every /%d in %s is taken", defaultSubnetBits, defaultSubnetPool)
}

// subnetPrefixes skips subnets whose CIDR does not parse.
func subnetPrefixes(subnets []verda.Subnet) []netip.Prefix {
out := make([]netip.Prefix, 0, len(subnets))
for i := range subnets {
if p, err := netip.ParsePrefix(subnets[i].CIDR); err == nil {
out = append(out, p)
}
}
return out
}

// defaultNetwork returns nil when no network is the default; it never falls back to another network.
func defaultNetwork(networks []verda.PrivateNetwork) *verda.PrivateNetwork {
for i := range networks {
if networks[i].IsDefault {
return &networks[i]
}
}
return nil
}
Loading
Loading