github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/status/formatted.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package status 5 6 import ( 7 "encoding/json" 8 9 "github.com/juju/juju/instance" 10 "github.com/juju/juju/status" 11 ) 12 13 type formattedStatus struct { 14 Model string `json:"model"` 15 ModelStatus *modelStatus `json:"model-status,omitempty" yaml:"model-status,omitempty"` 16 Machines map[string]machineStatus `json:"machines"` 17 Services map[string]serviceStatus `json:"services"` 18 } 19 20 type formattedMachineStatus struct { 21 Model string `json:"model"` 22 Machines map[string]machineStatus `json:"machines"` 23 } 24 25 type errorStatus struct { 26 StatusError string `json:"status-error" yaml:"status-error"` 27 } 28 29 type modelStatus struct { 30 AvailableVersion string `json:"upgrade-available,omitempty" yaml:"upgrade-available,omitempty"` 31 } 32 33 type machineStatus struct { 34 Err error `json:"-" yaml:",omitempty"` 35 JujuStatus statusInfoContents `json:"juju-status,omitempty" yaml:"juju-status,omitempty"` 36 DNSName string `json:"dns-name,omitempty" yaml:"dns-name,omitempty"` 37 InstanceId instance.Id `json:"instance-id,omitempty" yaml:"instance-id,omitempty"` 38 MachineStatus statusInfoContents `json:"machine-status,omitempty" yaml:"machine-status,omitempty"` 39 Series string `json:"series,omitempty" yaml:"series,omitempty"` 40 Id string `json:"-" yaml:"-"` 41 Containers map[string]machineStatus `json:"containers,omitempty" yaml:"containers,omitempty"` 42 Hardware string `json:"hardware,omitempty" yaml:"hardware,omitempty"` 43 HAStatus string `json:"controller-member-status,omitempty" yaml:"controller-member-status,omitempty"` 44 } 45 46 // A goyaml bug means we can't declare these types 47 // locally to the GetYAML methods. 48 type machineStatusNoMarshal machineStatus 49 50 func (s machineStatus) MarshalJSON() ([]byte, error) { 51 if s.Err != nil { 52 return json.Marshal(errorStatus{s.Err.Error()}) 53 } 54 return json.Marshal(machineStatusNoMarshal(s)) 55 } 56 57 func (s machineStatus) MarshalYAML() (interface{}, error) { 58 if s.Err != nil { 59 return errorStatus{s.Err.Error()}, nil 60 } 61 return machineStatusNoMarshal(s), nil 62 } 63 64 type serviceStatus struct { 65 Err error `json:"-" yaml:",omitempty"` 66 Charm string `json:"charm" yaml:"charm"` 67 CanUpgradeTo string `json:"can-upgrade-to,omitempty" yaml:"can-upgrade-to,omitempty"` 68 Exposed bool `json:"exposed" yaml:"exposed"` 69 Life string `json:"life,omitempty" yaml:"life,omitempty"` 70 StatusInfo statusInfoContents `json:"service-status,omitempty" yaml:"service-status"` 71 Relations map[string][]string `json:"relations,omitempty" yaml:"relations,omitempty"` 72 SubordinateTo []string `json:"subordinate-to,omitempty" yaml:"subordinate-to,omitempty"` 73 Units map[string]unitStatus `json:"units,omitempty" yaml:"units,omitempty"` 74 } 75 76 type serviceStatusNoMarshal serviceStatus 77 78 func (s serviceStatus) MarshalJSON() ([]byte, error) { 79 if s.Err != nil { 80 return json.Marshal(errorStatus{s.Err.Error()}) 81 } 82 return json.Marshal(serviceStatusNoMarshal(s)) 83 } 84 85 func (s serviceStatus) MarshalYAML() (interface{}, error) { 86 if s.Err != nil { 87 return errorStatus{s.Err.Error()}, nil 88 } 89 return serviceStatusNoMarshal(s), nil 90 } 91 92 type meterStatus struct { 93 Color string `json:"color,omitempty" yaml:"color,omitempty"` 94 Message string `json:"message,omitempty" yaml:"message,omitempty"` 95 } 96 97 type unitStatus struct { 98 // New Juju Health Status fields. 99 WorkloadStatusInfo statusInfoContents `json:"workload-status,omitempty" yaml:"workload-status"` 100 JujuStatusInfo statusInfoContents `json:"juju-status,omitempty" yaml:"juju-status"` 101 MeterStatus *meterStatus `json:"meter-status,omitempty" yaml:"meter-status,omitempty"` 102 103 Charm string `json:"upgrading-from,omitempty" yaml:"upgrading-from,omitempty"` 104 Machine string `json:"machine,omitempty" yaml:"machine,omitempty"` 105 OpenedPorts []string `json:"open-ports,omitempty" yaml:"open-ports,omitempty"` 106 PublicAddress string `json:"public-address,omitempty" yaml:"public-address,omitempty"` 107 Subordinates map[string]unitStatus `json:"subordinates,omitempty" yaml:"subordinates,omitempty"` 108 } 109 110 type statusInfoContents struct { 111 Err error `json:"-" yaml:",omitempty"` 112 Current status.Status `json:"current,omitempty" yaml:"current,omitempty"` 113 Message string `json:"message,omitempty" yaml:"message,omitempty"` 114 Since string `json:"since,omitempty" yaml:"since,omitempty"` 115 Version string `json:"version,omitempty" yaml:"version,omitempty"` 116 Life string `json:"life,omitempty" yaml:"life,omitempty"` 117 } 118 119 type statusInfoContentsNoMarshal statusInfoContents 120 121 func (s statusInfoContents) MarshalJSON() ([]byte, error) { 122 if s.Err != nil { 123 return json.Marshal(errorStatus{s.Err.Error()}) 124 } 125 return json.Marshal(statusInfoContentsNoMarshal(s)) 126 } 127 128 func (s statusInfoContents) MarshalYAML() (interface{}, error) { 129 if s.Err != nil { 130 return errorStatus{s.Err.Error()}, nil 131 } 132 return statusInfoContentsNoMarshal(s), nil 133 } 134 135 type unitStatusNoMarshal unitStatus 136 137 func (s unitStatus) MarshalJSON() ([]byte, error) { 138 if s.WorkloadStatusInfo.Err != nil { 139 return json.Marshal(errorStatus{s.WorkloadStatusInfo.Err.Error()}) 140 } 141 return json.Marshal(unitStatusNoMarshal(s)) 142 } 143 144 func (s unitStatus) MarshalYAML() (interface{}, error) { 145 if s.WorkloadStatusInfo.Err != nil { 146 return errorStatus{s.WorkloadStatusInfo.Err.Error()}, nil 147 } 148 return unitStatusNoMarshal(s), nil 149 }