Modify the configuration information of OpenStack

This commit is contained in:
qiwang 2024-07-02 16:29:04 +08:00
parent fa9253c254
commit 1120cfcebc
5 changed files with 37 additions and 16 deletions

View File

@ -1,6 +1,7 @@
Name: pcm.openstack.rpc Name: pcm.openstack.rpc
ListenOn: 0.0.0.0:2010 ListenOn: 0.0.0.0:2010
AdapterId: 1706858330967773113 AdapterId: 1706858330967773113
CoreUrl: "http://127.0.0.1:8999"
Timeout: 100000 # 100s设置rpc服务的响应的超时时间若超过10s还未返回则结束请求 Timeout: 100000 # 100s设置rpc服务的响应的超时时间若超过10s还未返回则结束请求
@ -13,8 +14,11 @@ Participant:
TenantName: "host" #租户名 TenantName: "host" #租户名
CoreClientConf: CoreClientConf:
Url: "localhost:8999" #Url: "localhost:8999"
DataSource: "" #DataSource: ""
AdapterId: 1706858330967773113
CoreUrl: "http://127.0.0.1:8999"
openstackConfig: openstackConfig:

View File

@ -41,9 +41,9 @@ type GetServersDetailedByIdReq struct {
} }
type GetServersDetailedByIdResp struct { type GetServersDetailedByIdResp struct {
Code int64 `json:"code"` Code int64 `json:"code"`
Msg string `json:"msg"` Msg string `json:"msg"`
Data string `json:"data"` // Data string `json:"data"`
Server ServerDetailed `json:"server,omitempty"` Server ServerDetailed `json:"server,omitempty"`
} }

View File

@ -11,14 +11,16 @@ const (
) )
type Config struct { type Config struct {
AdapterId int `yaml:"AdapterId"` //AdapterId int `yaml:"AdapterId"`
zrpc.RpcServerConf zrpc.RpcServerConf
OpenstackConfig OpenstackConfig OpenstackConfig OpenstackConfig
CoreClientConf CoreClientConf `yaml:"CoreClientConf"` CoreClientConf CoreClientConf
LogConf logx.LogConf LogConf logx.LogConf
PcmCoreRpcConf zrpc.RpcClientConf PcmCoreRpcConf zrpc.RpcClientConf
ParticipantId int64 AdapterId int64
Participant Participant Participant Participant
CoreUrl string
ParticipantId int64
} }
type Participant struct { type Participant struct {
@ -30,6 +32,8 @@ type Participant struct {
} }
type CoreClientConf struct { type CoreClientConf struct {
Url string `yaml:"Url"` /* Url string `yaml:"Url"`
DataSource string `yaml:"DataSource"` DataSource string `yaml:"DataSource"`*/
AdapterId int64 `json:"AdapterId"`
CoreUrl string `json:"CoreUrl"`
} }

View File

@ -5,7 +5,7 @@ import "gitlink.org.cn/JointCloud/pcm-openstack/internal/svc"
func AddCronGroup(svc *svc.ServiceContext) { func AddCronGroup(svc *svc.ServiceContext) {
// 同步任务信息到core端 // 同步任务信息到core端
svc.Cron.AddFunc("*/5 * * * * ?", func() { svc.Cron.AddFunc("*/5 * * * * ?", func() {
PullTaskInfo() PullTaskInfo(svc)
}) })
} }

View File

@ -9,6 +9,7 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/common" "gitlink.org.cn/JointCloud/pcm-openstack/internal/common"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/config" "gitlink.org.cn/JointCloud/pcm-openstack/internal/config"
"gitlink.org.cn/JointCloud/pcm-openstack/internal/svc"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"log" "log"
"net/http" "net/http"
@ -20,8 +21,11 @@ var AdapterId int64
var CoreUrl string var CoreUrl string
var C config.Config var C config.Config
func PullTaskInfo() { func PullTaskInfo(svc *svc.ServiceContext) {
AdapterId := svc.Config.AdapterId
CoreUrl := svc.Config.CoreUrl
fmt.Println("AdapterId:", AdapterId)
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(1706858330967773113, 10)).
@ -53,8 +57,18 @@ func PullTaskInfo() {
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 state is not "Saved" ,then get state from participant and sync to core } 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
} }
} }
@ -69,7 +83,6 @@ func PullTaskInfo() {
if len(PushReq.VmInfoList) != 0 { if len(PushReq.VmInfoList) != 0 {
url := "http://127.0.0.1:8999" + "/pcm/v1/core/pushTaskInfo" url := "http://127.0.0.1:8999" + "/pcm/v1/core/pushTaskInfo"
method := "POST" method := "POST"
jsonStr, _ := json.Marshal(PushReq) jsonStr, _ := json.Marshal(PushReq)
payload := bytes.NewBuffer(jsonStr) payload := bytes.NewBuffer(jsonStr)
client := &http.Client{} client := &http.Client{}