forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.go
38 lines (30 loc) · 1.12 KB
/
stack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package v2action
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
)
type Stack ccv2.Stack
// GetStack returns the stack information associated with the provided stack GUID.
func (actor Actor) GetStack(guid string) (Stack, Warnings, error) {
stack, warnings, err := actor.CloudControllerClient.GetStack(guid)
if _, ok := err.(ccerror.ResourceNotFoundError); ok {
return Stack{}, Warnings(warnings), actionerror.StackNotFoundError{GUID: guid}
}
return Stack(stack), Warnings(warnings), err
}
// GetStackByName returns the provided stack
func (actor Actor) GetStackByName(stackName string) (Stack, Warnings, error) {
stacks, warnings, err := actor.CloudControllerClient.GetStacks(ccv2.Query{
Filter: ccv2.NameFilter,
Operator: ccv2.EqualOperator,
Values: []string{stackName},
})
if err != nil {
return Stack{}, Warnings(warnings), err
}
if len(stacks) == 0 {
return Stack{}, Warnings(warnings), actionerror.StackNotFoundError{Name: stackName}
}
return Stack(stacks[0]), Warnings(warnings), nil
}