-
Notifications
You must be signed in to change notification settings - Fork 2
feat(vm): cocoon vm net --nics N — runtime NIC resize #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
a515f7f
feat(netresize): extend interface + chVMInfoConfig.Nets
CMGS 100a08c
refactor(network): replace Network.Config with Add/Remove
CMGS 5c65f0c
refactor(network): dedup Delete/Remove via shared tearDown helpers
CMGS 68a58b8
feat(cloudhypervisor): implement netresize.Resizer
CMGS 1e23e1a
feat(vm): cocoon vm net --nics N
CMGS 20578be
fix(clone): verify each NIC removed before re-adding in hotSwapNets
CMGS 01187b3
docs: cocoon vm net --nics N
CMGS 8067417
revert(clone): drop post-remove vm.info check in hotSwapNets
CMGS bebc11c
remove(netresize): drop --keep-host-on-remove flag
CMGS c95d796
refactor(cloudhypervisor): single inspect bootstrap + consolidate pro…
CMGS a90a5d5
fix(netresize): rollback CH device + always truncate on partial failure
CMGS 0333437
fix(network): propagate teardown errors and rollback bridge.Add partials
CMGS f5cf1ce
docs(readme): rephrase NIC hot-resize add/remove summary
CMGS 1dc67a7
docs(netresize): correct leak-reclaim hint
CMGS 7c97cbf
fix: CNI Add rollback TAP cleanup + skip vm.info on add-only resize
CMGS 6b1f164
feat(netresize): surface non-fatal warnings in Result
CMGS ca0534c
chore: trim verbose comments across vm-net-resize branch
CMGS d1cd8c7
fix(cni): always attempt deleteNetns in deleteVM
CMGS 63649d7
fix(cni): sweep partial records when Remove aborts mid-loop
CMGS feb7a43
refactor(cni): drop delNICs, route gc.Collect through tearDownNICs
CMGS 836f47e
refactor(cloudhypervisor): share addCocoonNIC across resize-up and clone
CMGS b5ddeb8
docs: restore 1-line godoc on exported netresize/network items
CMGS e882433
perf: pre-size Result.Added/Removed and bridge added slices
CMGS 609fc4d
docs(netresize): point leak warning at the actual reclaim path
CMGS e4ad25b
chore: tighten a few inline/godoc comments
CMGS e52dc03
fix(cni): converge Remove on CNI DEL / TAP failure
CMGS 5ee5837
fix(cni): join Remove teardown and delete-records errors
CMGS d5ae027
fix(cni): always sweep DB records in deleteVM regardless of teardown
CMGS edb767d
fix: nil-guard NetworkConfig derefs in addCocoonNIC and netResizeRemove
CMGS a3d41cc
fix(netresize): wait for guest B0EJ before host plumbing teardown
CMGS e642cce
docs: note clone hot-swap can't wait for B0EJ (paused guest)
CMGS 534a9f6
fix(netresize): symmetric eject-wait in Add persist-fail rollback + 1…
CMGS 3962951
chore: trim multi-line godocs introduced by this branch to 1 line
CMGS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,6 @@ tmp/* | |
|
|
||
| .claude/* | ||
| cocoon-test | ||
|
|
||
| # Local scratch / test scripts (not for upstream) | ||
| /scratch/ | ||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package vm | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/projecteru2/core/log" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| cmdcore "github.com/cocoonstack/cocoon/cmd/core" | ||
| "github.com/cocoonstack/cocoon/config" | ||
| "github.com/cocoonstack/cocoon/extend/netresize" | ||
| "github.com/cocoonstack/cocoon/network" | ||
| "github.com/cocoonstack/cocoon/types" | ||
| ) | ||
|
|
||
| func (h Handler) NetResize(cmd *cobra.Command, args []string) error { | ||
| ctx, conf, hyper, resizer, err := resolveAttacher[netresize.Resizer](h, cmd, args, "vm net", netresize.ErrUnsupportedBackend) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| vm, err := hyper.Inspect(ctx, args[0]) | ||
| if err != nil { | ||
| return fmt.Errorf("vm net: %w", err) | ||
| } | ||
| plumbing, err := plumbingForVM(conf, vm.NetworkConfigs) | ||
| if err != nil { | ||
| return fmt.Errorf("vm net: %w", err) | ||
| } | ||
| target, _ := cmd.Flags().GetInt("nics") | ||
| res, err := resizer.NetResize(ctx, args[0], netresize.Spec{Target: target}, plumbing) | ||
| if err != nil { | ||
| return classifyAttachErr(err) | ||
| } | ||
| if done, jsonErr := cmdcore.MaybeOutputJSON(cmd, res); done { | ||
| return jsonErr | ||
| } | ||
| logger := log.WithFunc("cmd.vm.net") | ||
| logger.Infof(ctx, "resized %s: before=%d after=%d added=%d removed=%d", | ||
| args[0], res.Before, res.After, len(res.Added), len(res.Removed)) | ||
| for _, w := range res.Warnings { | ||
| logger.Warnf(ctx, "%s: %s", args[0], w) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // plumbingForVM picks the provider for the VM's existing NICs; fails on zero NICs (VMConfig has no bridge hint). | ||
| func plumbingForVM(conf *config.Config, configs []*types.NetworkConfig) (network.Network, error) { | ||
| if len(configs) == 0 { | ||
| return nil, fmt.Errorf("vm has zero NICs; resize up is not supported (start the VM with at least one NIC)") | ||
| } | ||
| return providerForVM(conf, nil, map[string]network.Network{}, configs) | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Package netresize is the runtime interface for resizing a VM's NIC count. | ||
| package netresize | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/cocoonstack/cocoon/network" | ||
| "github.com/cocoonstack/cocoon/types" | ||
| ) | ||
|
|
||
| // ErrUnsupportedBackend signals the resolved hypervisor cannot resize NICs. | ||
| var ErrUnsupportedBackend = errors.New("backend does not support net resize") | ||
|
|
||
| // Spec is one resize request. | ||
| type Spec struct { | ||
| Target int | ||
| } | ||
|
|
||
| // NIC is one NIC summary surfaced through Result.Added / Result.Removed. | ||
| type NIC struct { | ||
| Index int `json:"index"` | ||
| TAP string `json:"tap"` | ||
| MAC string `json:"mac"` | ||
| } | ||
|
|
||
| // Result reports the before/after count, NICs touched, and non-fatal Warnings. | ||
| type Result struct { | ||
| Before int `json:"before"` | ||
| After int `json:"after"` | ||
| Added []NIC `json:"added,omitempty"` | ||
| Removed []NIC `json:"removed,omitempty"` | ||
| Warnings []string `json:"warnings,omitempty"` | ||
| } | ||
|
|
||
| // Plumbing is the host-side network ops NetResize delegates to; network.Network satisfies it. | ||
| type Plumbing interface { | ||
| Add(ctx context.Context, vmID string, vmCfg *types.VMConfig, specs ...network.AddSpec) ([]*types.NetworkConfig, error) | ||
| Remove(ctx context.Context, vmID string, indices ...int) error | ||
| } | ||
|
|
||
| // Resizer resizes a running VM's NIC count. | ||
| type Resizer interface { | ||
| NetResize(ctx context.Context, vmRef string, spec Spec, plumbing Plumbing) (Result, error) | ||
| } | ||
|
|
||
| // Normalize validates the spec. | ||
| func (s *Spec) Normalize() error { | ||
| if s.Target < 0 { | ||
| return fmt.Errorf("--nics must be non-negative, got %d", s.Target) | ||
| } | ||
| return nil | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.