Refactor of server, logging, building of images, template updates

* Combine provision response handling, add hwaddr and interface to dhcp
* Simplify stage cases, add backward compatible uri parse
* Move control of image compression to client
* Fix kernel search path for ubuntu, buffer template generation
* Implement cpio and gz as functions, add log named functions
* Generalize fs image creation routine
* Combine daemonLogf to generalized wwlog
* Fix template newline insertion, update dhcp and hosts tmpl
* Update IPXE template to handle non-compressed files
* Update DHCP template to set network interfaces and server IP assignment
* Update DHCP/hosts templates to choose a host-name self-consistently
This commit is contained in:
Carter Dodd
2022-05-07 01:36:18 -05:00
parent fea148903c
commit 379faad51d
30 changed files with 1214 additions and 794 deletions

View File

@@ -14,14 +14,24 @@ type parserInfo struct {
remoteport int
assetkey string
uuid string
stage string
overlay string
compress string
}
func parseReq(req *http.Request) (parserInfo, error) {
var ret parserInfo
url := strings.Split(req.URL.Path, "?")[0]
hwaddr := strings.Split(url, "/")[2]
path_parts := strings.Split(url, "/")
if len(path_parts) != 3 {
return ret, errors.New("unknown path components in GET")
}
// handle when stage was passed in the url path /[stage]/hwaddr
stage := path_parts[1]
hwaddr := path_parts[2]
hwaddr = strings.ReplaceAll(hwaddr, "-", ":")
hwaddr = strings.ToLower(hwaddr)
@@ -36,9 +46,35 @@ func parseReq(req *http.Request) (parserInfo, error) {
if len(req.URL.Query()["uuid"]) > 0 {
ret.uuid = req.URL.Query()["uuid"][0]
}
if len(req.URL.Query()["stage"]) > 0 {
ret.stage = req.URL.Query()["stage"][0]
}else{
if stage == "ipxe" || stage == "provision" {
ret.stage = "ipxe"
}else if stage == "kernel" {
ret.stage = "kernel"
}else if stage == "kmods" {
ret.stage = "kmods"
}else if stage == "container" {
ret.stage = "container"
}else if stage == "overlay-system" {
ret.stage = "system"
}else if stage == "overlay-runtime" {
ret.stage = "runtime"
}
}
if len(req.URL.Query()["overlay"]) > 0 {
ret.overlay = req.URL.Query()["overlay"][0]
}
if len(req.URL.Query()["compress"]) > 0 {
ret.compress = req.URL.Query()["compress"][0]
}
if ret.stage == "" {
return ret, errors.New("no stage encoded in GET")
}
if ret.hwaddr == "" {
return ret, errors.New("no hwaddr encoded in GET")
}