| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package baremetal
- import (
- "strings"
- "yunion.io/x/onecloud/pkg/apis"
- "yunion.io/x/onecloud/pkg/cloudcommon/types"
- )
- const (
- DefaultBaremetalProfileId = "default"
- )
- type BaremetalProfileListInput struct {
- apis.StandaloneAnonResourceListInput
- OemName []string `json:"oem_name"`
- Model []string `json:"model"`
- }
- func (input *BaremetalProfileListInput) Normalize() {
- for i := range input.OemName {
- input.OemName[i] = strings.TrimSpace(input.OemName[i])
- }
- for i := range input.Model {
- input.Model[i] = strings.TrimSpace(input.Model[i])
- }
- }
- type BaremetalProfileCreateInput struct {
- apis.StandaloneAnonResourceCreateInput
- OemName string `json:"oem_name"`
- Model string `json:"model"`
- LanChannel uint8 `json:"lan_channel"`
- RootId int `json:"root_id"`
- RootName string `json:"root_name"`
- StrongPass bool `json:"strong_pass"`
- }
- type BaremetalProfileUpdateInput struct {
- apis.StandaloneAnonResourceBaseUpdateInput
- LanChannel uint8 `json:"lan_channel"`
- RootId *int `json:"root_id"`
- RootName string `json:"root_name"`
- StrongPass *bool `json:"strong_pass"`
- }
- type BaremetalProfileDetails struct {
- SBaremetalProfile
- }
- func (detail BaremetalProfileDetails) ToSpec() BaremetalProfileSpec {
- channels := make([]uint8, 0)
- if detail.LanChannel > 0 {
- channels = append(channels, detail.LanChannel)
- }
- if detail.LanChannel2 > 0 {
- channels = append(channels, detail.LanChannel2)
- }
- if detail.LanChannel3 > 0 {
- channels = append(channels, detail.LanChannel3)
- }
- return BaremetalProfileSpec{
- OemName: detail.OemName,
- Model: detail.Model,
- LanChannels: channels,
- RootName: detail.RootName,
- RootId: detail.RootId,
- StrongPass: detail.StrongPass,
- }
- }
- type BaremetalProfileSpec struct {
- OemName string `json:"oem_name"`
- Model string `json:"model"`
- LanChannels []uint8 `json:"lan_channels"`
- RootName string `json:"root_name"`
- RootId int `json:"root_id"`
- StrongPass bool `json:"strong_pass"`
- }
- type BaremetalProfileSpecs []BaremetalProfileSpec
- func (a BaremetalProfileSpecs) Len() int { return len(a) }
- func (a BaremetalProfileSpecs) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
- func (a BaremetalProfileSpecs) Less(i, j int) bool {
- if a[i].OemName != a[j].OemName {
- return a[i].OemName < a[j].OemName
- }
- if a[i].Model != a[j].Model {
- return a[i].Model < a[j].Model
- }
- return false
- }
- var PredefinedProfiles = []BaremetalProfileSpec{
- {
- OemName: "",
- LanChannels: []uint8{1, 2, 8},
- RootName: "root",
- RootId: 2,
- },
- {
- OemName: types.OEM_NAME_INSPUR,
- LanChannels: []uint8{8, 1},
- RootName: "admin",
- RootId: 2,
- },
- {
- OemName: types.OEM_NAME_LENOVO,
- LanChannels: []uint8{1, 8},
- RootName: "root",
- RootId: 2,
- },
- {
- OemName: types.OEM_NAME_HP,
- LanChannels: []uint8{1, 2},
- RootName: "root",
- RootId: 1,
- },
- {
- OemName: types.OEM_NAME_HUAWEI,
- LanChannels: []uint8{1},
- RootName: "root",
- RootId: 2,
- StrongPass: true,
- },
- {
- OemName: types.OEM_NAME_FOXCONN,
- LanChannels: []uint8{1},
- RootName: "root",
- RootId: 2,
- StrongPass: true,
- },
- {
- OemName: types.OEM_NAME_QEMU,
- LanChannels: []uint8{8, 1},
- RootName: "root",
- RootId: 2,
- StrongPass: true,
- },
- {
- OemName: types.OEM_NAME_H3C,
- LanChannels: []uint8{1},
- RootName: "root",
- RootId: 2,
- StrongPass: true,
- },
- }
|