resource.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package redfish
  15. import (
  16. "fmt"
  17. "sort"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "yunion.io/x/onecloud/pkg/util/influxdb"
  22. )
  23. type SCdromInfo struct {
  24. Image string `json:"Image"`
  25. SupportAction bool `json:"SupportAction"`
  26. }
  27. type SSystemInfo struct {
  28. Manufacturer string `json:"Manufacturer"`
  29. Model string `json:"Model"`
  30. SKU string `json:"SKU"`
  31. SerialNumber string `json:"SerialNumber"`
  32. UUID string `json:"UUID"`
  33. EthernetNICs []string `json:"EthernetNICs"`
  34. MemoryGB int `json:"MemoryGB"`
  35. NodeCount int `json:"NodeCount"`
  36. CpuDesc string `json:"CpuDesc"`
  37. PowerState string `json:"PowerState"`
  38. NextBootDev string `json:"NextBootDev"`
  39. NextBootDevSupported []string `json:"NextBootDevSupported"`
  40. ResetTypeSupported []string `json:"ResetTypeSupported"`
  41. }
  42. const (
  43. EVENT_TYPE_SYSTEM = "system"
  44. EVENT_TYPE_MANAGER = "manager"
  45. )
  46. type SEvent struct {
  47. Created time.Time `json:"Created"`
  48. EventId string `json:"Id"`
  49. Message string `json:"Message"`
  50. Severity string `json:"Severity"`
  51. Type string `json:"type"`
  52. }
  53. type SEventList []SEvent
  54. func (el SEventList) Len() int { return len(el) }
  55. func (el SEventList) Swap(i, j int) { el[i], el[j] = el[j], el[i] }
  56. func (el SEventList) Less(i, j int) bool { return el[i].Created.Before(el[j].Created) }
  57. func SortEvents(el []SEvent) {
  58. sort.Sort(SEventList(el))
  59. }
  60. type SBiosInfo struct {
  61. }
  62. type SPower struct {
  63. PowerCapacityWatts int `json:"PowerCapacityWatts"`
  64. PowerConsumedWatts int `json:"PowerConsumedWatts"`
  65. PowerMetrics struct {
  66. AverageConsumedWatts int `json:"AverageConsumedWatts"`
  67. IntervalInMin int `json:"IntervalInMin"`
  68. MaxConsumedWatts int `json:"MaxConsumedWatts"`
  69. MinConsumedWatts int `json:"MinConsumedWatts"`
  70. } `json:"PowerMetrics"`
  71. }
  72. func (p SPower) ToMetrics() []influxdb.SKeyValue {
  73. return []influxdb.SKeyValue{
  74. {
  75. Key: "PowerCapacityWatts",
  76. Value: strconv.FormatInt(int64(p.PowerCapacityWatts), 10),
  77. },
  78. {
  79. Key: "PowerConsumedWatts",
  80. Value: strconv.FormatInt(int64(p.PowerConsumedWatts), 10),
  81. },
  82. {
  83. Key: "AverageConsumedWatts",
  84. Value: strconv.FormatInt(int64(p.PowerMetrics.AverageConsumedWatts), 10),
  85. },
  86. {
  87. Key: "IntervalInMin",
  88. Value: strconv.FormatInt(int64(p.PowerMetrics.IntervalInMin), 10),
  89. },
  90. {
  91. Key: "MaxConsumedWatts",
  92. Value: strconv.FormatInt(int64(p.PowerMetrics.MaxConsumedWatts), 10),
  93. },
  94. {
  95. Key: "MinConsumedWatts",
  96. Value: strconv.FormatInt(int64(p.PowerMetrics.MinConsumedWatts), 10),
  97. },
  98. }
  99. }
  100. type STemperature struct {
  101. Name string `json:"Name"`
  102. PhysicalContext string `json:"PhysicalContext"`
  103. ReadingCelsius int `json:"ReadingCelsius"`
  104. }
  105. func (t STemperature) ToMetric() influxdb.SKeyValue {
  106. return influxdb.SKeyValue{
  107. Key: fmt.Sprintf("%s/%s", t.PhysicalContext, strings.ReplaceAll(t.Name, " ", "")),
  108. Value: strconv.FormatInt(int64(t.ReadingCelsius), 10),
  109. }
  110. }
  111. type SNTPConf struct {
  112. NTPServers []string `json:"NTPServers,allowempty"`
  113. ProtocolEnabled bool `json:"ProtocolEnabled,allowfalse"`
  114. TimeZone string `json:"TimeZone"`
  115. }