github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/qdrmanagement/entities/autolink.go (about) 1 package entities 2 3 import ( 4 "encoding/json" 5 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common" 6 "strconv" 7 "strings" 8 ) 9 10 type AutoLink struct { 11 EntityCommon 12 Address string `json:"address"` 13 Direction common.DirectionType `json:"direction,string"` 14 Phase int `json:"phase"` 15 ContainerId string `json:"containerId"` 16 Connection string `json:"connection"` 17 ExternalAddress string `json:"externalAddress"` 18 Fallback bool `json:"fallback"` 19 LinkRef string `json:"linkRef"` 20 OperStatus AutoLinkOperStatusType `json:"operStatus,string"` 21 LastError string `json:"lastError"` 22 } 23 24 func (AutoLink) GetEntityId() string { 25 return "router.config.autoLink" 26 } 27 28 type AutoLinkOperStatusType int 29 30 const ( 31 AutoLinkOperStatusInactive AutoLinkOperStatusType = iota 32 AutoLinkOperStatusAttaching 33 AutoLinkOperStatusFailed 34 AutoLinkOperStatusActive 35 AutoLinkOperStatusQuiescing 36 AutoLinkOperStatusIdle 37 ) 38 39 // UnmarshalJSON returns the appropriate AutoLinkOperStatusType for parsed string 40 func (o *AutoLinkOperStatusType) UnmarshalJSON(b []byte) error { 41 var s string 42 43 if len(b) == 0 { 44 return nil 45 } 46 if b[0] != '"' { 47 b = []byte(strconv.Quote(string(b))) 48 } 49 if err := json.Unmarshal(b, &s); err != nil { 50 return err 51 } 52 switch strings.ToLower(s) { 53 case "inactive": 54 *o = AutoLinkOperStatusInactive 55 case "attaching": 56 *o = AutoLinkOperStatusAttaching 57 case "failed": 58 *o = AutoLinkOperStatusFailed 59 case "active": 60 *o = AutoLinkOperStatusActive 61 case "quiescing": 62 *o = AutoLinkOperStatusQuiescing 63 case "idle": 64 *o = AutoLinkOperStatusIdle 65 } 66 return nil 67 } 68 69 // MarshalJSON returns the string representation of AutoLinkOperStatusType 70 func (o AutoLinkOperStatusType) MarshalJSON() ([]byte, error) { 71 var s string 72 switch o { 73 case AutoLinkOperStatusInactive: 74 s = "inactive" 75 case AutoLinkOperStatusAttaching: 76 s = "attaching" 77 case AutoLinkOperStatusFailed: 78 s = "failed" 79 case AutoLinkOperStatusActive: 80 s = "active" 81 case AutoLinkOperStatusQuiescing: 82 s = "quiescing" 83 case AutoLinkOperStatusIdle: 84 s = "idle" 85 } 86 return json.Marshal(s) 87 }