|
| 1 | +/* |
| 2 | + * Tencent is pleased to support the open source community by making |
| 3 | + * 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available. |
| 4 | + * Copyright (C) 2017 Tencent. All rights reserved. |
| 5 | + * Licensed under the MIT License (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at http://opensource.org/licenses/MIT |
| 8 | + * Unless required by applicable law or agreed to in writing, |
| 9 | + * software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 11 | + * either express or implied. See the License for the |
| 12 | + * specific language governing permissions and limitations under the License. |
| 13 | + * We undertake not to change the open source license (MIT license) applicable |
| 14 | + * to the current version of the project delivered to anyone in the future. |
| 15 | + */ |
| 16 | + |
| 17 | +package y3_14_202604271012 |
| 18 | + |
| 19 | +import ( |
| 20 | + "configcenter/src/common" |
| 21 | + "configcenter/src/common/blog" |
| 22 | + "configcenter/src/scene_server/admin_server/upgrader" |
| 23 | + "configcenter/src/storage/dal" |
| 24 | + "context" |
| 25 | + "fmt" |
| 26 | + |
| 27 | + "go.mongodb.org/mongo-driver/bson" |
| 28 | +) |
| 29 | + |
| 30 | +// updateHostBkCPUArchitectureAttr add bk_cpu_architecture attribute for host |
| 31 | +func updateHostBkCPUArchitectureAttr(ctx context.Context, db dal.RDB, conf *upgrader.Config) error { |
| 32 | + attrFilter := map[string]interface{}{ |
| 33 | + common.BKObjIDField: common.BKInnerObjIDHost, |
| 34 | + common.BKPropertyIDField: "bk_cpu_architecture", |
| 35 | + common.BkSupplierAccount: conf.OwnerID, |
| 36 | + } |
| 37 | + |
| 38 | + cnt, err := db.Table(common.BKTableNameObjAttDes).Find(attrFilter).Count(ctx) |
| 39 | + if err != nil { |
| 40 | + blog.Errorf("count bk_cpu_architecture attribute failed, err: %v", err) |
| 41 | + return err |
| 42 | + } |
| 43 | + |
| 44 | + if cnt <= 0 { |
| 45 | + return fmt.Errorf("must have bk_cpu_architecture attribute") |
| 46 | + } |
| 47 | + |
| 48 | + updateData := bson.M{ |
| 49 | + "option": []EnumVal{ |
| 50 | + {ID: "x86", Name: "X86", Type: "text", IsDefault: true}, |
| 51 | + {ID: "x86_64", Name: "X86_64", Type: "text"}, |
| 52 | + {ID: "arm", Name: "ARM", Type: "text"}, |
| 53 | + {ID: "arm64", Name: "ARM64", Type: "text"}, |
| 54 | + {ID: "aarch64", Name: "AARCH64", Type: "text"}, |
| 55 | + {ID: "powerpc", Name: "POWERPC", Type: "text"}, |
| 56 | + {ID: "ppc64", Name: "PPC64", Type: "text"}, |
| 57 | + {ID: "ppc", Name: "PPC", Type: "text"}, |
| 58 | + {ID: "riscv64", Name: "RISCV64", Type: "text"}, |
| 59 | + }, |
| 60 | + } |
| 61 | + m, err := db.Table(common.BKTableNameObjAttDes).UpdateMany(ctx, attrFilter, updateData) |
| 62 | + if err != nil { |
| 63 | + blog.Errorf("update bk_cpu_architecture attribute failed, err: %v", err) |
| 64 | + return err |
| 65 | + } |
| 66 | + blog.Errorf("update bk_cpu_architecture attribute %v", m) |
| 67 | + |
| 68 | + return nil |
| 69 | +} |
| 70 | + |
| 71 | +// EnumVal TODO |
| 72 | +type EnumVal struct { |
| 73 | + ID string `bson:"id" json:"id"` |
| 74 | + Name string `bson:"name" json:"name"` |
| 75 | + Type string `bson:"type" json:"type"` |
| 76 | + IsDefault bool `bson:"is_default" json:"is_default"` |
| 77 | +} |
0 commit comments