resolveTemplateName resolves a package name (e.g. "debian-12-standard") to a full template filename by querying aplinfo. If section is non-empty, only templates in that section are considered. Returns the alphabetically last (latest) match.
(client *api.Client, nodeName, packageName, section string)
| 1134 | // templates in that section are considered. Returns the alphabetically last |
| 1135 | // (latest) match. |
| 1136 | func resolveTemplateName(client *api.Client, nodeName, packageName, section string) (string, error) { |
| 1137 | templates, err := client.GetAvailableTemplates(nodeName) |
| 1138 | if err != nil { |
| 1139 | return "", fmt.Errorf("failed to fetch template list: %w", err) |
| 1140 | } |
| 1141 | |
| 1142 | var matches []string |
| 1143 | for _, t := range templates { |
| 1144 | if t.Package != packageName { |
| 1145 | continue |
| 1146 | } |
| 1147 | if section != "" && !strings.EqualFold(t.Section, section) { |
| 1148 | continue |
| 1149 | } |
| 1150 | matches = append(matches, t.Filename) |
| 1151 | } |
| 1152 | |
| 1153 | if len(matches) == 0 { |
| 1154 | return "", fmt.Errorf("no template found matching package name %q", packageName) |
| 1155 | } |
| 1156 | |
| 1157 | // Sort and pick the last (latest) version. |
| 1158 | for i := 0; i < len(matches)-1; i++ { |
| 1159 | for j := i + 1; j < len(matches); j++ { |
| 1160 | if matches[j] > matches[i] { |
| 1161 | matches[i], matches[j] = matches[j], matches[i] |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | resolved := matches[0] |
| 1166 | fmt.Fprintf(os.Stderr, "resolved template %q → %q\n", packageName, resolved) |
| 1167 | return resolved, nil |
| 1168 | } |
| 1169 | |
| 1170 | // ── guests migrate ─────────────────────────────────────────────────────────── |
| 1171 |
no test coverage detected