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

Function ValidName

internal/server/instance/instance_utils.go:685–709  ·  view source on GitHub ↗

ValidName validates an instance name. There are different validation rules for instance snapshot names so it takes an argument indicating whether the name is to be used for a snapshot or not.

(instanceName string, isSnapshot bool)

Source from the content-addressed store, hash-verified

683// ValidName validates an instance name. There are different validation rules for instance snapshot names
684// so it takes an argument indicating whether the name is to be used for a snapshot or not.
685func ValidName(instanceName string, isSnapshot bool) error {
686 if isSnapshot {
687 parentName, snapshotName, _ := api.GetParentAndSnapshotName(instanceName)
688 err := validate.IsHostname(parentName)
689 if err != nil {
690 return fmt.Errorf("Invalid instance name: %w", err)
691 }
692
693 // Snapshot part is more flexible, but doesn't allow space or / character.
694 if strings.ContainsAny(snapshotName, " /") {
695 return errors.New("Invalid instance snapshot name: Cannot contain space or / characters")
696 }
697 } else {
698 if strings.Contains(instanceName, instance.SnapshotDelimiter) {
699 return fmt.Errorf("The character %q is reserved for snapshots", instance.SnapshotDelimiter)
700 }
701
702 err := validate.IsHostname(instanceName)
703 if err != nil {
704 return fmt.Errorf("Invalid instance name: %w", err)
705 }
706 }
707
708 return nil
709}
710
711// CreateInternal creates an instance record and storage volume record in the database and sets up devices.
712// Accepts a reverter that revert steps this function does will be added to. It is up to the caller to

Callers 5

RenameMethod · 0.92
RenameMethod · 0.92
instancePostFunction · 0.92
instancesPostFunction · 0.92
CreateInternalFunction · 0.70

Calls 4

GetParentAndSnapshotNameFunction · 0.92
IsHostnameFunction · 0.92
ErrorfMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…