From 15395555d82b16c6f351d4c2b65af60cee09e75a Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 25 May 2022 04:55:39 +0800 Subject: [PATCH] feature: daemon server support --- pkg/apis/compute/guests.go | 2 ++ pkg/compute/models/guests.go | 4 ++++ pkg/hostman/guestman/qemu-kvm.go | 8 ++++++-- pkg/mcclient/options/compute/servers.go | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 0d06bd2610..79410ccb71 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -744,6 +744,8 @@ type GuestJsonDesc struct { } `json:"instance_snapshot_info"` EncryptKeyId string `json:"encrypt_key_id,omitempty"` + + IsDaemon bool `json:"is_daemon"` } type ServerChangeDiskStorageInput struct { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 5a0d848f76..351255c0ed 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -163,6 +163,8 @@ type SGuest struct { InstanceType string `width:"64" charset:"utf8" nullable:"true" list:"user" create:"optional"` SshableLastState tristate.TriState `default:"false" list:"user"` + + IsDaemon tristate.TriState `default:"false" list:"user" create:"optional" update:"user"` } // 云主机实例列表 @@ -4248,6 +4250,8 @@ func (self *SGuest) GetJsonDescAtHypervisor(ctx context.Context, host *SHost) *a HostId: host.Id, EncryptKeyId: self.EncryptKeyId, + + IsDaemon: self.IsDaemon.Bool(), } if len(self.BackupHostId) > 0 { diff --git a/pkg/hostman/guestman/qemu-kvm.go b/pkg/hostman/guestman/qemu-kvm.go index ecf00c71c9..6bc59da08e 100644 --- a/pkg/hostman/guestman/qemu-kvm.go +++ b/pkg/hostman/guestman/qemu-kvm.go @@ -299,6 +299,10 @@ func (s *SKVMGuestInstance) IsDirtyShotdown() bool { return s.GetPid() == -2 } +func (s *SKVMGuestInstance) IsDaemon() bool { + return jsonutils.QueryBoolean(s.Desc, "is_daemon", false) +} + func (s *SKVMGuestInstance) DirtyServerRequestStart() { hostId, _ := s.Desc.GetString("host_id") var body = jsonutils.NewDict() @@ -419,8 +423,8 @@ func (s *SKVMGuestInstance) ImportServer(pendingDelete bool) { s.manager.SaveServer(s.Id, s) s.manager.RemoveCandidateServer(s) - if s.IsDirtyShotdown() && !pendingDelete { - log.Infof("Server dirty shotdown %s", s.GetName()) + if (s.IsDirtyShotdown() || s.IsDaemon()) && !pendingDelete { + log.Infof("Server dirty shotdown or a daemon %s", s.GetName()) if jsonutils.QueryBoolean(s.Desc, "is_master", false) || jsonutils.QueryBoolean(s.Desc, "is_slave", false) { go s.DirtyServerRequestStart() diff --git a/pkg/mcclient/options/compute/servers.go b/pkg/mcclient/options/compute/servers.go index 3de0a17a06..2d938cb166 100644 --- a/pkg/mcclient/options/compute/servers.go +++ b/pkg/mcclient/options/compute/servers.go @@ -615,6 +615,8 @@ type ServerUpdateOptions struct { Delete string `help:"Lock server to prevent from deleting" choices:"enable|disable" json:"-"` ShutdownBehavior string `help:"Behavior after VM server shutdown" choices:"stop|terminate"` Machine string `help:"Machine type" choices:"q35|pc"` + + IsDaemon *bool `help:"Daemon server" negative:"no-daemon"` } func (opts *ServerUpdateOptions) Params() (jsonutils.JSONObject, error) {