MCPcopy Create free account
hub / github.com/danderson/netboot / ipxeScript

Function ipxeScript

pixiecore/http.go:183–221  ·  view source on GitHub ↗
(mach Machine, spec *Spec, serverHost string)

Source from the content-addressed store, hash-verified

181}
182
183func ipxeScript(mach Machine, spec *Spec, serverHost string) ([]byte, error) {
184 if spec.IpxeScript != "" {
185 return []byte(spec.IpxeScript), nil
186 }
187
188 if spec.Kernel == "" {
189 return nil, errors.New("spec is missing Kernel")
190 }
191
192 urlTemplate := fmt.Sprintf("http://%s/_/file?name=%%s&type=%%s&mac=%%s", serverHost)
193 var b bytes.Buffer
194 b.WriteString("#!ipxe\n")
195 u := fmt.Sprintf(urlTemplate, url.QueryEscape(string(spec.Kernel)), "kernel", url.QueryEscape(mach.MAC.String()))
196 fmt.Fprintf(&b, "kernel --name kernel %s\n", u)
197 for i, initrd := range spec.Initrd {
198 u = fmt.Sprintf(urlTemplate, url.QueryEscape(string(initrd)), "initrd", url.QueryEscape(mach.MAC.String()))
199 fmt.Fprintf(&b, "initrd --name initrd%d %s\n", i, u)
200 }
201
202 fmt.Fprintf(&b, "imgfetch --name ready http://%s/_/booting?mac=%s ||\n", serverHost, url.QueryEscape(mach.MAC.String()))
203 b.WriteString("imgfree ready ||\n")
204
205 b.WriteString("boot kernel ")
206 for i := range spec.Initrd {
207 fmt.Fprintf(&b, "initrd=initrd%d ", i)
208 }
209
210 f := func(id string) string {
211 return fmt.Sprintf("http://%s/_/file?name=%s", serverHost, url.QueryEscape(id))
212 }
213 cmdline, err := expandCmdline(spec.Cmdline, template.FuncMap{"ID": f})
214 if err != nil {
215 return nil, fmt.Errorf("expanding cmdline %q: %s", spec.Cmdline, err)
216 }
217 b.WriteString(cmdline)
218 b.WriteByte('\n')
219
220 return b.Bytes(), nil
221}

Callers 1

handleIpxeMethod · 0.85

Calls 3

expandCmdlineFunction · 0.85
BytesMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected