This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
85 lines (74 loc) · 2.21 KB
/
node.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package entities
import (
"net"
"time"
)
const (
NodeStatusNew = "NEW"
NodeStatusDeploying = "DEPLOYING"
NodeStatusActive = "ACTIVE"
NodeStatusReady = "READY"
NodeStatusFailing = "FAILING"
NodeStatusRetrying = "RETRYING"
NodeStatusRestarting = "RESTARTING"
NodeStatusStopped = "STOPPED"
NodeStatusError = "ERROR"
NodeStatusDeleted = "DELETED"
)
type Node struct {
ID string `json:"id"`
ProviderID string `json:"providerId"`
NodeToken string `json:"nodeToken"`
IsMaster bool `json:"isMaster"`
MasterIP net.IP `json:"masterIP"`
Tags []string `json:"tags"`
Name string `json:"name"`
IPV4 net.IP `json:"ipv4"`
IPV6 net.IP `json:"ipv6"`
Status string `json:"status"`
Retries int `json:"retries"`
Error string `json:"error"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Deleted *time.Time `json:"deleted"`
Features NodeFeatures `json:"features"`
Dependencies []Dependency `json:"dependencies"`
InstallPassword string `json:"installPassword"`
InstallUser string `json:"installUser"`
//TODO: Add data as needed
}
type NodeFeatures map[string] bool
func(ma *Node) NeedsAdapting() bool{
return ma.Status == NodeStatusNew || ma.Status == NodeStatusActive || ma.Status == NodeStatusRetrying
}
func(n *Node) Retry() (*Node){
if(n.Retries> 10){
n.Status = NodeStatusFailing
return n
}
n.Retries = n.Retries+1
n.Status = NodeStatusRetrying
return n
}
func (ma *Node) Requires(dependency string) bool {
for i := range ma.Dependencies {
if(ma.Dependencies[i].Name == dependency){
if(ma.Dependencies[i].Status == DependencyStatusNew ||
ma.Dependencies[i].Status == DependencyStatusRetrying ||
ma.Dependencies[i].Status == DependencyStatusWaiting ){
return true
}
}
}
return false
}
func (ma *Node) Fulfils(dependency string) bool {
for i := range ma.Dependencies {
if(ma.Dependencies[i].Name == dependency){
if(ma.Dependencies[i].Status == DependencyStatusReady){
return true
}
}
}
return false
}