adapt ui to new assets
This commit is contained in:
@@ -262,14 +262,17 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
for _, item := range set.Items {
|
||||
names := make([]string, 0)
|
||||
section := ""
|
||||
switch item.Kind {
|
||||
case "cluster":
|
||||
section = "Cluster"
|
||||
for _, c := range cfg.Clusters {
|
||||
if globMatch(item.Name, c.Name) {
|
||||
names = append(names, c.Name)
|
||||
}
|
||||
}
|
||||
case "host":
|
||||
section = "Host"
|
||||
for _, h := range cfg.Hosts {
|
||||
if globMatch(item.Name, h.Name) {
|
||||
names = append(names, h.Name)
|
||||
@@ -278,12 +281,22 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
fmt.Fprintf(buf, "<h2>%s %s</h2>", strings.Title(item.Kind), name)
|
||||
fmt.Fprintf(buf, "<p class=\"download-links\">\n")
|
||||
buf.WriteString("<p>")
|
||||
fmt.Fprintf(buf, "<strong>%s %s:</strong>", section, name)
|
||||
buf.WriteString(" <span class=\"download-links\">")
|
||||
for _, asset := range item.Assets {
|
||||
fmt.Fprintf(buf, " <a href=\"/public/download-set/%s/%s/%s?set=%s\" download>%s</a>\n", item.Kind, name, asset, setStr, asset)
|
||||
for _, v := range hostAssetVariants(asset) {
|
||||
url := fmt.Sprintf("/public/download-set/%s/%s/%s", item.Kind, name, v.url)
|
||||
if strings.Contains(url, "?") {
|
||||
url += "&"
|
||||
} else {
|
||||
url += "?"
|
||||
}
|
||||
url += "set=" + setStr
|
||||
fmt.Fprintf(buf, " <a href=\"%s\" download>%s</a>\n", url, v.name)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(buf, `</p>`)
|
||||
buf.WriteString("</span></p>\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -188,11 +188,15 @@ func wsDownloadPage(req *restful.Request, resp *restful.Response) {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteString(htmlHeader(fmt.Sprintf("Token assets: %s %s", spec.Kind, spec.Name)))
|
||||
|
||||
buf.WriteString("<ul>")
|
||||
buf.WriteString("<table class=\"download-table\">")
|
||||
for _, asset := range spec.Assets {
|
||||
fmt.Fprintf(buf, "<li><a href=\"%s\" download>%s</a></li>\n", asset, asset)
|
||||
buf.WriteString("<tr>")
|
||||
for _, v := range hostAssetVariants(asset) {
|
||||
fmt.Fprintf(buf, "<td><a href=\"%s\" download>%s</a></td>", v.url, v.name)
|
||||
}
|
||||
buf.WriteString("</tr>\n")
|
||||
}
|
||||
buf.WriteString("</ul>")
|
||||
buf.WriteString("</table>")
|
||||
|
||||
buf.WriteString(htmlFooter)
|
||||
buf.WriteTo(resp)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -14,10 +13,36 @@ import (
|
||||
"novit.tech/direktil/local-server/pkg/mime"
|
||||
)
|
||||
|
||||
var (
|
||||
allowDetectedHost = flag.Bool("allow-detected-host", false, "Allow access to host assets from its IP (insecure but enables unattended netboot)")
|
||||
trustXFF = flag.Bool("trust-xff", false, "Trust the X-Forwarded-For header")
|
||||
)
|
||||
type AssetVariant struct {
|
||||
name string
|
||||
url string
|
||||
}
|
||||
|
||||
func hostAssetVariants(asset string) []AssetVariant {
|
||||
switch asset {
|
||||
case "uki":
|
||||
return []AssetVariant{
|
||||
{asset, asset},
|
||||
{asset + " (serial)", asset + "?serial=0"},
|
||||
}
|
||||
case "boot.img",
|
||||
"boot.img.gz",
|
||||
"boot.qcow2",
|
||||
"boot.qed",
|
||||
"boot.vdi",
|
||||
"boot.vmdk",
|
||||
"boot.vpc",
|
||||
"boot.iso",
|
||||
"boot.tar":
|
||||
return []AssetVariant{
|
||||
{asset, asset},
|
||||
{asset + " (UKI)", asset + "?uki"},
|
||||
{asset + " (UKI+serial)", asset + "?uki&serial=0"},
|
||||
}
|
||||
default:
|
||||
return []AssetVariant{{asset, asset}}
|
||||
}
|
||||
}
|
||||
|
||||
type wsHost struct {
|
||||
hostDoc string
|
||||
@@ -52,9 +77,6 @@ func (ws wsHost) register(rws *restful.WebService, alterRB func(*restful.RouteBu
|
||||
b("boot.img.gz").
|
||||
Produces(mime.DISK + "+gzip").
|
||||
Doc("Get the " + ws.hostDoc + "'s boot disk image, gzip compressed"),
|
||||
b("boot.img.lz4").
|
||||
Produces(mime.DISK + "+lz4").
|
||||
Doc("Get the " + ws.hostDoc + "'s boot disk image, lz4 compressed"),
|
||||
|
||||
// - other formats
|
||||
b("boot.qcow2").
|
||||
@@ -188,19 +210,12 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
|
||||
}
|
||||
|
||||
switch what {
|
||||
case "config":
|
||||
err = renderConfig(w, r, ctx, false)
|
||||
case "config.json":
|
||||
err = renderConfig(w, r, ctx, true)
|
||||
|
||||
case "ipxe":
|
||||
err = renderIPXE(w, ctx)
|
||||
|
||||
case "kernel":
|
||||
err = renderKernel(w, r, ctx)
|
||||
case "initrd":
|
||||
err = renderCtx(w, r, ctx, what, buildInitrd)
|
||||
case "uki":
|
||||
uki = true
|
||||
err = renderCtx(w, r, ctx, what, withUki(buildUki))
|
||||
|
||||
case "bootstrap.tar":
|
||||
@@ -230,6 +245,14 @@ func renderHost(w http.ResponseWriter, r *http.Request, what string, host *local
|
||||
case "bootstrap-config":
|
||||
err = renderBootstrapConfig(w, ctx)
|
||||
|
||||
case "config":
|
||||
err = renderConfig(w, r, ctx, false)
|
||||
case "config.json":
|
||||
err = renderConfig(w, r, ctx, true)
|
||||
|
||||
case "ipxe":
|
||||
err = renderIPXE(w, ctx)
|
||||
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user