mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9715 from wanyaoqi/automated-cherry-pick-of-#9711-upstream-release-3.7
Automated cherry pick of #9711: fix(region,host,host-deployer): sync status chekc block jobs
This commit is contained in:
@@ -407,12 +407,14 @@ func init() {
|
||||
})
|
||||
|
||||
type HostAddNetIfOptions struct {
|
||||
ID string `help:"ID or Name of host"`
|
||||
WIRE string `help:"ID or Name of wire to attach"`
|
||||
MAC string `help:"Mac address of NIC"`
|
||||
INDEX int64 `help:"nic index"`
|
||||
Type string `help:"Nic type" choices:"admin|ipmi"`
|
||||
IpAddr string `help:"IP address"`
|
||||
ID string `help:"ID or Name of host"`
|
||||
WIRE string `help:"ID or Name of wire to attach"`
|
||||
MAC string `help:"Mac address of NIC"`
|
||||
INDEX int64 `help:"nic index"`
|
||||
Type string `help:"Nic type" choices:"admin|ipmi"`
|
||||
IpAddr string `help:"IP address"`
|
||||
Bridge string `help:"Bridge of hostwire"`
|
||||
Interface string `help:"Interface name, eg:eth0, en0"`
|
||||
}
|
||||
R(&HostAddNetIfOptions{}, "host-add-netif", "Host add a NIC", func(s *mcclient.ClientSession, args *HostAddNetIfOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
@@ -426,6 +428,12 @@ func init() {
|
||||
if len(args.IpAddr) > 0 {
|
||||
params.Add(jsonutils.NewString(args.IpAddr), "ip_addr")
|
||||
}
|
||||
if len(args.Bridge) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Bridge), "bridge")
|
||||
}
|
||||
if len(args.Interface) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Interface), "interface")
|
||||
}
|
||||
result, err := modules.Hosts.PerformAction(s, args.ID, "add-netif", params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -205,6 +205,8 @@ type PerformStatusInput struct {
|
||||
// 更改的目标状态值
|
||||
// required:true
|
||||
Status string `json:"status"`
|
||||
// swagger:ignore
|
||||
BlockJobsCount int `json:"block_jobs_count"`
|
||||
|
||||
// 更改状态的原因描述
|
||||
// required:false
|
||||
|
||||
@@ -2723,7 +2723,7 @@ func (self *SGuest) PerformStatus(ctx context.Context, userCred mcclient.TokenCr
|
||||
}
|
||||
|
||||
status := input.Status
|
||||
if len(self.BackupHostId) > 0 && status == api.VM_RUNNING {
|
||||
if len(self.BackupHostId) > 0 && status == api.VM_RUNNING && input.BlockJobsCount > 0 {
|
||||
self.SetMetadata(ctx, api.MIRROR_JOB, api.MIRROR_JOB_READY, userCred)
|
||||
} else if ispId := self.GetMetadata(api.BASE_INSTANCE_SNAPSHOT_ID, userCred); len(ispId) > 0 {
|
||||
ispM, err := InstanceSnapshotManager.FetchById(ispId)
|
||||
|
||||
@@ -4782,7 +4782,7 @@ func (self *SGuestManager) switchBackupGuests(ctx context.Context, userCred mccl
|
||||
log.Errorf("ReconcileBackupGuests failed fetch guests %s", err)
|
||||
return
|
||||
}
|
||||
log.Infof("Guests count %d need reconcile with switch bakcup", len(guests))
|
||||
log.Debugf("Guests count %d need reconcile with switch backup", len(guests))
|
||||
for i := 0; i < len(guests); i++ {
|
||||
val := guests[i].GetMetadataJson("switch_backup", userCred)
|
||||
t, err := val.GetTime()
|
||||
|
||||
@@ -68,8 +68,13 @@ func (self *GuestSyncstatusTask) OnGetStatusSucc(ctx context.Context, guest *mod
|
||||
default:
|
||||
statusStr = api.VM_UNKNOWN
|
||||
}
|
||||
blockJobsCount, err := body.Int("block_jobs_count")
|
||||
if err != nil {
|
||||
blockJobsCount = -1
|
||||
}
|
||||
input := apis.PerformStatusInput{
|
||||
Status: statusStr,
|
||||
Status: statusStr,
|
||||
BlockJobsCount: int(blockJobsCount),
|
||||
}
|
||||
guest.PerformStatus(ctx, self.UserCred, nil, input)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -109,8 +109,12 @@ func guestActions(f actionFunc) appsrv.FilterHandler {
|
||||
|
||||
func getStatus(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
params, _, _ := appsrv.FetchEnv(ctx, w, r)
|
||||
var status = guestman.GetGuestManager().Status(params["<sid>"])
|
||||
appsrv.SendStruct(w, strDict{"status": status})
|
||||
var status, blockJobsCount = guestman.GetGuestManager().StatusWithBlockJobsCount(params["<sid>"])
|
||||
res := map[string]interface{}{
|
||||
"status": status,
|
||||
"block_jobs_count": blockJobsCount,
|
||||
}
|
||||
appsrv.SendStruct(w, res)
|
||||
}
|
||||
|
||||
func cpusetBalance(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -627,6 +627,19 @@ func (m *SGuestManager) Status(sid string) string {
|
||||
return status
|
||||
}
|
||||
|
||||
func (m *SGuestManager) StatusWithBlockJobsCount(sid string) (string, int) {
|
||||
status := m.GetStatus(sid)
|
||||
blockJobsCount := 0
|
||||
if status == GUEST_RUNNING {
|
||||
guest, _ := m.GetServer(sid)
|
||||
if guest.Monitor == nil && !guest.IsStopping() {
|
||||
guest.StartMonitor(context.Background())
|
||||
}
|
||||
blockJobsCount = guest.BlockJobsCount()
|
||||
}
|
||||
return status, blockJobsCount
|
||||
}
|
||||
|
||||
func (m *SGuestManager) GetStatus(sid string) string {
|
||||
if guest, ok := m.GetServer(sid); ok {
|
||||
if guest.IsRunning() && guest.Monitor != nil && guest.IsMaster() {
|
||||
|
||||
@@ -178,6 +178,7 @@ func FileGetContents(file string) (string, error) {
|
||||
func GetFsFormat(diskPath string) string {
|
||||
ret, err := procutils.NewCommand("blkid", "-o", "value", "-s", "TYPE", diskPath).Output()
|
||||
if err != nil {
|
||||
log.Errorf("failed exec blkid of dev %s: %s, %s", diskPath, err, ret)
|
||||
return ""
|
||||
}
|
||||
var res string
|
||||
|
||||
Reference in New Issue
Block a user