Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/onie/onie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package onie

import "net/http"

// Register a handler which serves the given directory over HTTP. See the ONIE
// documentation for which file names are tried:
// https://opencomputeproject.github.io/onie/design-spec/discovery.html
func Register(mux *http.ServeMux, installerDir string) {
mux.Handle("GET /", http.FileServer(http.Dir(installerDir)))
}
11 changes: 4 additions & 7 deletions internal/ztp/ztp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ type SwitchParameters struct {
ASNumber int `json:"as_number"`
}

type Handler struct {
type handler struct {
t *template.Template
m map[netip.Addr]SwitchParameters
}

func NewZTPHandler(c Config) *Handler {
func Register(mux *http.ServeMux, c Config) {
t := template.New("ztp-scripts")
t = t.Funcs(template.FuncMap{
"add": func(a, b int) int { return a + b },
Expand All @@ -79,10 +79,7 @@ func NewZTPHandler(c Config) *Handler {
})
t = template.Must(t.ParseFS(templateFS, "templates/*.gotmpl"))

return &Handler{
t: t,
m: c.SwitchParams,
}
mux.Handle("GET /ztp", &handler{t: t, m: c.SwitchParams})
}

// interfacePrefix takes the interface ID and the /64 prefix of the switch and
Expand All @@ -101,7 +98,7 @@ func interfacePrefix(prefix netip.Prefix, interfaceID int) (string, error) {
return prefix.String(), nil
}

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ap, err := netip.ParseAddrPort(r.RemoteAddr)
if err != nil {
handleErr(w, err)
Expand Down
Loading