MCPcopy
hub / github.com/lxc/incus / run

Method run

cmd/incus-migrate/main_migrate.go:480–546  ·  view source on GitHub ↗
(_ *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

478}
479
480func (c *cmdMigrate) run(_ *cobra.Command, _ []string) error {
481 // Server
482 server, clientFingerprint, err := c.askServer()
483 if err != nil {
484 return err
485 }
486
487 sigChan := make(chan os.Signal, 1)
488 signal.Notify(sigChan, os.Interrupt)
489 ctx, cancel := context.WithCancel(context.Background())
490
491 go func() {
492 <-sigChan
493
494 if clientFingerprint != "" {
495 _ = server.DeleteCertificate(clientFingerprint)
496 }
497
498 cancel()
499
500 // The following nolint directive ignores the "deep-exit" rule of the revive linter.
501 // We should be exiting cleanly by passing the above context into each invoked method and checking for
502 // cancellation. Unfortunately our client methods do not accept a context argument.
503 os.Exit(1) //nolint:revive
504 }()
505
506 if clientFingerprint != "" {
507 defer logger.WarnOnError(func() error { return server.DeleteCertificate(clientFingerprint) }, "Failed to delete certificate")
508 }
509
510 // Provide migration type
511 creationType, err := c.global.asker.AskInt(`
512What would you like to create?
5131) Container
5142) Virtual Machine
5153) Virtual Machine (from .ova)
5164) Custom Volume
517
518Please enter the number of your choice: `, 1, 4, "", nil)
519 if err != nil {
520 return err
521 }
522
523 var migrator Migrator
524 switch creationType {
525 case 1:
526 migrator = newInstanceMigration(ctx, server, c.global.asker, c.flagRsyncArgs, MigrationTypeContainer)
527 case 2:
528 migrator = newInstanceMigration(ctx, server, c.global.asker, c.flagRsyncArgs, MigrationTypeVM)
529 case 3:
530 migrator = newOVAMigration(ctx, server, c.global.asker, c.flagRsyncArgs)
531 case 4:
532 migrator = newVolumeMigration(ctx, server, c.global.asker, c.flagRsyncArgs)
533 }
534
535 err = migrator.gatherInfo()
536 if err != nil {
537 return err

Callers

nothing calls this directly

Calls 10

askServerMethod · 0.95
gatherInfoMethod · 0.95
renderObjectMethod · 0.95
migrateMethod · 0.95
WarnOnErrorFunction · 0.92
newInstanceMigrationFunction · 0.85
newOVAMigrationFunction · 0.85
newVolumeMigrationFunction · 0.85
AskIntMethod · 0.80
DeleteCertificateMethod · 0.65

Tested by

no test coverage detected