forked from rancher/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_check.go
49 lines (43 loc) · 1.41 KB
/
compute_check.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
39
40
41
42
43
44
45
46
47
48
49
package compute
import (
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/rancher/agent/model"
"github.com/rancher/agent/utilities/constants"
"github.com/rancher/agent/utilities/utils"
)
func IsInstanceActive(instance model.Instance, host model.Host, client *client.Client) (bool, error) {
if utils.IsNoOp(instance.ProcessData) {
return true, nil
}
container, err := utils.GetContainer(client, instance, false)
if err != nil {
if utils.IsContainerNotFoundError(err) {
return false, nil
}
return false, errors.Wrap(err, constants.IsInstanceActiveError+"failed to get container")
}
return isRunning(client, container)
}
func IsInstanceInactive(instance model.Instance, client *client.Client) (bool, error) {
if utils.IsNoOp(instance.ProcessData) {
return true, nil
}
container, err := utils.GetContainer(client, instance, false)
if err != nil {
if !utils.IsContainerNotFoundError(err) {
return false, errors.Wrap(err, constants.IsInstanceInactiveError+"failed to get container")
}
}
return isStopped(client, container)
}
func IsInstanceRemoved(instance model.Instance, dockerClient *client.Client) (bool, error) {
con, err := utils.GetContainer(dockerClient, instance, false)
if err != nil {
if utils.IsContainerNotFoundError(err) {
return true, nil
}
return false, errors.Wrap(err, constants.IsInstanceRemovedError+"failed to get container")
}
return con.ID == "", nil
}