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

Method Rename

internal/server/instance/drivers/driver_lxc.go:4557–4743  ·  view source on GitHub ↗

Rename renames the instance. Accepts an argument to enable applying deferred TemplateTriggerRename.

(newName string, applyTemplateTrigger bool)

Source from the content-addressed store, hash-verified

4555
4556// Rename renames the instance. Accepts an argument to enable applying deferred TemplateTriggerRename.
4557func (d *lxc) Rename(newName string, applyTemplateTrigger bool) error {
4558 oldName := d.Name()
4559 ctxMap := logger.Ctx{
4560 "created": d.creationDate,
4561 "ephemeral": d.ephemeral,
4562 "used": d.lastUsedDate,
4563 "newname": newName,
4564 }
4565
4566 d.logger.Info("Renaming instance", ctxMap)
4567
4568 // Quick checks.
4569 err := instance.ValidName(newName, d.IsSnapshot())
4570 if err != nil {
4571 return err
4572 }
4573
4574 if d.IsRunning() {
4575 return errors.New("Renaming of running instance not allowed")
4576 }
4577
4578 // Clean things up.
4579 d.cleanup()
4580
4581 pool, err := storagePools.LoadByInstance(d.state, d)
4582 if err != nil {
4583 return fmt.Errorf("Failed loading instance storage pool: %w", err)
4584 }
4585
4586 if d.IsSnapshot() {
4587 _, newSnapName, _ := api.GetParentAndSnapshotName(newName)
4588 err = pool.RenameInstanceSnapshot(d, newSnapName, nil)
4589 if err != nil {
4590 return fmt.Errorf("Rename instance snapshot: %w", err)
4591 }
4592 } else {
4593 err = pool.RenameInstance(d, newName, nil)
4594 if err != nil {
4595 return fmt.Errorf("Rename instance: %w", err)
4596 }
4597
4598 if applyTemplateTrigger {
4599 err = d.DeferTemplateApply(instance.TemplateTriggerRename)
4600 if err != nil {
4601 return err
4602 }
4603 }
4604 }
4605
4606 if !d.IsSnapshot() {
4607 var results []string
4608
4609 err := d.state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
4610 var err error
4611
4612 // Rename all the instance snapshot database entries.
4613 results, err = tx.GetInstanceSnapshotsNames(ctx, d.project.Name, oldName)
4614 if err != nil {

Callers

nothing calls this directly

Calls 15

IsRunningMethod · 0.95
cleanupMethod · 0.95
releaseMethod · 0.95
UpdateBackupFileMethod · 0.95
ValidNameFunction · 0.92
GetParentAndSnapshotNameFunction · 0.92
RenameInstanceSnapshotFunction · 0.92
RenameInstanceFunction · 0.92
InstanceFunction · 0.92
PathExistsFunction · 0.92
NewFunction · 0.92
UpdateDNSMasqStaticFunction · 0.92

Tested by

no test coverage detected