diff --git a/cmd/climc/shell/compute/hosts.go b/cmd/climc/shell/compute/hosts.go index c44399277f..6e47ebf39f 100644 --- a/cmd/climc/shell/compute/hosts.go +++ b/cmd/climc/shell/compute/hosts.go @@ -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 diff --git a/pkg/apis/input.go b/pkg/apis/input.go index 15ecaebbe7..3004dbee15 100644 --- a/pkg/apis/input.go +++ b/pkg/apis/input.go @@ -205,6 +205,8 @@ type PerformStatusInput struct { // 更改的目标状态值 // required:true Status string `json:"status"` + // swagger:ignore + BlockJobsCount int `json:"block_jobs_count"` // 更改状态的原因描述 // required:false diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 292b029f1d..accf2d0c6b 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -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) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 69161d1e28..50840f760d 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -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() diff --git a/pkg/compute/tasks/guest_syncstatus_task.go b/pkg/compute/tasks/guest_syncstatus_task.go index 33b2663e96..ac36923d4e 100644 --- a/pkg/compute/tasks/guest_syncstatus_task.go +++ b/pkg/compute/tasks/guest_syncstatus_task.go @@ -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) diff --git a/pkg/hostman/guestman/guesthandlers/guesthandler.go b/pkg/hostman/guestman/guesthandlers/guesthandler.go index dea39bbebc..b8bb50e238 100644 --- a/pkg/hostman/guestman/guesthandlers/guesthandler.go +++ b/pkg/hostman/guestman/guesthandlers/guesthandler.go @@ -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[""]) - appsrv.SendStruct(w, strDict{"status": status}) + var status, blockJobsCount = guestman.GetGuestManager().StatusWithBlockJobsCount(params[""]) + 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) { diff --git a/pkg/hostman/guestman/guestman.go b/pkg/hostman/guestman/guestman.go index e23f2b10ff..07842949dc 100644 --- a/pkg/hostman/guestman/guestman.go +++ b/pkg/hostman/guestman/guestman.go @@ -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() { diff --git a/pkg/util/fileutils2/fileutils.go b/pkg/util/fileutils2/fileutils.go index c2069128cb..e2078ea847 100644 --- a/pkg/util/fileutils2/fileutils.go +++ b/pkg/util/fileutils2/fileutils.go @@ -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