implement check commands for cores, memory and ips assigned

release/release-0.2.0
parent fba073fb3a
commit 1b7ea807d3

@ -9,6 +9,9 @@ import (
)
type ServersStatusCommand struct {
Comparator string `short:"c" long:"comp" description:"value to compare with" required:"no"`
Max int `short:"n" long:"max" description:"max value" required:"no"`
Min int `short:"m" long:"min" description:"minimal value" required:"no"`
Relation string `short:"r" long:"relation" description:"relation uuid to check" required:"no"`
ServerUUID string `short:"u" long:"uuid" description:"uuid of server to check" required:"yes"`
Status string `short:"s" long:"status" description:"value of status to compare against" choice:"active" choice:"deleted" required:"no"`
@ -48,6 +51,51 @@ func (x *ServersStatusCommand) Execute(args []string) error {
}
if x.Type == "server.cores" {
vm, err := gridscale.GetVM(Config.UserId, Config.Token, x.ServerUUID)
if err != nil {
Unknown(fmt.Sprintf("%s: %s", "Error retrieving server", err))
}
if vm.Server.Cores >= x.Min && vm.Server.Cores <= x.Max {
Ok(fmt.Sprintf("Expected amount (%d <= %d <= %d) of cores assigned: %d", x.Min, vm.Server.Cores, x.Max, vm.Server.Cores))
}
Critical(fmt.Sprintf("Expect amount (%d <= %d <= %d) of cores NOT assigned: %d", x.Min, vm.Server.Cores, x.Max, vm.Server.Cores))
}
if x.Type == "server.memory" {
vm, err := gridscale.GetVM(Config.UserId, Config.Token, x.ServerUUID)
if err != nil {
Unknown(fmt.Sprintf("%s: %s", "Error retrieving server", err))
}
if vm.Server.Memory >= x.Min && vm.Server.Memory <= x.Max {
Ok(fmt.Sprintf("Expected amount (%d <= %d <= %d) of memory assigned: %d", x.Min, vm.Server.Memory, x.Max, vm.Server.Memory))
}
Critical(fmt.Sprintf("Expect amount (%d <= %d <= %d) of memory NOT assigned: %d", x.Min, vm.Server.Memory, x.Max, vm.Server.Memory))
}
if x.Type == "ip.assigned" {
vm, err := gridscale.GetVM(Config.UserId, Config.Token, x.ServerUUID)
if err != nil {
Unknown(fmt.Sprintf("%s: %s", "Error retrieving server", err))
}
for _, ipRelation := range vm.IPsRelations {
if ipRelation.IP == x.Comparator || ipRelation.ObjectUUID == x.Relation {
Ok(fmt.Sprintf("Expected ip '%s' is assigned", ipRelation.IP))
}
}
Critical("Expected ip is NOT assigned!")
}
// never reached
return nil
}

Loading…
Cancel
Save