Add function to get endpoint by its name

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-15 01:17:13 -04:00
parent d28a78cf28
commit a6f4f88fd2

View File

@ -11,6 +11,7 @@ import (
const (
ErrStackNotFound = Error("Stack not found")
ErrStackClusterNotFound = Error("Stack cluster not found")
ErrEndpointNotFound = Error("Endpoint not found")
ErrSeveralEndpointsAvailable = Error("Several endpoints available")
ErrNoEndpointsAvailable = Error("No endpoints available")
)
@ -71,6 +72,26 @@ func GetStackByName(name string, swarmId string, endpointId portainer.EndpointID
return
}
func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
portainerClient, err := GetClient()
if err != nil {
return
}
endpoints, err := portainerClient.GetEndpoints()
if err != nil {
return
}
for _, endpoint := range endpoints {
if endpoint.Name == name {
return endpoint, nil
}
}
err = ErrEndpointNotFound
return
}
func GetEndpointSwarmClusterId(endpointId portainer.EndpointID) (endpointSwarmClusterId string, err error) {
// Get docker information for endpoint
portainerClient, err := GetClient()