psu/common/utils.go

43 lines
717 B
Go
Raw Normal View History

2019-07-21 02:00:04 +00:00
package common
import (
"fmt"
)
func GetStackByName(name string) (stack Stack, err error) {
client, err := GetClient()
2019-07-21 02:00:04 +00:00
if err != nil {
return
2019-07-21 02:00:04 +00:00
}
stacks, err := client.GetStacks("", 0)
2019-07-21 02:00:04 +00:00
if err != nil {
return
2019-07-21 02:00:04 +00:00
}
PrintVerbose(fmt.Sprintf("Getting stack %s...", name))
for _, stack := range stacks {
if stack.Name == name {
return stack, nil
}
}
err = &StackNotFoundError{
2019-07-21 02:00:04 +00:00
StackName: name,
}
return
2019-07-21 02:00:04 +00:00
}
type StackListFilter struct {
SwarmId string `json:",omitempty"`
EndpointId uint32 `json:",omitempty"`
}
// Custom customerrors
type StackNotFoundError struct {
StackName string
}
func (e *StackNotFoundError) Error() string {
return fmt.Sprintf("Stack %s not found", e.StackName)
}