Skip to content

feat: support VPC network type and existing network attachment for instance creation - #47

Open
cokerrd wants to merge 4 commits into
zsoftly:mainfrom
cokerrd:feat/instance-create-options
Open

feat: support VPC network type and existing network attachment for instance creation#47
cokerrd wants to merge 4 commits into
zsoftly:mainfrom
cokerrd:feat/instance-create-options

Conversation

@cokerrd

@cokerrd cokerrd commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

This adds support for creating an instance of Vpc network type, and also attaching an existing network or networks to the creation of an instance instead of creating a new network

Changes

  • Add --vr-plan flag to specify the router for the VPC creation
  • Add --networks flag to specify the network(s) to attach to the instance
  • Add --default-network flag to specify the default network if multiple networks are specified
  • Add Input validations based on the network type specified
  • Add instance create test case
Screen.Recording.2026-08-02.at.23.23.53.mov

Summary by CodeRabbit

  • New Features

    • Instance creation now supports L2, Isolated, and VPC network types.
    • Added support for virtual-router plans, multiple network attachments, and selecting a default network.
    • Network options are validated according to the selected network type.
  • Bug Fixes

    • Removed the requirement to always provide a network plan when creating an instance.
  • Tests

    • Added coverage for successful virtual machine creation and request validation.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cokerrd, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8bbe6967-0fc3-4632-bc78-3aaf2fc722fe

📥 Commits

Reviewing files that changed from the base of the PR and between b576ffd and b19f625.

📒 Files selected for processing (1)
  • internal/commands/instance.go
📝 Walkthrough

Walkthrough

Changes

Instance network creation

Layer / File(s) Summary
Create request contract and service coverage
pkg/api/instance/instance.go, pkg/api/instance/instance_test.go
CreateRequest now supports VrPlan and DefaultNetwork. Service tests validate the VM creation request and response.
CLI network validation and request wiring
internal/commands/instance.go
The create command supports multiple network types, attached networks, virtual-router plans, and default-network selection. Validation and request construction now use these values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant InstanceCreateCommand
  participant instance.Service.Create
  participant API server
  User->>InstanceCreateCommand: Provide network options
  InstanceCreateCommand->>InstanceCreateCommand: Validate options by network type
  InstanceCreateCommand->>instance.Service.Create: Send CreateRequest
  instance.Service.Create->>API server: POST /virtual-machines
  API server-->>instance.Service.Create: Return created VM
Loading

Possibly related PRs

  • zsoftly/zcp-cli#3: Both modify network-aware instance creation and VPC plan handling.
  • zsoftly/zcp-cli#25: Both modify instance creation validation and network-plan CLI behavior.
  • zsoftly/zcp-cli#27: Both modify L2 network validation and instance creation behavior.

Suggested reviewers: ditahkk, clintonche, ditahm6

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: VPC network support and attaching existing networks during instance creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/api/instance/instance_test.go (1)

49-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the new network request fields.

TestCreate only verifies name. A missing or incorrect vr_plan, default_network, or networks field will still pass this test. Populate these fields in req and assert their JSON values in gotBody.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/api/instance/instance_test.go` around lines 49 - 64, Update TestCreate to
populate req with representative values for vr_plan, default_network, and
networks, then assert the corresponding JSON fields in gotBody alongside the
existing name check. Preserve the current Create success and VM response
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/commands/instance.go`:
- Around line 546-555: Update the flag descriptions in the command setup around
the networkType, networkPlan, and vrPlan variables to reflect validation: remove
“required” from --network-type, and state that --network-plan and --vr-plan are
only required when creating their applicable network types unless --networks is
provided.
- Around line 461-462: Update the network validation around the existing
len(networks) check in the instance command to require a non-empty
defaultNetwork only when networks are provided, and verify that its value
matches one of the entries in networks. Reject values that are absent from
networks, including when defaultNetwork is supplied without networks, before
reaching the API.

---

Nitpick comments:
In `@pkg/api/instance/instance_test.go`:
- Around line 49-64: Update TestCreate to populate req with representative
values for vr_plan, default_network, and networks, then assert the corresponding
JSON fields in gotBody alongside the existing name check. Preserve the current
Create success and VM response assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12e1a1f2-0490-453d-98b9-0ec693259c30

📥 Commits

Reviewing files that changed from the base of the PR and between b9d121c and b576ffd.

📒 Files selected for processing (3)
  • internal/commands/instance.go
  • pkg/api/instance/instance.go
  • pkg/api/instance/instance_test.go

Comment thread internal/commands/instance.go
Comment on lines +546 to +555
cmd.Flags().StringVar(&plan, "plan", "", "Plan slug (e.g. ca2sxs- see: zcp plan vm (required)")
cmd.Flags().StringVar(&billingCycle, "billing-cycle", "", "Billing cycle slug: hourly, monthly, etc. (required)")
cmd.Flags().StringVar(&networkType, "network-type", "Isolated", "Network type (default: Isolated)")
cmd.Flags().StringVar(&networkType, "network-type", "Isolated", "Network type: Isolated, L2 or Vpc (required)")
cmd.Flags().StringVar(&sshKey, "ssh-key", "", "Name of an existing SSH key to attach for login (optional; see 'zcp ssh-key list')")
cmd.Flags().StringVar(&hostname, "hostname", "", "Hostname (defaults to --name)")
cmd.Flags().StringVar(&storageCategory, "storage-category", "", "Storage category (required, e.g. premium-ssd - see: zcp plan storage)")
cmd.Flags().StringVar(&computeCategory, "compute-category", "", "Compute category slug (optional)")
cmd.Flags().StringVar(&blockstoragePlan, "blockstorage-plan", "", "Block storage plan slug (optional, e.g. b2g1 — see: zcp plan storage)")
cmd.Flags().StringVar(&networkPlan, "network-plan", "", "Network plan slug (required, e.g. pnet-yow, pnet-yul — see: zcp plan network)")
cmd.Flags().StringVar(&networkPlan, "network-plan", "", "Network plan slug (optional; required when creating an Isolated or L2 network type— see: zcp plan network)")
cmd.Flags().StringVar(&vrPlan, "vr-plan", "", "Virtual router plan slug (optional; required when creating a VPC — see: zcp plan router)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the conditional flag help text.

--network-type has a default value, so it is not required. --network-plan and --vr-plan are optional when --networks is set. Update these descriptions to match the validation rules.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/commands/instance.go` around lines 546 - 555, Update the flag
descriptions in the command setup around the networkType, networkPlan, and
vrPlan variables to reflect validation: remove “required” from --network-type,
and state that --network-plan and --vr-plan are only required when creating
their applicable network types unless --networks is provided.

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.

1 participant