From d82fb4a773f7c3a7d1ad8e049fc114ea9f7f57c6 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 4 Dec 2018 18:32:08 +0800 Subject: [PATCH] - region: fix host enable not clean sched cache - network dhcp and gateway searchable --- pkg/cloudcommon/db/enabledstatusstandalone.go | 4 ++ pkg/compute/models/hosts.go | 45 ++++++++++++++----- pkg/compute/models/networks.go | 4 +- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/pkg/cloudcommon/db/enabledstatusstandalone.go b/pkg/cloudcommon/db/enabledstatusstandalone.go index 6a456a429b..faffc888c0 100644 --- a/pkg/cloudcommon/db/enabledstatusstandalone.go +++ b/pkg/cloudcommon/db/enabledstatusstandalone.go @@ -5,7 +5,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/util/logclient" ) type SEnabledStatusStandaloneResourceBase struct { @@ -37,6 +39,7 @@ func (self *SEnabledStatusStandaloneResourceBase) PerformEnable(ctx context.Cont return nil, err } OpsLog.LogEvent(self, ACT_ENABLE, "", userCred) + logclient.AddActionLog(self, logclient.ACT_ENABLE, nil, userCred, true) } return nil, nil } @@ -56,6 +59,7 @@ func (self *SEnabledStatusStandaloneResourceBase) PerformDisable(ctx context.Con return nil, err } OpsLog.LogEvent(self, ACT_DISABLE, "", userCred) + logclient.AddActionLog(self, logclient.ACT_DISABLE, nil, userCred, true) } return nil, nil } diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 13f62f7bed..5df731c4fb 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -2447,7 +2447,7 @@ func (self *SHost) AllowPerformOffline(ctx context.Context, func (self *SHost) PerformOffline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { if self.HostStatus != HOST_OFFLINE { - _, err := self.SaveCleanUpdates(func() error { + _, err := self.SaveUpdates(func() error { self.HostStatus = HOST_OFFLINE return nil }) @@ -2456,6 +2456,7 @@ func (self *SHost) PerformOffline(ctx context.Context, userCred mcclient.TokenCr } db.OpsLog.LogEvent(self, db.ACT_OFFLINE, "", userCred) logclient.AddActionLog(self, logclient.ACT_ONLINE, nil, userCred, true) + self.SyncAttachedStorageStatus() } return nil, nil } @@ -2469,7 +2470,7 @@ func (self *SHost) AllowPerformOnline(ctx context.Context, func (self *SHost) PerformOnline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { if self.HostStatus != HOST_ONLINE { - _, err := self.SaveCleanUpdates(func() error { + _, err := self.SaveUpdates(func() error { self.LastPingAt = time.Now() self.HostStatus = HOST_ONLINE self.Status = BAREMETAL_RUNNING @@ -2966,24 +2967,46 @@ func (self *SHost) PerformRemoveAllNetifs(ctx context.Context, userCred mcclient return nil, nil } -func (self *SHost) AllowPerformDisable(ctx context.Context, +func (self *SHost) AllowPerformEnable( + ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, - data jsonutils.JSONObject) bool { - return db.IsAdminAllowPerform(userCred, self, "disable") + data jsonutils.JSONObject, +) bool { + return self.SEnabledStatusStandaloneResourceBase.AllowPerformEnable(ctx, userCred, query, data) +} + +func (self *SHost) PerformEnable( + ctx context.Context, + userCred mcclient.TokenCredential, + query jsonutils.JSONObject, + data jsonutils.JSONObject, +) (jsonutils.JSONObject, error) { + if !self.Enabled { + _, err := self.SEnabledStatusStandaloneResourceBase.PerformEnable(ctx, userCred, query, data) + if err != nil { + return nil, err + } + self.SyncAttachedStorageStatus() + } + return nil, nil +} + +func (self *SHost) AllowPerformDisable( + ctx context.Context, + userCred mcclient.TokenCredential, + query jsonutils.JSONObject, + data jsonutils.JSONObject, +) bool { + return self.SEnabledStatusStandaloneResourceBase.AllowPerformDisable(ctx, userCred, query, data) } func (self *SHost) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { if self.Enabled { - _, err := self.SaveCleanUpdates(func() error { - self.Enabled = false - return nil - }) + _, err := self.SEnabledStatusStandaloneResourceBase.PerformDisable(ctx, userCred, query, data) if err != nil { return nil, err } - db.OpsLog.LogEvent(self, db.ACT_DISABLE, "", userCred) - logclient.AddActionLog(self, logclient.ACT_DISABLE, nil, userCred, true) self.SyncAttachedStorageStatus() } return nil, nil diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index a2c6d829db..6901df0296 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -87,8 +87,8 @@ type SNetwork struct { GuestIpEnd string `width:"16" charset:"ascii" nullable:"false" list:"user" update:"user" create:"required"` // Column(VARCHAR(16, charset='ascii'), nullable=False) GuestIpMask int8 `nullable:"false" list:"user" update:"user" create:"required"` // Column(TINYINT, nullable=False) GuestGateway string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) - GuestDns string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) - GuestDhcp string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + GuestDns string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) + GuestDhcp string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) GuestDomain string `width:"128" charset:"ascii" nullable:"true" get:"user" update:"user"` // Column(VARCHAR(128, charset='ascii'), nullable=True)