Add tencent create

Signed-off-by: zhouqunjie <450705171@qq.com>
This commit is contained in:
zhouqunjie 2022-04-05 16:20:05 +08:00
parent 580e731a36
commit c39c043eec
6 changed files with 135 additions and 94 deletions

View File

@ -5,6 +5,7 @@ import (
"gitlink.org.cn/JCCE/PCM/common/tenanter" "gitlink.org.cn/JCCE/PCM/common/tenanter"
"gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbpod" "gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbpod"
"gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbtenant" "gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbtenant"
"strconv"
"sync" "sync"
alieci "github.com/aliyun/alibaba-cloud-sdk-go/services/eci" alieci "github.com/aliyun/alibaba-cloud-sdk-go/services/eci"
@ -27,7 +28,6 @@ func newAliEciClient(region tenanter.Region, tenant tenanter.Tenanter) (Poder, e
switch t := tenant.(type) { switch t := tenant.(type) {
case *tenanter.AccessKeyTenant: case *tenanter.AccessKeyTenant:
// 阿里云的sdk有一个 map 的并发问题go test 加上-race 能检测出来,所以这里加一个锁
aliClientMutex.Lock() aliClientMutex.Lock()
client, err = alieci.NewClientWithAccessKey(region.GetName(), t.GetId(), t.GetSecret()) client, err = alieci.NewClientWithAccessKey(region.GetName(), t.GetId(), t.GetSecret())
aliClientMutex.Unlock() aliClientMutex.Unlock()
@ -90,8 +90,8 @@ func (eci *AliEci) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailRe
RegionId: 0, RegionId: 0,
ContainerImage: v.Containers[k].Image, ContainerImage: v.Containers[k].Image,
ContainerName: v.Containers[k].Name, ContainerName: v.Containers[k].Name,
CpuPod: v.Cpu, CpuPod: strconv.FormatFloat(float64(v.Cpu), 'f', 6, 64),
MemoryPod: v.Memory, MemoryPod: strconv.FormatFloat(float64(v.Memory), 'f', 6, 64),
SecurityGroupId: v.SecurityGroupId, SecurityGroupId: v.SecurityGroupId,
SubnetId: v.InternetIp, SubnetId: v.InternetIp,
VpcId: v.VpcId, VpcId: v.VpcId,

View File

@ -33,7 +33,7 @@ func NewPodClient(provider pbtenant.CloudProvider, region tenanter.Region, tenan
case pbtenant.CloudProvider_ali: case pbtenant.CloudProvider_ali:
return newAliEciClient(region, tenant) return newAliEciClient(region, tenant)
case pbtenant.CloudProvider_tencent: case pbtenant.CloudProvider_tencent:
return nil, nil return newTencentEksClient(region, tenant)
case pbtenant.CloudProvider_huawei: case pbtenant.CloudProvider_huawei:
return nil, nil return nil, nil
//TODO aws //TODO aws

View File

@ -1,67 +1,112 @@
package poder package poder
// import (
//import ( "context"
// "fmt" "github.com/pkg/errors"
// "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
// "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
// "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" tencenteks "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
// tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525" "gitlink.org.cn/JCCE/PCM/common/tenanter"
// "gitlink.org.cn/JCCE/PCM/adaptor/pod_adaptor/common/auth/aksk" "gitlink.org.cn/JCCE/PCM/lan_trans/idl/pbpod"
// pcmCommon "gitlink.org.cn/JCCE/PCM/adaptor/pod_adaptor/common/config" "strconv"
//) "sync"
// )
//func CreateEksInstance(cloudStack string, akskPath string, configPath string) {
// var tencentClientMutex sync.Mutex
// configCommon, _ := pcmCommon.PCMconfig(configPath)
// configAksk, _ := aksk.AkskConfig(cloudStack, akskPath) type TencentEks struct {
// cli *tencenteks.Client
// credential := common.NewCredential( region tenanter.Region
// configAksk.AccessKey, tenanter tenanter.Tenanter
// configAksk.SecretKey, }
// )
// cpf := profile.NewClientProfile() func newTencentEksClient(region tenanter.Region, tenant tenanter.Tenanter) (Poder, error) {
// cpf.HttpProfile.Endpoint = "tke.tencentcloudapi.com" var (
// client, _ := tke.NewClient(credential, configCommon.RegionId, cpf) client *tencenteks.Client
// err error
// request := tke.NewCreateEKSContainerInstancesRequest() )
//
// eksCiName := &configCommon.ContainerGroupName switch t := tenant.(type) {
// containerName := &configCommon.ContainerName case *tenanter.AccessKeyTenant:
// containerImage := &configCommon.ContainerImage tencentClientMutex.Lock()
// eksCpu := &configCommon.CpuPodFloat
// eksMemory := &configCommon.MemoryPodFloat credential := common.NewCredential(
// securityGroupId := &configCommon.SecurityGroupId t.GetId(),
// securityGroupIds := make([]*string, 1) t.GetSecret(),
// securityGroupIds[0] = securityGroupId )
// subNetId := &configCommon.SubnetId cpf := profile.NewClientProfile()
// vpcId := &configCommon.VpcId client, err = tencenteks.NewClient(credential, region.GetName(), cpf)
// tencentClientMutex.Unlock()
// request.EksCiName = eksCiName default:
// container := make([]*tke.Container, 1) }
// container[0] = new(tke.Container)
// container[0].Name = containerName if err != nil {
// container[0].Image = containerImage return nil, errors.Wrap(err, "init ali ecs client error")
// //container[0].Cpu = containerCpuPt }
// //container[0].Memory = containerMemoryPt
// return &TencentEks{
// request.Containers = container cli: client,
// request.Cpu = eksCpu region: region,
// request.Memory = eksMemory tenanter: tenant,
// request.SecurityGroupIds = securityGroupIds }, nil
// request.SubnetId = subNetId }
// request.VpcId = vpcId
// func (eks TencentEks) CreatePod(ctx context.Context, req *pbpod.CreatePodReq) (*pbpod.CreatePodResp, error) {
// response, err := client.CreateEKSContainerInstances(request)
// if _, ok := err.(*errors.TencentCloudSDKError); ok { request := tencenteks.NewCreateEKSContainerInstancesRequest()
// fmt.Printf("An API error has returned: %s", err)
// return eksCiName := req.PodName
// } containerName := req.ContainerName
// if err != nil { containerImage := req.ContainerImage
// panic(err) eksCpu := req.CpuPod
// } eksMemory := req.MemoryPod
// fmt.Printf("%s", response.ToJsonString()) securityGroupId := req.SecurityGroupId
//} securityGroupIds := make([]*string, 1)
securityGroupIds[0] = &securityGroupId
subNetId := req.SubnetId
vpcId := req.VpcId
request.EksCiName = &eksCiName
container := make([]*tencenteks.Container, 1)
container[0] = new(tencenteks.Container)
container[0].Name = &containerName
container[0].Image = &containerImage
//container[0].Cpu = containerCpuPt
//container[0].Memory = containerMemoryPt
request.Containers = container
eksCpu64, err := strconv.ParseFloat(eksCpu, 64)
eksMemory64, err := strconv.ParseFloat(eksMemory, 64)
request.Cpu = &eksCpu64
request.Memory = &eksMemory64
request.SecurityGroupIds = securityGroupIds
request.SubnetId = &subNetId
request.VpcId = &vpcId
resp, err := eks.cli.CreateEKSContainerInstances(request)
if err != nil {
return nil, errors.Wrap(err, "Tencent CreatePod error")
}
isFinished := false
if resp.Response.RequestId != nil {
isFinished = true
}
return &pbpod.CreatePodResp{
Pods: nil,
Finished: isFinished,
RequestId: *resp.Response.RequestId,
}, nil
}
func (eks TencentEks) ListPodDetail(ctx context.Context, req *pbpod.ListPodDetailReq) (resp *pbpod.ListPodDetailResp, err error) {
//TODO implement me
panic("implement me")
}
// //
//func ListEksInstance(cloudStack string, akskPath string, configPath string) { //func ListEksInstance(cloudStack string, akskPath string, configPath string) {
// //

View File

@ -22,9 +22,9 @@ message PodInstance {
// //
string container_name = 7; string container_name = 7;
// vcpu数 // vcpu数
float cpu_pod = 8; string cpu_pod = 8;
// MB // MB
float memory_pod = 9; string memory_pod = 9;
//ID SecurityGroupIds() //ID SecurityGroupIds()
string security_group_id = 10; string security_group_id = 10;
@ -54,9 +54,9 @@ message CreatePodReq {
// //
string container_name = 7; string container_name = 7;
// v cpu数 // v cpu数
float cpu_pod = 8; string cpu_pod = 8;
// MB // MB
float memory_pod = 9; string memory_pod = 9;
//ID SecurityGroupIds() //ID SecurityGroupIds()
string security_group_id = 10; string security_group_id = 10;
//ID SubnetId() //ID SubnetId()

View File

@ -42,9 +42,9 @@ type PodInstance struct {
// 容器名称 // 容器名称
ContainerName string `protobuf:"bytes,7,opt,name=container_name,json=containerName,proto3" json:"container_name,omitempty"` ContainerName string `protobuf:"bytes,7,opt,name=container_name,json=containerName,proto3" json:"container_name,omitempty"`
// vcpu数 // vcpu数
CpuPod float32 `protobuf:"fixed32,8,opt,name=cpu_pod,json=cpuPod,proto3" json:"cpu_pod,omitempty"` CpuPod string `protobuf:"bytes,8,opt,name=cpu_pod,json=cpuPod,proto3" json:"cpu_pod,omitempty"`
// 内存MB // 内存MB
MemoryPod float32 `protobuf:"fixed32,9,opt,name=memory_pod,json=memoryPod,proto3" json:"memory_pod,omitempty"` MemoryPod string `protobuf:"bytes,9,opt,name=memory_pod,json=memoryPod,proto3" json:"memory_pod,omitempty"`
//安全组ID 对应腾讯 SecurityGroupIds(腾讯必需) //安全组ID 对应腾讯 SecurityGroupIds(腾讯必需)
SecurityGroupId string `protobuf:"bytes,10,opt,name=security_group_id,json=securityGroupId,proto3" json:"security_group_id,omitempty"` SecurityGroupId string `protobuf:"bytes,10,opt,name=security_group_id,json=securityGroupId,proto3" json:"security_group_id,omitempty"`
//子网ID 对应腾讯 SubnetId(腾讯必需) //子网ID 对应腾讯 SubnetId(腾讯必需)
@ -136,18 +136,18 @@ func (x *PodInstance) GetContainerName() string {
return "" return ""
} }
func (x *PodInstance) GetCpuPod() float32 { func (x *PodInstance) GetCpuPod() string {
if x != nil { if x != nil {
return x.CpuPod return x.CpuPod
} }
return 0 return ""
} }
func (x *PodInstance) GetMemoryPod() float32 { func (x *PodInstance) GetMemoryPod() string {
if x != nil { if x != nil {
return x.MemoryPod return x.MemoryPod
} }
return 0 return ""
} }
func (x *PodInstance) GetSecurityGroupId() string { func (x *PodInstance) GetSecurityGroupId() string {
@ -198,9 +198,9 @@ type CreatePodReq struct {
// 容器名称 // 容器名称
ContainerName string `protobuf:"bytes,7,opt,name=container_name,json=containerName,proto3" json:"container_name,omitempty"` ContainerName string `protobuf:"bytes,7,opt,name=container_name,json=containerName,proto3" json:"container_name,omitempty"`
// v cpu数 // v cpu数
CpuPod float32 `protobuf:"fixed32,8,opt,name=cpu_pod,json=cpuPod,proto3" json:"cpu_pod,omitempty"` CpuPod string `protobuf:"bytes,8,opt,name=cpu_pod,json=cpuPod,proto3" json:"cpu_pod,omitempty"`
// 内存MB // 内存MB
MemoryPod float32 `protobuf:"fixed32,9,opt,name=memory_pod,json=memoryPod,proto3" json:"memory_pod,omitempty"` MemoryPod string `protobuf:"bytes,9,opt,name=memory_pod,json=memoryPod,proto3" json:"memory_pod,omitempty"`
//安全组ID 对应腾讯 SecurityGroupIds(腾讯必需) //安全组ID 对应腾讯 SecurityGroupIds(腾讯必需)
SecurityGroupId string `protobuf:"bytes,10,opt,name=security_group_id,json=securityGroupId,proto3" json:"security_group_id,omitempty"` SecurityGroupId string `protobuf:"bytes,10,opt,name=security_group_id,json=securityGroupId,proto3" json:"security_group_id,omitempty"`
//子网ID 对应腾讯 SubnetId(腾讯必需) //子网ID 对应腾讯 SubnetId(腾讯必需)
@ -292,18 +292,18 @@ func (x *CreatePodReq) GetContainerName() string {
return "" return ""
} }
func (x *CreatePodReq) GetCpuPod() float32 { func (x *CreatePodReq) GetCpuPod() string {
if x != nil { if x != nil {
return x.CpuPod return x.CpuPod
} }
return 0 return ""
} }
func (x *CreatePodReq) GetMemoryPod() float32 { func (x *CreatePodReq) GetMemoryPod() string {
if x != nil { if x != nil {
return x.MemoryPod return x.MemoryPod
} }
return 0 return ""
} }
func (x *CreatePodReq) GetSecurityGroupId() string { func (x *CreatePodReq) GetSecurityGroupId() string {
@ -754,9 +754,9 @@ var file_idl_pbpod_pod_proto_rawDesc = []byte{
0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63,
0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07,
0x63, 0x70, 0x75, 0x5f, 0x70, 0x6f, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x63, 0x63, 0x70, 0x75, 0x5f, 0x70, 0x6f, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63,
0x70, 0x75, 0x50, 0x6f, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 0x70, 0x75, 0x50, 0x6f, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f,
0x70, 0x6f, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x02, 0x52, 0x09, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x70, 0x6f, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x65, 0x6d, 0x6f, 0x72,
0x79, 0x50, 0x6f, 0x64, 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x79, 0x50, 0x6f, 0x64, 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79,
0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0f, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x0f, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64,
@ -782,9 +782,9 @@ var file_idl_pbpod_pod_proto_rawDesc = []byte{
0x61, 0x67, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x61, 0x67, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x6f, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x6f, 0x6e,
0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x63, 0x70, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x63, 0x70,
0x75, 0x5f, 0x70, 0x6f, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x63, 0x70, 0x75, 0x75, 0x5f, 0x70, 0x6f, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x70, 0x75,
0x50, 0x6f, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 0x70, 0x6f, 0x50, 0x6f, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 0x70, 0x6f,
0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x02, 0x52, 0x09, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x50, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x50,
0x6f, 0x64, 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x5f, 0x67, 0x6f, 0x64, 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x5f, 0x67,
0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x73, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x73,
0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x12, 0x1b, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x12, 0x1b,

View File

@ -183,13 +183,11 @@
"title": "容器名称" "title": "容器名称"
}, },
"cpuPod": { "cpuPod": {
"type": "number", "type": "string",
"format": "float",
"title": "v cpu数" "title": "v cpu数"
}, },
"memoryPod": { "memoryPod": {
"type": "number", "type": "string",
"format": "float",
"title": "内存MB" "title": "内存MB"
}, },
"securityGroupId": { "securityGroupId": {
@ -358,13 +356,11 @@
"title": "容器名称" "title": "容器名称"
}, },
"cpuPod": { "cpuPod": {
"type": "number", "type": "string",
"format": "float",
"title": "vcpu数" "title": "vcpu数"
}, },
"memoryPod": { "memoryPod": {
"type": "number", "type": "string",
"format": "float",
"title": "内存MB" "title": "内存MB"
}, },
"securityGroupId": { "securityGroupId": {