+check container name and not image name

This commit is contained in:
Miki 2024-06-06 10:29:32 +02:00
parent f12bf1a327
commit 0d7900912b

20
main.go
View file

@ -68,15 +68,16 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
var ctr Containers
for _, host := range hosts.Hosts {
fmt.Printf("%s -> %s\n", host.Name, host.IP)
fmt.Printf("HOST: %s -> %s\n", host.Name, host.IP)
ctr.Adds(get_ollama_containers(host, false))
// ctr = append(ctr, get_ollama_containers(host)...)
fmt.Println(ctr)
// fmt.Println(ctr)
}
retval := []Model{}
for _, ollama := range ctr.Containers {
// fmt.Println(ollama)
if ollama.State != "running" {
retval = append(retval, Model{Ip: ollama.IP, Port: ollama.Port, State: "stopped"})
} else {
@ -97,16 +98,15 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
if err != nil {
return Models{}, fmt.Errorf("failed to unmarshal JSON: %v", err)
}
fmt.Printf("%+v\n", mods)
// fmt.Printf("%+v\n", mods)
for n := range mods.Models {
mods.Models[n].Ip = ollama.IP
mods.Models[n].Port = ollama.Port
mods.Models[n].State = "running"
fmt.Printf("mod: %s - %s:%d\n", mods.Models[n].Name, mods.Models[n].Ip, mods.Models[n].Port)
}
fmt.Printf("mod: %+v\n", mods)
retval = append(retval, mods.Models...)
}
}
@ -118,7 +118,7 @@ func get_ollama_containers(host Host, all bool) Containers {
ctr_list := Containers{}
fmt.Printf("%s -> %s\n", host.Name, host.IP)
// fmt.Printf("%s -> %s\n", host.Name, host.IP)
cli, err := client.NewClientWithOpts(client.WithHost(fmt.Sprintf("tcp://%s:%s", host.IP, host.Port)))
if err != nil {
fmt.Println(err)
@ -133,10 +133,10 @@ func get_ollama_containers(host Host, all bool) Containers {
}
for _, ctr := range containers {
if strings.Contains(ctr.Names[0], "ollama") && ctr.Image == "ollama/ollama" {
if strings.Contains(ctr.Names[0], "ollama") { //&& ctr.Image == "ollama/ollama" {
c := Container{ID: ctr.ID, Name: ctr.Names[0], Image: ctr.Image, State: ctr.State, Status: ctr.Status}
if ctr.State == "running" {
fmt.Println(ctr.Ports[0])
// fmt.Println(ctr.Ports[0])
c.Port = int(ctr.Ports[0].PublicPort)
}
c.IP = host.IP
@ -145,7 +145,7 @@ func get_ollama_containers(host Host, all bool) Containers {
}
}
fmt.Println(ctr_list)
// fmt.Println(ctr_list)
return ctr_list
}
@ -194,7 +194,7 @@ func main() {
r.ForwardedByClientIP = true
fmt.Println("liste")
fmt.Println("Starting server on port " + port)
r.Run(":" + port)
fmt.Print("END")