mirror of
https://github.com/danderson/netboot.git
synced 2025-08-10 00:27:12 +02:00
Allow {{ ServerHost }} in --cmdline
This commit is contained in:
parent
870d490bda
commit
3bcb83e55b
@ -30,6 +30,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func dummyServerHost() string {
|
||||
return "{{ ServerHost }}"
|
||||
}
|
||||
|
||||
// StaticBooter boots all machines with the same Spec.
|
||||
//
|
||||
// IDs in spec should be either local file paths, or HTTP/HTTPS URLs.
|
||||
@ -50,7 +54,7 @@ func StaticBooter(spec *Spec) (Booter, error) {
|
||||
ret.otherIDs = append(ret.otherIDs, id)
|
||||
return fmt.Sprintf("{{ ID \"other-%d\" }}", len(ret.otherIDs)-1)
|
||||
}
|
||||
cmdline, err := expandCmdline(spec.Cmdline, template.FuncMap{"ID": f})
|
||||
cmdline, err := expandCmdline(spec.Cmdline, template.FuncMap{"ID": f, "ServerHost": dummyServerHost})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -237,7 +241,7 @@ func (b *apibooter) BootSpec(m Machine) (*Spec, error) {
|
||||
}
|
||||
return fmt.Sprintf("{{ ID %q }}", id), nil
|
||||
}
|
||||
ret.Cmdline, err = expandCmdline(ret.Cmdline, template.FuncMap{"URL": f})
|
||||
ret.Cmdline, err = expandCmdline(ret.Cmdline, template.FuncMap{"URL": f, "ServerHost": dummyServerHost})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -207,10 +207,14 @@ func ipxeScript(mach Machine, spec *Spec, serverHost string) ([]byte, error) {
|
||||
fmt.Fprintf(&b, "initrd=initrd%d ", i)
|
||||
}
|
||||
|
||||
f := func(id string) string {
|
||||
idFunc := func(id string) string {
|
||||
return fmt.Sprintf("http://%s/_/file?name=%s", serverHost, url.QueryEscape(id))
|
||||
}
|
||||
cmdline, err := expandCmdline(spec.Cmdline, template.FuncMap{"ID": f})
|
||||
serverHostFunc := func() string {
|
||||
return serverHost
|
||||
}
|
||||
cmdline, err := expandCmdline(spec.Cmdline,
|
||||
template.FuncMap{"ID": idFunc, "ServerHost": serverHostFunc})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("expanding cmdline %q: %s", spec.Cmdline, err)
|
||||
}
|
||||
|
@ -77,9 +77,10 @@ type Spec struct {
|
||||
// Optional init ramdisks for linux kernels
|
||||
Initrd []ID
|
||||
// Optional kernel commandline. This string is evaluated as a
|
||||
// text/template template, in which "ID(x)" function is
|
||||
// available. Invoking ID(x) returns a URL that will call
|
||||
// Booter.ReadBootFile(x) when fetched.
|
||||
// text/template template, in which these functions are available:
|
||||
// "ID(x)": returns a URL that will call
|
||||
// Booter.ReadBootFile(x) when fetched.
|
||||
// "ServerHost()": returns the server address of the http server
|
||||
Cmdline string
|
||||
// Message to print on the client machine before booting.
|
||||
Message string
|
||||
|
Loading…
Reference in New Issue
Block a user