finish vm create task
This commit is contained in:
parent
1120cfcebc
commit
0f1f58b6d8
|
@ -28,8 +28,8 @@ func PullTaskInfo(svc *svc.ServiceContext) {
|
||||||
fmt.Println("CoreUrl:", CoreUrl)
|
fmt.Println("CoreUrl:", CoreUrl)
|
||||||
httpClient := resty.New().R()
|
httpClient := resty.New().R()
|
||||||
result, _ := httpClient.SetHeader("Content-Type", "application/json").
|
result, _ := httpClient.SetHeader("Content-Type", "application/json").
|
||||||
SetQueryParam("adapterId", strconv.FormatInt(1706858330967773113, 10)).
|
SetQueryParam("adapterId", strconv.FormatInt(AdapterId, 10)).
|
||||||
Get("http://127.0.0.1:8999" + "/pcm/v1/core/pullTaskInfo")
|
Get(CoreUrl + "/pcm/v1/core/pullTaskInfo")
|
||||||
|
|
||||||
var resp coreClient.PullTaskInfoResp
|
var resp coreClient.PullTaskInfoResp
|
||||||
err := json.Unmarshal(result.Body(), &resp)
|
err := json.Unmarshal(result.Body(), &resp)
|
||||||
|
@ -41,14 +41,15 @@ func PullTaskInfo(svc *svc.ServiceContext) {
|
||||||
var oldVmInfoList []coreClient.VmInfo
|
var oldVmInfoList []coreClient.VmInfo
|
||||||
CreateServerReq := common.CreateSerReq{}
|
CreateServerReq := common.CreateSerReq{}
|
||||||
|
|
||||||
for i, vmInfo := range resp.VmInfoList {
|
for _, vmInfo := range resp.VmInfoList {
|
||||||
if vmInfo.Status == "Saved" {
|
if vmInfo.Status == "Saved" {
|
||||||
CreateServerReq.CrServer.Server.Networks = make([]common.Networks, len(resp.VmInfoList))
|
network := common.Networks{}
|
||||||
CreateServerReq.Platform = vmInfo.Platform
|
CreateServerReq.Platform = vmInfo.Platform
|
||||||
CreateServerReq.CrServer.Server.Name = vmInfo.VmName
|
CreateServerReq.CrServer.Server.Name = vmInfo.VmName
|
||||||
CreateServerReq.CrServer.Server.FlavorRef = vmInfo.FlavorRef
|
CreateServerReq.CrServer.Server.FlavorRef = vmInfo.FlavorRef
|
||||||
CreateServerReq.CrServer.Server.ImageRef = vmInfo.ImageRef
|
CreateServerReq.CrServer.Server.ImageRef = vmInfo.ImageRef
|
||||||
CreateServerReq.CrServer.Server.Networks[i].Uuid = vmInfo.Uuid
|
network.Uuid = vmInfo.Uuid
|
||||||
|
CreateServerReq.CrServer.Server.Networks = append(CreateServerReq.CrServer.Server.Networks, network)
|
||||||
CreateServerReq.CrServer.Server.MinCount = vmInfo.MinCount
|
CreateServerReq.CrServer.Server.MinCount = vmInfo.MinCount
|
||||||
respServer, err := CreateServer(CreateServerReq)
|
respServer, err := CreateServer(CreateServerReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,31 +58,15 @@ func PullTaskInfo(svc *svc.ServiceContext) {
|
||||||
vmInfo.ServerId = respServer.Server.Id
|
vmInfo.ServerId = respServer.Server.Id
|
||||||
oldVmInfoList = append(oldVmInfoList, *vmInfo)
|
oldVmInfoList = append(oldVmInfoList, *vmInfo)
|
||||||
vmInfo.Status = "Running"
|
vmInfo.Status = "Running"
|
||||||
} else if vmInfo.Status == "Running" || vmInfo.Status == "BUILD" { //if state is not "Running" ,then get state from participant and sync to core
|
|
||||||
GetServersDetailedByIdReq := common.GetServersDetailedByIdReq{}
|
|
||||||
GetServersDetailedByIdReq.ServerId = vmInfo.ServerId
|
|
||||||
GetServersDetailedByIdReq.Platform = vmInfo.Platform
|
|
||||||
GetServersDetailedByIdResp, err := GetServerDetail(GetServersDetailedByIdReq)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
vmInfo.Status = GetServersDetailedByIdResp.Server.Status
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// push submitted mark to coordinator
|
// push submitted mark to coordinator
|
||||||
PushReq := coreClient.PushTaskInfoReq{
|
PushReq := coreClient.PushTaskInfoReq{
|
||||||
AdapterId: 1706858330967773113,
|
AdapterId: AdapterId,
|
||||||
VmInfoList: resp.VmInfoList,
|
VmInfoList: resp.VmInfoList,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(PushReq.VmInfoList) != 0 {
|
if len(PushReq.VmInfoList) != 0 {
|
||||||
url := "http://127.0.0.1:8999" + "/pcm/v1/core/pushTaskInfo"
|
url := CoreUrl + "/pcm/v1/core/pushTaskInfo"
|
||||||
method := "POST"
|
method := "POST"
|
||||||
jsonStr, _ := json.Marshal(PushReq)
|
jsonStr, _ := json.Marshal(PushReq)
|
||||||
payload := bytes.NewBuffer(jsonStr)
|
payload := bytes.NewBuffer(jsonStr)
|
||||||
|
@ -94,6 +79,41 @@ func PullTaskInfo(svc *svc.ServiceContext) {
|
||||||
}
|
}
|
||||||
fmt.Print(resp)
|
fmt.Print(resp)
|
||||||
}
|
}
|
||||||
|
} else if vmInfo.Status == "Running" || vmInfo.Status == "BUILD" { //if state is not "Running" ,then get state from participant and sync to core
|
||||||
|
GetServersDetailedByIdReq := common.GetServersDetailedByIdReq{}
|
||||||
|
GetServersDetailedByIdReq.ServerId = vmInfo.ServerId
|
||||||
|
GetServersDetailedByIdReq.Platform = vmInfo.Platform
|
||||||
|
GetServersDetailedByIdResp, err := GetServerDetail(GetServersDetailedByIdReq)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
vmInfo.Status = GetServersDetailedByIdResp.Server.Status
|
||||||
|
|
||||||
|
// push submitted mark to coordinator
|
||||||
|
PushReq := coreClient.PushTaskInfoReq{
|
||||||
|
AdapterId: AdapterId,
|
||||||
|
VmInfoList: resp.VmInfoList,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(PushReq.VmInfoList) != 0 {
|
||||||
|
url := CoreUrl + "/pcm/v1/core/pushTaskInfo"
|
||||||
|
method := "POST"
|
||||||
|
jsonStr, _ := json.Marshal(PushReq)
|
||||||
|
payload := bytes.NewBuffer(jsonStr)
|
||||||
|
client := &http.Client{}
|
||||||
|
req, _ := http.NewRequest(method, url, payload)
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Print(resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue