Skip to content

feat(migration): optional power-off of target VM after migration (#1867)#1950

Open
valentin-pf9 wants to merge 1 commit into
platform9:mainfrom
valentin-pf9:feature/optional-target-poweroff
Open

feat(migration): optional power-off of target VM after migration (#1867)#1950
valentin-pf9 wants to merge 1 commit into
platform9:mainfrom
valentin-pf9:feature/optional-target-poweroff

Conversation

@valentin-pf9

@valentin-pf9 valentin-pf9 commented May 18, 2026

Copy link
Copy Markdown

Summary

Implements #1867.

By default the migrated VM boots powered-on in the target cloud — Nova starts it on creation. Operators who need to run post-migration tasks before first boot (the issue's example: assigning security groups via script) had no way to keep it off.

This adds a powerOffTargetVm option. When set, the target VM is stopped immediately after it's created and verified ACTIVE, and post-migration health checks are skipped (they require a running VM).

Design

The flag mirrors the existing disconnectSourceNetwork plumbing end-to-end — an established pattern:

  • migrationplan_types.goPowerOffTargetVM added to MigrationStrategy.
  • migration_types.goPowerOffTargetVM added to MigrationSpec.
  • config/crd/bases/* — regenerated via make manifests.
  • migrationplan_controller.go — copies the strategy flag onto each Migration's spec, and writes POWER_OFF_TARGET_VM into the v2v-helper configmap.
  • vcenterutils.go — reads POWER_OFF_TARGET_VM into MigrationParams.
  • main.go — populates Migrate.PowerOffTargetVM and logs it.
  • migrate.go — new PowerOffTargetVM field; in CreateTargetInstance, after the VM is ACTIVE, stops it and skips health checks when the flag is set.

New OpenStack operation

OpenstackOperations gains StopServer, which issues servers.Stop and polls until the server reaches SHUTOFF (reusing the existing VMActiveWait retry settings). Implementation in openstackopsutils.go, mock in openstackops_mock.go.

Tests

TestCreateTargetInstance_PowerOffTargetVM asserts StopServer is called exactly once when PowerOffTargetVM is set.

Verified locally:

  • go build ./... (k8s/migration) — OK
  • go test ./pkg/utils/... (k8s/migration) — OK
  • CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./... (v2v-helper) — OK

The v2v-helper migrate package test suite can't be built locally because of a pre-existing CreateVM mock mismatch on main (addressed by #1945). TestCreateTargetInstance_PowerOffTargetVM will run in CI.

Scope

Backend only. A UI checkbox ("Keep Target VM Powered Off", as the issue suggests) will follow in a separate PR. The capability is usable now via the MigrationPlan CRD / CLI:

spec:
  migrationStrategy:
    powerOffTargetVm: true

Open in Devin Review

…ation

Implements platform9#1867.

By default the migrated VM boots powered-on in the target cloud (Nova
starts it on creation). Operators who need to run post-migration tasks
before first boot -- e.g. assigning security groups via script -- had no
way to keep it off.

Adds a powerOffTargetVm option that, when set, stops the target VM
immediately after it is created and verified, and skips post-migration
health checks (which require a running VM).

The flag mirrors the existing disconnectSourceNetwork plumbing:
- migrationplan_types.go: add PowerOffTargetVM to MigrationStrategy.
- migration_types.go: add PowerOffTargetVM to MigrationSpec.
- config/crd/bases: regenerated via 'make manifests'.
- migrationplan_controller.go: copy the strategy flag onto each Migration
  spec and write POWER_OFF_TARGET_VM into the v2v-helper configmap.
- v2v-helper/pkg/utils/vcenterutils.go: read POWER_OFF_TARGET_VM into
  MigrationParams.
- v2v-helper/main.go: populate Migrate.PowerOffTargetVM and log it.
- v2v-helper/migrate/migrate.go: new PowerOffTargetVM field; in
  CreateTargetInstance, after the VM is ACTIVE, stop it and skip health
  checks when the flag is set.

New OpenStack operation:
- openstack.OpenstackOperations gains StopServer, which issues
  servers.Stop and polls until the server reaches SHUTOFF (reusing the
  VMActiveWait retry settings). Impl in openstackopsutils.go, mock in
  openstackops_mock.go.

Tests:
- TestCreateTargetInstance_PowerOffTargetVM asserts StopServer is called
  exactly once when PowerOffTargetVM is set.

deploy/installer.yaml + deploy/00crds.yaml regenerated by the pre-commit
make build-installer hook.

Backend only -- a UI checkbox ('Keep Target VM Powered Off') will follow
in a separate PR. The capability is usable now via the MigrationPlan CRD.

Test plan:
- go build ./... (k8s/migration): OK.
- go test ./pkg/utils/... (k8s/migration): OK.
- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./... (v2v-helper): OK.
- v2v-helper migrate tests not runnable locally (blocked by the
  pre-existing CreateVM mock build break on main, addressed by platform9#1945);
  TestCreateTargetInstance_PowerOffTargetVM runs in CI.

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

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