Skip to content

Commit 22db316

Browse files
committed
feat:主机模型CPU架构添加常见类型--story=133845526 [CMDB-v3]主机模型缺少的CPU架构类型
# Conflicts: # src/scene_server/admin_server/imports.go
1 parent 112f64d commit 22db316

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

src/scene_server/admin_server/imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ import (
121121
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202410100930"
122122
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202502101200"
123123
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202603231000"
124+
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202604271012"
124125
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202605111642"
125126
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
"context"
21+
22+
"configcenter/src/common/blog"
23+
"configcenter/src/scene_server/admin_server/upgrader"
24+
"configcenter/src/storage/dal"
25+
)
26+
27+
func init() {
28+
upgrader.RegistUpgrader("y3.14.202604271012", upgrade)
29+
}
30+
31+
func upgrade(ctx context.Context, db dal.RDB, conf *upgrader.Config) (err error) {
32+
blog.Infof("start execute y3.14.202604271012")
33+
34+
err = updateHostBkCPUArchitectureAttr(ctx, db, conf)
35+
if err != nil {
36+
blog.Errorf("update host bk_cpu_architecture attribute failed, error: %v")
37+
return err
38+
}
39+
40+
return nil
41+
}

0 commit comments

Comments
 (0)