节点管理
更新时间:2025-05-30
创建节点
                Plain Text
                
            
            1func CreateInstance() {
2	// 用户的Access Key ID 和 Secret Access Key
3	AK, SK := "", ""
4
5	// 用户指定的endpoint
6	ENDPOINT := ""
7
8	// 初始化一个CCEClient
9	ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT)
10	if err != nil {
11		panic(err)
12	}
13	resp, err := ccev2Client.CreateInstances(&v2.CreateInstancesArgs{
14		ClusterID: "",
15		Instances: []*v2.InstanceSet{
16			{
17				InstanceSpec: types.InstanceSpec{
18					MachineType:  types.MachineTypeBCC,
19					InstanceType: api.InstanceType34,
20					InstanceName: "",
21					VPCConfig: types.VPCConfig{
22						VPCSubnetID: "sbn-xxx",
23						SecurityGroup: types.SecurityGroup{
24							EnableCCERequiredSecurityGroup: true,
25							EnableCCEOptionalSecurityGroup: false,
26						},
27					},
28					InstanceResource: types.InstanceResource{
29						CPU:           2,
30						MEM:           8,
31						RootDiskType:  api.StorageTypeHP1,
32						RootDiskSize:  100,
33						LocalDiskSize: 0,
34						CDSList:       []types.CDSConfig{},
35						MachineSpec:   "bcc.g5.c2m8",
36					},
37					ImageID: "7183d3d0-3e24-464d-9c02-xxxx",
38					InstanceOS: types.InstanceOS{
39						ImageType: api.ImageTypeSystem,
40					},
41					SSHKeyID: "k-xxx",
42					DeployCustomConfig: types.DeployCustomConfig{
43						KubeletRootDir: "/var/lib/kubelet",
44						KubeReserved: map[string]string{
45							"cpu":    "50m",
46							"memory": "100Mi",
47						},
48						SystemReserved: map[string]string{
49							"cpu":    "50m",
50							"memory": "100Mi",
51						},
52						ContainerdConfig: types.ContainerdConfig{
53							DataRoot: "/home/cce/containerd",
54						},
55					},
56					RelationTag:          true,
57					InstanceChargingType: api.PaymentTimingPostPaid,
58					Tags: types.TagList{
59						{
60							TagKey:   "tagkey",
61							TagValue: "tagvalue",
62						},
63					},
64				},
65				Count: 1,
66			},
67		},
68	})
69	if err != nil {
70		fmt.Println(err.Error())
71		return
72	}
73	s, _ := json.MarshalIndent(resp, "", "\t")
74	fmt.Println("Response:" + string(s))
75}创建节点并关联标签
                Plain Text
                
            
            1    resp, err := ccev2Client.CreateInstances(&v2.CreateInstancesArgs{
2		ClusterID: "",
3		Instances: []*v2.InstanceSet{
4			{
5				InstanceSpec: types.InstanceSpec{
6                    // 创建节点所需的其他配置
7                    
8                    // 节点关联的标签
9					Tags: types.TagList{
10						{
11							TagKey:   "tagkey",
12							TagValue: "tagvalue",
13						},
14					},
15				},
16				Count: 1,
17			},
18		},
19	})查询节点
                Plain Text
                
            
            1func GetInstance(){
2	// 用户的Access Key ID和Secret Access Key
3	AK, SK := "", ""
4
5	// 用户指定的endpoint
6	ENDPOINT := ""
7
8	// 初始化一个CCEClient
9	ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT)
10	if err != nil {
11		panic(err)
12	}
13
14	resp, err := ccev2Client.GetInstance(&v2.GetInstanceArgs{
15		ClusterID:  "",
16		InstanceID: "",
17	})
18	if err != nil {
19		fmt.Println(err.Error())
20		return
21	}
22
23	s, _ := json.MarshalIndent(resp, "", "\t")
24	fmt.Println("Response:" + string(s))
25}查询节点标签
                Plain Text
                
            
            1    instance, err := ccev2Client.GetInstance(&v2.GetInstanceArgs{
2		ClusterID:  "",
3		InstanceID: "",
4	})
5	if err != nil {
6		fmt.Println(err.Error())
7		return
8	}
9	
10	tags, _ := json.MarshalIndent(instance.Instance.Spec.Tags, "", "\t")
11	fmt.Println("Response:" + string(tags))