Documentation
¶
Overview ¶
Package datasource locates the first-boot configuration. V0.1 supports two flavours of the NoCloud datasource :
nocloud-net : HTTP fetch of user-data + meta-data (cloud-init's
standard "fetch from a web server pointed at by DHCP")
nocloud : block device with a filesystem label "cidata" or
"CIDATA" holding /user-data + /meta-data
The nocloud disk is read *without mounting it* : the candidate device nodes are opened read-only and their on-disk structures decoded in pure Go (go-filesystems/detect picks the driver from the magic signature). No mount(2), no /sbin/mount_* fork, no root. A mount fallback survives for filesystem shapes the pure-Go drivers cannot read yet — see fromDisk in disk.go — and Source.Origin always says which of the two served.
The configuration format inside the datasource is auto-detected : if user-data starts with "#cloud-config" or is parseable as YAML, we treat it as cloud-config legacy ; otherwise we parse as HCL. The HCL path is preferred for new VMs (no magic header needed).
Discovery order, from cheapest to most invasive :
- --datasource URL explicit override (highest priority)
- NoCloud disk (cidata label) no network, no privilege : a read-only open plus a few bounded reads per candidate device
- NoCloud-NET via HTTP one DHCP probe + one GET
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("datasource: not found")
ErrNotFound is returned by individual probes when their datasource flavour wasn't present. The Discover function aggregates probes and only fails when every probe returned ErrNotFound.
Functions ¶
func Parse ¶
Parse routes raw bytes through the right parser. Heuristic :
- first non-whitespace line is "#cloud-config" → cloud-config YAML
- else default to HCL (the preferred format)
We don't try to parse-and-fallback because HCL and YAML can both silently consume each other's syntax in pathological cases ; the explicit header keeps the choice deterministic.
Exported so the CLI can parse a local file without going through Discover (which would mis-tag a file URL as "nocloud-net:").
Types ¶
type Source ¶
type Source struct {
// Origin describes where the data came from, e.g.
// "nocloud-net:http://10.0.2.2/user-data" or "nocloud:/dev/sd1a".
// Used for logging and the sentinel file's record.
Origin string
// Raw is the unparsed user-data bytes. Useful for hashing to skip
// re-apply on already-converged hosts.
Raw []byte
// Config is the parsed Config (HCL or cloud-config YAML).
Config config.Config
}
Source is the result of a successful probe : the raw user-data bytes (so we can record a hash for idempotence) plus the parsed Config.