The kvm2 block reuses KVMConfig; validateKVM gains a block-name variant so messages say kvm2. The package skeleton has a non-dialing New, strict providerID parsing, the state table and a 34-row classify test. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
29 lines
987 B
Go
29 lines
987 B
Go
package kvm2
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// The providerID is hosts/<host>/domains/<name>. Host names are validated at
|
|
// config load to contain no slash, and domain names come from NameFromUID,
|
|
// so a strict four-segment split is enough to parse it.
|
|
const (
|
|
idHostsSegment = "hosts"
|
|
idDomainsSegment = "domains"
|
|
)
|
|
|
|
func formatProviderID(host, name string) string {
|
|
return idHostsSegment + "/" + host + "/" + idDomainsSegment + "/" + name
|
|
}
|
|
|
|
// parseProviderID splits an ID back into host and domain name. Anything
|
|
// that is not exactly hosts/<host>/domains/<name> with both non-empty is
|
|
// ErrPermanent: no retry will make it resolve.
|
|
func parseProviderID(id string) (host, name string, err error) {
|
|
parts := strings.Split(id, "/")
|
|
if len(parts) != 4 || parts[0] != idHostsSegment || parts[2] != idDomainsSegment || parts[1] == "" || parts[3] == "" {
|
|
return "", "", permanentf("malformed providerID %q: want hosts/<host>/domains/<name>", id)
|
|
}
|
|
return parts[1], parts[3], nil
|
|
}
|