Merge pull request 'create vm task' (#175) from master-wq into master

Former-commit-id: 495d29591d470a244a2eaa4c8e47b2dc575c0137
This commit is contained in:
qiwang 2024-05-15 15:52:03 +08:00
commit a2342261f5
3 changed files with 22 additions and 29 deletions

View File

@ -228,15 +228,14 @@ type (
VmName string `json:"vm_name,optional"` VmName string `json:"vm_name,optional"`
// Replicas int64 `json:"replicas,optional"` // Replicas int64 `json:"replicas,optional"`
// MatchLabels map[string]string `json:"matchLabels,optional"` // MatchLabels map[string]string `json:"matchLabels,optional"`
// ClusterType string `json:"clusterType,optional"` // ClusterType string `json:"clusterType,optional"`
// //Virtual Machine Section // //Virtual Machine Section
//CreateMulServer []CreateMulDomainServer `json:"createMulServer,optional"` //CreateMulServer []CreateMulDomainServer `json:"createMulServer,optional"`
//VmOption *VmOption `json:"vmOption,optional"` //VmOption *VmOption `json:"vmOption,optional"`
} }
TaskVm { TaskVm {
ImageRef string `json:"imageRef"` Image string `json:"image"`
FlavorRef string `json:"flavorRef"` Flavor string `json:"flavor"`
Uuid string `json:"uuid"` Uuid string `json:"uuid"`
Platform string `json:"platform"` Platform string `json:"platform"`
} }

View File

@ -35,6 +35,8 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type
// todo: add your logic here and delete this line // todo: add your logic here and delete this line
resp = &types.CommitVmTaskResp{} resp = &types.CommitVmTaskResp{}
tx := l.svcCtx.DbEngin.Begin() tx := l.svcCtx.DbEngin.Begin()
var adaptersName string
var clusterName string
//Building the main task structure //Building the main task structure
defer func() { defer func() {
if p := recover(); p != nil { if p := recover(); p != nil {
@ -99,7 +101,7 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type
for _, clusterId := range req.ClusterIds { for _, clusterId := range req.ClusterIds {
if r.Replica > 0 && r.ClusterId == clusterId { if r.Replica > 0 && r.ClusterId == clusterId {
fmt.Println("", clusterId) fmt.Println("", clusterId)
sql := `SELECT vi.image_id as imageRef,vf.flavor_id as flavorRef,vn.network_id as uuid,vi.cluster_name as platform FROM sql := `SELECT vi.image_id as image,vf.flavor_id as flavor,vn.network_id as uuid,vi.cluster_name as platform FROM
vm_flavor vf vm_flavor vf
LEFT JOIN vm_image vi ON vf.cluster_id = vi.cluster_id LEFT JOIN vm_image vi ON vf.cluster_id = vi.cluster_id
LEFT JOIN vm_network vn ON vf.cluster_id = vn.cluster_id LEFT JOIN vm_network vn ON vf.cluster_id = vn.cluster_id
@ -122,28 +124,20 @@ func (l *CommitVmTaskLogic) CommitVmTask(req *types.CommitVmTaskReq) (resp *type
taskVm.Status = "Saved" taskVm.Status = "Saved"
taskVm.StartTime = time.Now().String() taskVm.StartTime = time.Now().String()
taskVm.MinCount = req.MinCount taskVm.MinCount = req.MinCount
/* sqlImage := "SELECT image_id FROM `vm_image_dict` vm left join vm_image vi on vm.id=vi.public_image_id where cluster_id =? AND public_image_id = ?" taskVm.ImageRef = VmObject.Image
txImage := l.svcCtx.DbEngin.Raw(sqlImage, clusterId, req.ImageRef).Scan(&ImageRef) taskVm.FlavorRef = VmObject.Flavor
if txImage.Error != nil {
logx.Error(err)
return nil, txImage.Error
}*/
taskVm.ImageRef = VmObject.ImageRef
/* sqlFlavor := "SELECT * FROM `vm_flavor_dict` vm left join vm_flavor vf on vm.id=vf.public_flavor_id where cluster_id =? AND public_flavor_id = ?"
txFlavor := l.svcCtx.DbEngin.Raw(sqlFlavor, clusterId, req.FlavorRef).Scan(&FlavorRef)
if txFlavor.Error != nil {
logx.Error(err)
return nil, txFlavor.Error
}*/
taskVm.FlavorRef = VmObject.FlavorRef
/* sqlNetwork := "SELECT * FROM `vm_network_dict` vm left join vm_network vi on vm.id=vi.public_network_id where cluster_id =? AND public_network_id = ?"
txNetwork := l.svcCtx.DbEngin.Raw(sqlNetwork, clusterId, req.Uuid).Scan(&NetworkRef)
if txNetwork.Error != nil {
logx.Error(err)
return nil, txNetwork.Error
}*/
taskVm.Uuid = VmObject.Uuid taskVm.Uuid = VmObject.Uuid
taskVm.Platform = VmObject.Platform taskVm.Platform = VmObject.Platform
taskVm.AdapterId = int64(adapterId)
l.svcCtx.DbEngin.Raw("select name from t_adapter where id= ?", int64(adapterId)).Scan(&adaptersName)
taskVm.AdapterName = adaptersName
l.svcCtx.DbEngin.Raw("select name from t_cluster where id= ?", r.ClusterId).Scan(&clusterName)
taskVm.ClusterName = clusterName
taskVm.ClusterId, err = strconv.ParseInt(clusterId, 10, 64)
if err != nil {
fmt.Println("Error converting string to int64:", err)
return
}
tx = l.svcCtx.DbEngin.Create(&taskVm) tx = l.svcCtx.DbEngin.Create(&taskVm)
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, tx.Error

View File

@ -206,10 +206,10 @@ type CommitVmTaskReq struct {
} }
type TaskVm struct { type TaskVm struct {
ImageRef string `json:"imageRef"` Image string `json:"image"`
FlavorRef string `json:"flavorRef"` Flavor string `json:"flavor"`
Uuid string `json:"uuid"` Uuid string `json:"uuid"`
Platform string `json:"platform"` Platform string `json:"platform"`
} }
type VmOption struct { type VmOption struct {
@ -1164,7 +1164,7 @@ type CommitHpcTaskReq struct {
Description string `json:"description,optional"` Description string `json:"description,optional"`
TenantId int64 `json:"tenantId,optional"` TenantId int64 `json:"tenantId,optional"`
TaskId int64 `json:"taskId,optional"` TaskId int64 `json:"taskId,optional"`
AdapterIds []string `json:"adapterIds"` AdapterIds []string `json:"adapterId"`
MatchLabels map[string]string `json:"matchLabels,optional"` MatchLabels map[string]string `json:"matchLabels,optional"`
CardCount int64 `json:"cardCount,optional"` CardCount int64 `json:"cardCount,optional"`
WorkDir string `json:"workDir,optional"` //paratera:workingDir WorkDir string `json:"workDir,optional"` //paratera:workingDir