profiles.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 baremetal
  15. import (
  16. "strings"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. "yunion.io/x/onecloud/pkg/cloudcommon/types"
  19. )
  20. const (
  21. DefaultBaremetalProfileId = "default"
  22. )
  23. type BaremetalProfileListInput struct {
  24. apis.StandaloneAnonResourceListInput
  25. OemName []string `json:"oem_name"`
  26. Model []string `json:"model"`
  27. }
  28. func (input *BaremetalProfileListInput) Normalize() {
  29. for i := range input.OemName {
  30. input.OemName[i] = strings.TrimSpace(input.OemName[i])
  31. }
  32. for i := range input.Model {
  33. input.Model[i] = strings.TrimSpace(input.Model[i])
  34. }
  35. }
  36. type BaremetalProfileCreateInput struct {
  37. apis.StandaloneAnonResourceCreateInput
  38. OemName string `json:"oem_name"`
  39. Model string `json:"model"`
  40. LanChannel uint8 `json:"lan_channel"`
  41. RootId int `json:"root_id"`
  42. RootName string `json:"root_name"`
  43. StrongPass bool `json:"strong_pass"`
  44. }
  45. type BaremetalProfileUpdateInput struct {
  46. apis.StandaloneAnonResourceBaseUpdateInput
  47. LanChannel uint8 `json:"lan_channel"`
  48. RootId *int `json:"root_id"`
  49. RootName string `json:"root_name"`
  50. StrongPass *bool `json:"strong_pass"`
  51. }
  52. type BaremetalProfileDetails struct {
  53. SBaremetalProfile
  54. }
  55. func (detail BaremetalProfileDetails) ToSpec() BaremetalProfileSpec {
  56. channels := make([]uint8, 0)
  57. if detail.LanChannel > 0 {
  58. channels = append(channels, detail.LanChannel)
  59. }
  60. if detail.LanChannel2 > 0 {
  61. channels = append(channels, detail.LanChannel2)
  62. }
  63. if detail.LanChannel3 > 0 {
  64. channels = append(channels, detail.LanChannel3)
  65. }
  66. return BaremetalProfileSpec{
  67. OemName: detail.OemName,
  68. Model: detail.Model,
  69. LanChannels: channels,
  70. RootName: detail.RootName,
  71. RootId: detail.RootId,
  72. StrongPass: detail.StrongPass,
  73. }
  74. }
  75. type BaremetalProfileSpec struct {
  76. OemName string `json:"oem_name"`
  77. Model string `json:"model"`
  78. LanChannels []uint8 `json:"lan_channels"`
  79. RootName string `json:"root_name"`
  80. RootId int `json:"root_id"`
  81. StrongPass bool `json:"strong_pass"`
  82. }
  83. type BaremetalProfileSpecs []BaremetalProfileSpec
  84. func (a BaremetalProfileSpecs) Len() int { return len(a) }
  85. func (a BaremetalProfileSpecs) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  86. func (a BaremetalProfileSpecs) Less(i, j int) bool {
  87. if a[i].OemName != a[j].OemName {
  88. return a[i].OemName < a[j].OemName
  89. }
  90. if a[i].Model != a[j].Model {
  91. return a[i].Model < a[j].Model
  92. }
  93. return false
  94. }
  95. var PredefinedProfiles = []BaremetalProfileSpec{
  96. {
  97. OemName: "",
  98. LanChannels: []uint8{1, 2, 8},
  99. RootName: "root",
  100. RootId: 2,
  101. },
  102. {
  103. OemName: types.OEM_NAME_INSPUR,
  104. LanChannels: []uint8{8, 1},
  105. RootName: "admin",
  106. RootId: 2,
  107. },
  108. {
  109. OemName: types.OEM_NAME_LENOVO,
  110. LanChannels: []uint8{1, 8},
  111. RootName: "root",
  112. RootId: 2,
  113. },
  114. {
  115. OemName: types.OEM_NAME_HP,
  116. LanChannels: []uint8{1, 2},
  117. RootName: "root",
  118. RootId: 1,
  119. },
  120. {
  121. OemName: types.OEM_NAME_HUAWEI,
  122. LanChannels: []uint8{1},
  123. RootName: "root",
  124. RootId: 2,
  125. StrongPass: true,
  126. },
  127. {
  128. OemName: types.OEM_NAME_FOXCONN,
  129. LanChannels: []uint8{1},
  130. RootName: "root",
  131. RootId: 2,
  132. StrongPass: true,
  133. },
  134. {
  135. OemName: types.OEM_NAME_QEMU,
  136. LanChannels: []uint8{8, 1},
  137. RootName: "root",
  138. RootId: 2,
  139. StrongPass: true,
  140. },
  141. {
  142. OemName: types.OEM_NAME_H3C,
  143. LanChannels: []uint8{1},
  144. RootName: "root",
  145. RootId: 2,
  146. StrongPass: true,
  147. },
  148. }