/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ package state import "strings" const ( // Zero value NULL State = 0 // VRRP instance is master and owns the VIP MASTER = 1 << iota // VRRP instance is now a backup, and does not own the VIP BACKUP // VRRP instance has exited STOP // Unknown state was encountered, aliases NULL UNKNOWN State = NULL ) var ( s2s map[string]State = map[string]State{ "MASTER": MASTER, "BACKUP": BACKUP, "STOP": STOP, } ) func ParseState(i string) State { i = strings.TrimSpace(i) s, ok := s2s[i] if !ok { return UNKNOWN } return s } type State uint8 func (t State) Has(flag State) bool { return t&flag != 0 } func (s State) Is(other State) bool { return s == other } func (s State) IsMaster() bool { return s.Is(MASTER) } func (s State) IsBackup() bool { return s.Is(BACKUP) } func (s State) IsStop() bool { return s.Is(STOP) } func (s State) IsUnknown() bool { return s.Is(UNKNOWN) } func (s State) String() string { var o string switch s { case UNKNOWN: o = "UNKNOWN" case MASTER: o = "MASTER" case BACKUP: o = "BACKUP" case STOP: o = "STOP" default: panic("missing case in notify/ty/flags.go:String()") } return o }