Skip to content

Commit

Permalink
limactl: make sure to remove "." from instance names
Browse files Browse the repository at this point in the history
Now `limactl create template://ubuntu-24.10` creates `ubuntu-24-10`.

Fix issue 2813

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Oct 28, 2024
1 parent 8b995a3 commit 7f7f3db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/limactl/guessarg/guessarg.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func SeemsYAMLPath(arg string) bool {
return strings.HasSuffix(lower, ".yml") || strings.HasSuffix(lower, ".yaml")
}

func InstNameFromTemplateName(templateName string) (string, error) {
s := filepath.Base(templateName)
s = strings.ReplaceAll(s, ".", "-")
if err := identifiers.Validate(s); err != nil {
return "", fmt.Errorf("instance name %q (from template name %qI is invalid: %w",
s, templateName, err)
}
return s, nil
}

func InstNameFromURL(urlStr string) (string, error) {
u, err := url.Parse(urlStr)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion cmd/limactl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
}
if st.instName == "" {
// e.g., templateName = "deprecated/centos-7" , st.instName = "centos-7"
st.instName = filepath.Base(templateName)
// e.g., templateName = "ubuntu-24.10" , st.instName = "ubuntu-24-10"
st.instName, err = guessarg.InstNameFromTemplateName(templateName)
if err != nil {
return nil, err
}
}
st.yBytes, err = templatestore.Read(templateName)
if err != nil {
Expand Down

0 comments on commit 7f7f3db

Please sign in to comment.