github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/services/results.go (about) 1 package services 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/pagination" 9 ) 10 11 // Service represents a Blockstorage service in the OpenStack cloud. 12 type Service struct { 13 // The binary name of the service. 14 Binary string `json:"binary"` 15 16 // The reason for disabling a service. 17 DisabledReason string `json:"disabled_reason"` 18 19 // The name of the host. 20 Host string `json:"host"` 21 22 // The state of the service. One of up or down. 23 State string `json:"state"` 24 25 // The status of the service. One of available or unavailable. 26 Status string `json:"status"` 27 28 // The date and time stamp when the extension was last updated. 29 UpdatedAt time.Time `json:"-"` 30 31 // The availability zone name. 32 Zone string `json:"zone"` 33 34 // The following fields are optional 35 36 // The host is frozen or not. Only in cinder-volume service. 37 Frozen bool `json:"frozen"` 38 39 // The cluster name. Only in cinder-volume service. 40 Cluster string `json:"cluster"` 41 42 // The volume service replication status. Only in cinder-volume service. 43 ReplicationStatus string `json:"replication_status"` 44 45 // The ID of active storage backend. Only in cinder-volume service. 46 ActiveBackendID string `json:"active_backend_id"` 47 } 48 49 // UnmarshalJSON to override default 50 func (r *Service) UnmarshalJSON(b []byte) error { 51 type tmp Service 52 var s struct { 53 tmp 54 UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"` 55 } 56 err := json.Unmarshal(b, &s) 57 if err != nil { 58 return err 59 } 60 *r = Service(s.tmp) 61 62 r.UpdatedAt = time.Time(s.UpdatedAt) 63 64 return nil 65 } 66 67 // ServicePage represents a single page of all Services from a List request. 68 type ServicePage struct { 69 pagination.SinglePageBase 70 } 71 72 // IsEmpty determines whether or not a page of Services contains any results. 73 func (page ServicePage) IsEmpty() (bool, error) { 74 services, err := ExtractServices(page) 75 return len(services) == 0, err 76 } 77 78 func ExtractServices(r pagination.Page) ([]Service, error) { 79 var s struct { 80 Service []Service `json:"services"` 81 } 82 err := (r.(ServicePage)).ExtractInto(&s) 83 return s.Service, err 84 }