节点管理
更新时间:2024-06-27
创建节点
func CreateInstance() {
// 用户的Access Key ID和Secret Access Key
AK, SK := "", ""
// 用户指定的endpoint
ENDPOINT := ""
// 初始化一个CCEClient
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT)
if err != nil {
panic(err)
}
resp, err := ccev2Client.CreateInstances(&v2.CreateInstancesArgs{
ClusterID: "",
Instances: []*v2.InstanceSet{
{
InstanceSpec: types.InstanceSpec{
MachineType: types.MachineTypeBCC,
InstanceType: api.InstanceType34,
InstanceName: "",
VPCConfig: types.VPCConfig{
VPCSubnetID: "sbn-xxx",
SecurityGroup: types.SecurityGroup{
EnableCCERequiredSecurityGroup: true,
EnableCCEOptionalSecurityGroup: false,
},
},
InstanceResource: types.InstanceResource{
CPU: 2,
MEM: 8,
RootDiskType: api.StorageTypeHP1,
RootDiskSize: 100,
LocalDiskSize: 0,
CDSList: []types.CDSConfig{},
MachineSpec: "bcc.g5.c2m8",
},
ImageID: "7183d3d0-3e24-464d-9c02-xxxx",
InstanceOS: types.InstanceOS{
ImageType: api.ImageTypeSystem,
},
SSHKeyID: "k-xxx",
DeployCustomConfig: types.DeployCustomConfig{
KubeletRootDir: "/var/lib/kubelet",
KubeReserved: map[string]string{
"cpu": "50m",
"memory": "100Mi",
},
SystemReserved: map[string]string{
"cpu": "50m",
"memory": "100Mi",
},
ContainerdConfig: types.ContainerdConfig{
DataRoot: "/home/cce/containerd",
},
},
RelationTag: true,
InstanceChargingType: api.PaymentTimingPostPaid,
Tags: types.TagList{
{
TagKey: "tagkey",
TagValue: "tagvalue",
},
},
},
Count: 1,
},
},
})
if err != nil {
fmt.Println(err.Error())
return
}
s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))
}
创建节点并关联标签
resp, err := ccev2Client.CreateInstances(&v2.CreateInstancesArgs{
ClusterID: "",
Instances: []*v2.InstanceSet{
{
InstanceSpec: types.InstanceSpec{
// 创建节点所需的其他配置
// 节点关联的标签
Tags: types.TagList{
{
TagKey: "tagkey",
TagValue: "tagvalue",
},
},
},
Count: 1,
},
},
})
查询节点
func GetInstance(){
// 用户的Access Key ID和Secret Access Key
AK, SK := "", ""
// 用户指定的endpoint
ENDPOINT := ""
// 初始化一个CCEClient
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT)
if err != nil {
panic(err)
}
resp, err := ccev2Client.GetInstance(&v2.GetInstanceArgs{
ClusterID: "",
InstanceID: "",
})
if err != nil {
fmt.Println(err.Error())
return
}
s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))
}
查询节点标签
instance, err := ccev2Client.GetInstance(&v2.GetInstanceArgs{
ClusterID: "",
InstanceID: "",
})
if err != nil {
fmt.Println(err.Error())
return
}
tags, _ := json.MarshalIndent(instance.Instance.Spec.Tags, "", "\t")
fmt.Println("Response:" + string(tags))