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