Add function to get endpoint group by name

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-17 16:37:41 -04:00
parent d2030e6bfb
commit b4f6dd7476

View File

@ -12,6 +12,7 @@ const (
ErrStackNotFound = Error("Stack not found")
ErrStackClusterNotFound = Error("Stack cluster not found")
ErrEndpointNotFound = Error("Endpoint not found")
ErrEndpointGroupNotFound = Error("Endpoint group not found")
ErrSeveralEndpointsAvailable = Error("Several endpoints available")
ErrNoEndpointsAvailable = Error("No endpoints available")
)
@ -92,6 +93,26 @@ func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) {
return
}
func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup, err error) {
portainerClient, err := GetClient()
if err != nil {
return
}
endpointGroups, err := portainerClient.GetEndpointGroups()
if err != nil {
return
}
for _, endpointGroup := range endpointGroups {
if endpointGroup.Name == name {
return endpointGroup, nil
}
}
err = ErrEndpointGroupNotFound
return
}
func GetEndpointFromListById(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) {
for i := range endpoints {
if endpoints[i].ID == id {