From a6abf41225c60302d21483dc720ccca38cb54076 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 25 Nov 2019 21:23:32 +0800 Subject: [PATCH] misc fix - image list filter by uefi - fix instance sanpshot delete - guest clean expire server exclude pending deleted servers - host register abort on network not match --- cmd/climc/shell/images.go | 4 +++ pkg/compute/models/guests.go | 10 +++++-- .../tasks/instance_snapshot_delete_task.go | 29 ++++++++++--------- pkg/hostman/hostinfo/hostinfohelper.go | 4 +++ pkg/image/models/images.go | 5 ++++ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cmd/climc/shell/images.go b/cmd/climc/shell/images.go index aa80653594..21587e2998 100644 --- a/cmd/climc/shell/images.go +++ b/cmd/climc/shell/images.go @@ -138,6 +138,7 @@ func init() { IsPublic string `help:"filter images public or not(True, False or None)" choices:"true|false"` IsStandard string `help:"filter images standard or non-standard" choices:"true|false"` Protected string `help:"filter images by protected" choices:"true|false"` + IsUefi bool `help:"list uefi image"` Format []string `help:"Disk formats"` Name string `help:"Name filter"` } @@ -155,6 +156,9 @@ func init() { if len(args.Protected) > 0 { params.Add(jsonutils.NewString(args.Protected), "protected") } + if args.IsUefi { + params.Add(jsonutils.JSONTrue, "uefi") + } if len(args.Tenant) > 0 { tid, e := modules.Projects.GetId(s, args.Tenant, nil) if e != nil { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index dfdc37683d..0296de07ed 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1577,7 +1577,7 @@ func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict, fields stringutils2 } } - if len(fields) == 0 || fields.Contains("host") || fields.ContainsAny(providerInfoFields...) { + if len(fields) == 0 || fields.Contains("host") || fields.ContainsAny(providerInfoFields...) || fields.Contains("host_sn") { host := self.GetHost() if host != nil { if len(fields) == 0 || fields.Contains("host") { @@ -1591,6 +1591,9 @@ func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict, fields stringutils2 extra.Update(jsonutils.Marshal(&info).(*jsonutils.JSONDict).CopyIncludes([]string(fields)...)) } } + if len(fields) == 0 || fields.Contains("host_sn") { + extra.Add(jsonutils.NewString(host.SN), "host_sn") + } } } @@ -4097,7 +4100,8 @@ func (manager *SGuestManager) getExpiredPrepaidGuests() []SGuest { deadline := time.Now().Add(time.Duration(options.Options.PrepaidExpireCheckSeconds*-1) * time.Second) q := manager.Query() - q = q.Equals("billing_type", billing_api.BILLING_TYPE_PREPAID).LT("expired_at", deadline).Limit(options.Options.ExpiredPrepaidMaxCleanBatchSize) + q = q.Equals("billing_type", billing_api.BILLING_TYPE_PREPAID).LT("expired_at", deadline). + IsFalse("pending_deleted").Limit(options.Options.ExpiredPrepaidMaxCleanBatchSize) guests := make([]SGuest, 0) err := db.FetchModelObjects(GuestManager, q, &guests) @@ -4111,7 +4115,7 @@ func (manager *SGuestManager) getExpiredPrepaidGuests() []SGuest { func (manager *SGuestManager) getExpiredPostpaidGuests() []SGuest { deadline := time.Now() - q := manager.Query().Equals("billing_type", billing_api.BILLING_TYPE_POSTPAID). + q := manager.Query().Equals("billing_type", billing_api.BILLING_TYPE_POSTPAID).IsFalse("pending_deleted"). LT("expired_at", deadline).Limit(options.Options.ExpiredPrepaidMaxCleanBatchSize) guests := make([]SGuest, 0) err := db.FetchModelObjects(GuestManager, q, &guests) diff --git a/pkg/compute/tasks/instance_snapshot_delete_task.go b/pkg/compute/tasks/instance_snapshot_delete_task.go index 8aef979468..2956e40c8e 100644 --- a/pkg/compute/tasks/instance_snapshot_delete_task.go +++ b/pkg/compute/tasks/instance_snapshot_delete_task.go @@ -55,7 +55,6 @@ func (self *InstanceSnapshotDeleteTask) OnInit( ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { isp := obj.(*models.SInstanceSnapshot) - self.SetStage("OnSnapshotDelete", nil) self.StartSnapshotDelete(ctx, isp) } @@ -72,10 +71,23 @@ func (self *InstanceSnapshotDeleteTask) StartSnapshotDelete( return } + params := jsonutils.NewDict() + params.Set("del_snapshot_id", jsonutils.NewString(snapshots[0].Id)) + self.SetStage("OnSnapshotDelete", params) + err = snapshots[0].StartSnapshotDeleteTask(ctx, self.UserCred, false, self.Id) + if err != nil { + self.taskFail(ctx, isp, err.Error()) + return + } +} + +func (self *InstanceSnapshotDeleteTask) OnSnapshotDelete( + ctx context.Context, isp *models.SInstanceSnapshot, data jsonutils.JSONObject) { + snapshotId, _ := self.Params.GetString("del_snapshot_id") // detach snapshot and instance isjp := new(models.SInstanceSnapshotJoint) - err = models.InstanceSnapshotJointManager.Query(). - Equals("instance_snapshot_id", isp.Id).Equals("snapshot_id", snapshots[0].Id).First(isjp) + err := models.InstanceSnapshotJointManager.Query(). + Equals("instance_snapshot_id", isp.Id).Equals("snapshot_id", snapshotId).First(isjp) if err != nil { self.taskFail(ctx, isp, err.Error()) return @@ -86,17 +98,6 @@ func (self *InstanceSnapshotDeleteTask) StartSnapshotDelete( self.taskFail(ctx, isp, err.Error()) return } - - err = snapshots[0].StartSnapshotDeleteTask(ctx, self.UserCred, false, self.Id) - if err != nil { - self.taskFail(ctx, isp, err.Error()) - return - } -} - -func (self *InstanceSnapshotDeleteTask) OnSnapshotDelete( - ctx context.Context, isp *models.SInstanceSnapshot, data jsonutils.JSONObject) { - self.StartSnapshotDelete(ctx, isp) } diff --git a/pkg/hostman/hostinfo/hostinfohelper.go b/pkg/hostman/hostinfo/hostinfohelper.go index 96bf391a12..652f2defab 100644 --- a/pkg/hostman/hostinfo/hostinfohelper.go +++ b/pkg/hostman/hostinfo/hostinfohelper.go @@ -316,6 +316,10 @@ func NewNIC(desc string) (*SNIC, error) { time.Sleep(time.Second * 2) wait += 1 } + if wait >= max { + // if ip not found in inter or bridge + return nil, fmt.Errorf("Ip %s is not configure on %s/%s ?", nic.Ip, nic.Bridge, nic.Inter) + } } var err error diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index dc6ef83c3f..a0fdb1275d 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -1087,6 +1087,11 @@ func (manager *SImageManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ fmtArray := jsonutils.JSONArray2StringArray(fmtJsonArray) q = q.In("disk_format", fmtArray) } + if jsonutils.QueryBoolean(query, "uefi", false) { + imagePropertyQ := ImagePropertyManager.Query(). + Equals("name", api.IMAGE_UEFI_SUPPORT).Equals("value", "true").SubQuery() + q = q.Join(imagePropertyQ, sqlchemy.Equals(q.Field("id"), imagePropertyQ.Field("image_id"))) + } return q, nil }