2024-03-10 07:15:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2024-03-14 01:12:48 +00:00
|
|
|
"net/http"
|
2024-03-12 01:39:17 +00:00
|
|
|
|
2024-03-16 17:09:58 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/lib/host"
|
2024-03-16 04:50:24 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/components"
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/layouts"
|
2024-03-15 17:55:28 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/static"
|
2024-03-16 04:50:24 +00:00
|
|
|
"github.com/a-h/templ"
|
2024-03-14 01:12:48 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
2024-03-10 07:15:49 +00:00
|
|
|
)
|
|
|
|
|
2024-03-14 01:12:48 +00:00
|
|
|
const DEBUG bool = true
|
|
|
|
|
2024-03-10 07:15:49 +00:00
|
|
|
func main() {
|
|
|
|
log.Println("Starting clustvirt, the libvirt cluster manager")
|
|
|
|
|
2024-03-16 17:09:58 +00:00
|
|
|
venus, err := host.ConnectHost(host.URI_QEMU_SSH_SYSTEM, "venus.staur.ca")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Println("Connected to host `venus.staur.ca`")
|
|
|
|
defer venus.Close()
|
2024-03-14 01:12:48 +00:00
|
|
|
//lm, err := venus.GetGuestByName("logan-minecraft")
|
|
|
|
//if err != nil {
|
|
|
|
// log.Fatal(err)
|
|
|
|
//}
|
|
|
|
//defer lm.Close()
|
|
|
|
|
|
|
|
// Start webserver and serve homepage
|
|
|
|
|
2024-03-16 04:50:24 +00:00
|
|
|
defaultNavBar := []components.NavItem{
|
|
|
|
{Name: "Home", Href: "/"},
|
|
|
|
{Name: "About", Href: "/about"},
|
|
|
|
}
|
2024-03-14 01:12:48 +00:00
|
|
|
fs := http.StripPrefix("/static/", http.FileServer(http.Dir("public")))
|
|
|
|
|
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Use(middleware.Logger)
|
2024-03-16 17:09:58 +00:00
|
|
|
if DEBUG {
|
|
|
|
r.Use(middleware.NoCache)
|
|
|
|
}
|
2024-03-14 01:12:48 +00:00
|
|
|
r.Get("/static/*", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
defer r.Body.Close()
|
|
|
|
fs.ServeHTTP(w, r)
|
|
|
|
})
|
2024-03-16 04:50:24 +00:00
|
|
|
r.Get("/", templ.Handler(layouts.Manager("Cluster Manager", "ClustVirt", defaultNavBar)).ServeHTTP)
|
|
|
|
r.Get("/about", templ.Handler(static.Home()).ServeHTTP)
|
2024-03-16 17:09:58 +00:00
|
|
|
r.Get("/chart", templ.Handler(components.HostInfo(venus)).ServeHTTP)
|
2024-03-14 01:12:48 +00:00
|
|
|
|
|
|
|
log.Println(http.ListenAndServe(":3000", r))
|
2024-03-10 07:15:49 +00:00
|
|
|
}
|