+check container name and not image name
This commit is contained in:
parent
f12bf1a327
commit
0d7900912b
1 changed files with 10 additions and 10 deletions
20
main.go
20
main.go
|
@ -68,15 +68,16 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
|
||||||
var ctr Containers
|
var ctr Containers
|
||||||
|
|
||||||
for _, host := range hosts.Hosts {
|
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.Adds(get_ollama_containers(host, false))
|
||||||
// ctr = append(ctr, get_ollama_containers(host)...)
|
// ctr = append(ctr, get_ollama_containers(host)...)
|
||||||
fmt.Println(ctr)
|
// fmt.Println(ctr)
|
||||||
}
|
}
|
||||||
|
|
||||||
retval := []Model{}
|
retval := []Model{}
|
||||||
|
|
||||||
for _, ollama := range ctr.Containers {
|
for _, ollama := range ctr.Containers {
|
||||||
|
// fmt.Println(ollama)
|
||||||
if ollama.State != "running" {
|
if ollama.State != "running" {
|
||||||
retval = append(retval, Model{Ip: ollama.IP, Port: ollama.Port, State: "stopped"})
|
retval = append(retval, Model{Ip: ollama.IP, Port: ollama.Port, State: "stopped"})
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,16 +98,15 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Models{}, fmt.Errorf("failed to unmarshal JSON: %v", err)
|
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 {
|
for n := range mods.Models {
|
||||||
mods.Models[n].Ip = ollama.IP
|
mods.Models[n].Ip = ollama.IP
|
||||||
mods.Models[n].Port = ollama.Port
|
mods.Models[n].Port = ollama.Port
|
||||||
mods.Models[n].State = "running"
|
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...)
|
retval = append(retval, mods.Models...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func get_ollama_containers(host Host, all bool) Containers {
|
||||||
|
|
||||||
ctr_list := 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)))
|
cli, err := client.NewClientWithOpts(client.WithHost(fmt.Sprintf("tcp://%s:%s", host.IP, host.Port)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -133,10 +133,10 @@ func get_ollama_containers(host Host, all bool) Containers {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ctr := range 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}
|
c := Container{ID: ctr.ID, Name: ctr.Names[0], Image: ctr.Image, State: ctr.State, Status: ctr.Status}
|
||||||
if ctr.State == "running" {
|
if ctr.State == "running" {
|
||||||
fmt.Println(ctr.Ports[0])
|
// fmt.Println(ctr.Ports[0])
|
||||||
c.Port = int(ctr.Ports[0].PublicPort)
|
c.Port = int(ctr.Ports[0].PublicPort)
|
||||||
}
|
}
|
||||||
c.IP = host.IP
|
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
|
return ctr_list
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ func main() {
|
||||||
|
|
||||||
r.ForwardedByClientIP = true
|
r.ForwardedByClientIP = true
|
||||||
|
|
||||||
fmt.Println("liste")
|
fmt.Println("Starting server on port " + port)
|
||||||
r.Run(":" + port)
|
r.Run(":" + port)
|
||||||
|
|
||||||
fmt.Print("END")
|
fmt.Print("END")
|
||||||
|
|
Loading…
Add table
Reference in a new issue