From 3b6ff508b815c2f87a97f16921e8d3c44b219bd8 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Sat, 14 Dec 2024 12:35:12 +0800 Subject: [PATCH 1/2] fix: add more action log --- pkg/compute/models/guest_sshable.go | 3 ++ pkg/compute/models/hosts.go | 5 ++ pkg/compute/models/reservedips.go | 3 ++ pkg/compute/models/schedtags.go | 2 + pkg/compute/models/snapshots.go | 7 +++ .../baremetal_unconvert_hypervisor_task.go | 2 + pkg/compute/tasks/disk_syncstatus_task.go | 1 + pkg/compute/tasks/guest_eject_iso_task.go | 7 +++ pkg/compute/tasks/guest_insert_iso_task.go | 4 ++ pkg/compute/tasks/guest_reset_task.go | 2 + .../tasks/guest_sync_isolated_device_task.go | 1 + pkg/compute/tasks/guest_syncstatus_task.go | 5 +- pkg/keystone/models/users.go | 5 ++ pkg/util/logclient/consts.go | 17 +++++++ pkg/util/logclient/consts_i18n.go | 46 +++++++++++++++++++ 15 files changed, 108 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/guest_sshable.go b/pkg/compute/models/guest_sshable.go index 3c7165db1f8..643fe2c6ff1 100644 --- a/pkg/compute/models/guest_sshable.go +++ b/pkg/compute/models/guest_sshable.go @@ -38,6 +38,7 @@ import ( ansible_modules "yunion.io/x/onecloud/pkg/mcclient/modules/ansible" cloudproxy_module "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy" "yunion.io/x/onecloud/pkg/util/ansible" + "yunion.io/x/onecloud/pkg/util/logclient" ssh_util "yunion.io/x/onecloud/pkg/util/ssh" ) @@ -109,6 +110,7 @@ func (guest *SGuest) GetDetailsSshable( } } + logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_TRYSSHABLE, nil, userCred, true) return tryData.outputJSON(), nil } @@ -498,6 +500,7 @@ func (guest *SGuest) PerformMakeSshable( return output, httperrors.NewGeneralError(err) } + logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MAKESSHABLE, nil, userCred, true) output = compute_api.GuestMakeSshableOutput{ AnsiblePlaybookId: pbModel.Id, } diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index a292b27b034..898c1f1f79e 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -4814,6 +4814,7 @@ func (hh *SHost) PerformAutoMigrateOnHostDown( return nil, err } + logclient.AddActionLogWithContext(ctx, hh, logclient.ACT_AUTO_MIGRATE_ON_HOST_DOWN, nil, userCred, true) return nil, hh.SetAllMetadata(ctx, meta, userCred) } @@ -6049,7 +6050,9 @@ func (hh *SHost) PerformUndoConvert(ctx context.Context, userCred mcclient.Token } db.OpsLog.LogEvent(&guest, db.ACT_DELETE, "Unconvert baremetal", userCred) } + db.OpsLog.LogEvent(hh, db.ACT_UNCONVERT_START, "", userCred) + logclient.AddActionLogWithContext(ctx, hh, logclient.ACT_UNCONVERT_START, nil, userCred, true) task, err := taskman.TaskManager.NewTask(ctx, "BaremetalUnconvertHypervisorTask", hh, userCred, nil, "", "", nil) if err != nil { return nil, err @@ -6538,6 +6541,7 @@ func (host *SHost) PerformHostExitMaintenance(ctx context.Context, userCred mccl if err != nil { return nil, err } + logclient.AddSimpleActionLog(host, logclient.ACT_HOST_UNMAINTENANCE, "host unmaintenance", userCred, true) return nil, nil } @@ -7127,6 +7131,7 @@ func (host *SHost) PerformSetReservedResourceForIsolatedDevice( return nil, errors.Wrap(err, "update isolated device") } } + logclient.AddSimpleActionLog(host, logclient.ACT_SET_RESERVE_RESOURCE_FOR_ISOLATED_DEVICES, nil, userCred, true) return nil, nil } diff --git a/pkg/compute/models/reservedips.go b/pkg/compute/models/reservedips.go index b8e1dbe4cf6..9008b25ab35 100644 --- a/pkg/compute/models/reservedips.go +++ b/pkg/compute/models/reservedips.go @@ -31,6 +31,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/util/logclient" "yunion.io/x/onecloud/pkg/util/stringutils2" ) @@ -124,6 +125,7 @@ func (manager *SReservedipManager) ReserveIPWithDurationAndStatus(ctx context.Co } } db.OpsLog.LogEvent(network, db.ACT_RESERVE_IP, rip.GetShortDesc(ctx), userCred) + logclient.AddSimpleActionLog(network, logclient.ACT_RESERVE_IP, rip.GetShortDesc(ctx), userCred, true) return nil } @@ -222,6 +224,7 @@ func (self *SReservedip) Release(ctx context.Context, userCred mcclient.TokenCre err := db.DeleteModel(ctx, userCred, self) if err == nil && network != nil { db.OpsLog.LogEvent(network, db.ACT_RELEASE_IP, self.GetShortDesc(ctx), userCred) + logclient.AddSimpleActionLog(network, logclient.ACT_RELEASE_IP, self.GetShortDesc(ctx), userCred, true) } return err } diff --git a/pkg/compute/models/schedtags.go b/pkg/compute/models/schedtags.go index e8b74b33315..2eb2fabc4d5 100644 --- a/pkg/compute/models/schedtags.go +++ b/pkg/compute/models/schedtags.go @@ -33,6 +33,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/util/logclient" "yunion.io/x/onecloud/pkg/util/stringutils2" ) @@ -603,6 +604,7 @@ func PerformSetResourceSchedtag(obj IModelWithSchedtag, ctx context.Context, use if err := obj.ClearSchedDescCache(); err != nil { log.Errorf("Resource %s/%s ClearSchedDescCache error: %v", obj.Keyword(), obj.GetId(), err) } + logclient.AddActionLogWithContext(ctx, obj, logclient.ACT_SET_SCHED_TAG, nil, userCred, true) return nil, nil } diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index c87e8bb41b0..53572d4e014 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -417,6 +417,13 @@ func (manager *SSnapshotManager) FetchCustomizeColumns( func (self *SSnapshot) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { res := self.SVirtualResourceBase.GetShortDesc(ctx) res.Add(jsonutils.NewInt(int64(self.Size)), "size") + res.Add(jsonutils.NewString(self.DiskId), "disk_id") + disk, _ := self.GetDisk() + if disk != nil { + if guest := disk.GetGuest(); guest != nil { + res.Add(jsonutils.NewString(guest.Id), "guest_id") + } + } info := self.getCloudProviderInfo() res.Update(jsonutils.Marshal(&info)) return res diff --git a/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go b/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go index 7305dfbc482..cc630d2cd1b 100644 --- a/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go +++ b/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go @@ -61,6 +61,7 @@ func (self *BaremetalUnconvertHypervisorTask) OnInit(ctx context.Context, obj db func (self *BaremetalUnconvertHypervisorTask) OnGuestDeleteComplete(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) { db.OpsLog.LogEvent(baremetal, db.ACT_UNCONVERT_COMPLETE, "", self.UserCred) + logclient.AddActionLogWithContext(ctx, baremetal, logclient.ACT_UNCONVERT_COMPLETE, nil, self.UserCred, true) driver, err := baremetal.GetHostDriver() if err != nil { self.SetStageFailed(ctx, jsonutils.NewString(errors.Wrapf(err, "GetHostDriver").Error())) @@ -77,6 +78,7 @@ func (self *BaremetalUnconvertHypervisorTask) OnGuestDeleteComplete(ctx context. func (self *BaremetalUnconvertHypervisorTask) OnGuestDeleteCompleteFailed(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) { db.OpsLog.LogEvent(baremetal, db.ACT_UNCONVERT_FAIL, body, self.UserCred) + logclient.AddActionLogWithContext(ctx, baremetal, logclient.ACT_UNCONVERT_COMPLETE, nil, self.UserCred, false) self.SetStage("OnFailSyncstatusComplete", nil) baremetal.StartSyncstatus(ctx, self.UserCred, self.GetTaskId()) logclient.AddActionLogWithStartable(self, baremetal, logclient.ACT_BM_UNCONVERT_HYPER, body, self.UserCred, false) diff --git a/pkg/compute/tasks/disk_syncstatus_task.go b/pkg/compute/tasks/disk_syncstatus_task.go index 71308eba5a1..03b4ff58c49 100644 --- a/pkg/compute/tasks/disk_syncstatus_task.go +++ b/pkg/compute/tasks/disk_syncstatus_task.go @@ -66,6 +66,7 @@ func (self *DiskSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneMo } func (self *DiskSyncstatusTask) OnDiskSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { + logclient.AddActionLogWithContext(ctx, obj, logclient.ACT_SYNC_STATUS, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/guest_eject_iso_task.go b/pkg/compute/tasks/guest_eject_iso_task.go index 095c3068698..11a6d6baddd 100644 --- a/pkg/compute/tasks/guest_eject_iso_task.go +++ b/pkg/compute/tasks/guest_eject_iso_task.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" + "yunion.io/x/onecloud/pkg/util/logclient" ) type GuestEjectISOTask struct { @@ -54,5 +55,11 @@ func (self *GuestEjectISOTask) startEjectIso(ctx context.Context, obj db.IStanda } func (self *GuestEjectISOTask) OnConfigSyncComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { + logclient.AddActionLogWithContext(ctx, obj, logclient.ACT_ISO_DETACH, nil, self.UserCred, true) self.SetStageComplete(ctx, nil) } + +func (self *GuestEjectISOTask) OnConfigSyncCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { + logclient.AddActionLogWithContext(ctx, obj, logclient.ACT_ISO_DETACH, nil, self.UserCred, false) + self.SetStageFailed(ctx, nil) +} diff --git a/pkg/compute/tasks/guest_insert_iso_task.go b/pkg/compute/tasks/guest_insert_iso_task.go index 80ee23df22e..6e20fd3262c 100644 --- a/pkg/compute/tasks/guest_insert_iso_task.go +++ b/pkg/compute/tasks/guest_insert_iso_task.go @@ -24,6 +24,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" + "yunion.io/x/onecloud/pkg/util/logclient" ) type GuestInsertIsoTask struct { @@ -62,6 +63,7 @@ func (self *GuestInsertIsoTask) prepareIsoImage(ctx context.Context, obj db.ISta } else { guest.EjectIso(cdromOrdinal, self.UserCred) db.OpsLog.LogEvent(obj, db.ACT_ISO_PREPARE_FAIL, imageId, self.UserCred) + logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_ISO_ATTACH, nil, self.UserCred, false) self.SetStageFailed(ctx, jsonutils.NewString("host no local storage cache")) } } @@ -72,6 +74,7 @@ func (self *GuestInsertIsoTask) OnIsoPrepareCompleteFailed(ctx context.Context, db.OpsLog.LogEvent(obj, db.ACT_ISO_PREPARE_FAIL, imageId, self.UserCred) guest := obj.(*models.SGuest) guest.EjectIso(cdromOrdinal, self.UserCred) + logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_ISO_ATTACH, nil, self.UserCred, false) self.SetStageFailed(ctx, data) } @@ -95,6 +98,7 @@ func (self *GuestInsertIsoTask) OnIsoPrepareComplete(ctx context.Context, obj db guest := obj.(*models.SGuest) if cdrom, ok := guest.InsertIsoSucc(cdromOrdinal, imageId, path, size, name, bootIndex); ok { db.OpsLog.LogEvent(guest, db.ACT_ISO_ATTACH, cdrom.GetDetails(), self.UserCred) + logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_ISO_ATTACH, cdrom.GetDetails(), self.UserCred, true) drv, err := guest.GetDriver() if err != nil { self.OnIsoPrepareCompleteFailed(ctx, guest, jsonutils.NewString(err.Error())) diff --git a/pkg/compute/tasks/guest_reset_task.go b/pkg/compute/tasks/guest_reset_task.go index f522ceb430f..1d0981617fc 100644 --- a/pkg/compute/tasks/guest_reset_task.go +++ b/pkg/compute/tasks/guest_reset_task.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" + "yunion.io/x/onecloud/pkg/util/logclient" ) func init() { @@ -76,6 +77,7 @@ func (self *GuestHardResetTask) StartServer(ctx context.Context, guest *models.S } func (self *GuestHardResetTask) OnServerStartComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { + logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_RESTART, nil, self.GetUserCred(), true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/guest_sync_isolated_device_task.go b/pkg/compute/tasks/guest_sync_isolated_device_task.go index 9635cfdb916..d953a56b2d3 100644 --- a/pkg/compute/tasks/guest_sync_isolated_device_task.go +++ b/pkg/compute/tasks/guest_sync_isolated_device_task.go @@ -73,6 +73,7 @@ func (self *GuestIsolatedDeviceSyncTask) OnSyncConfigCompleteFailed(ctx context. } func (self *GuestIsolatedDeviceSyncTask) OnStartComplete(ctx context.Context, obj *models.SGuest, data jsonutils.JSONObject) { + logclient.AddActionLogWithStartable(self, obj, logclient.ACT_VM_SYNC_ISOLATED_DEVICE, nil, self.GetUserCred(), true) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/guest_syncstatus_task.go b/pkg/compute/tasks/guest_syncstatus_task.go index 7ce7eef191a..7c3e961f5c3 100644 --- a/pkg/compute/tasks/guest_syncstatus_task.go +++ b/pkg/compute/tasks/guest_syncstatus_task.go @@ -27,6 +27,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" + "yunion.io/x/onecloud/pkg/util/logclient" ) type GuestSyncstatusTask struct { @@ -106,13 +107,13 @@ func (self *GuestSyncstatusTask) OnGetStatusComplete(ctx context.Context, obj db BlockJobsCount: int(blockJobsCount), } guest.PerformStatus(ctx, self.UserCred, nil, input) + logclient.AddSimpleActionLog(guest, logclient.ACT_VM_SYNC_STATUS, "", self.UserCred, true) self.SetStageComplete(ctx, nil) - // logclient.AddActionLog(guest, logclient.ACT_VM_SYNC_STATUS, "", self.UserCred, true) } func (self *GuestSyncstatusTask) OnGetStatusCompleteFailed(ctx context.Context, obj db.IStandaloneModel, err jsonutils.JSONObject) { guest := obj.(*models.SGuest) guest.SetStatus(ctx, self.UserCred, api.VM_UNKNOWN, err.String()) + logclient.AddSimpleActionLog(guest, logclient.ACT_VM_SYNC_STATUS, err, self.UserCred, false) self.SetStageComplete(ctx, nil) - // logclient.AddActionLog(guest, logclient.ACT_VM_SYNC_STATUS, err, self.UserCred, false) } diff --git a/pkg/keystone/models/users.go b/pkg/keystone/models/users.go index 7ef9ae22a57..3584aa09268 100644 --- a/pkg/keystone/models/users.go +++ b/pkg/keystone/models/users.go @@ -1307,11 +1307,13 @@ func (user *SUser) PerformJoin( ) (jsonutils.JSONObject, error) { err := joinProjects(user, true, ctx, userCred, input) if err != nil { + logclient.AddActionLogWithContext(ctx, user, logclient.ACT_JOIN_PROJECT, nil, userCred, false) return nil, errors.Wrap(err, "joinProjects") } if input.Enabled { db.EnabledPerformEnable(user, ctx, userCred, true) } + logclient.AddActionLogWithContext(ctx, user, logclient.ACT_JOIN_PROJECT, nil, userCred, true) return nil, nil } @@ -1381,8 +1383,10 @@ func (user *SUser) PerformLeave( ) (jsonutils.JSONObject, error) { err := leaveProjects(user, true, ctx, userCred, input) if err != nil { + logclient.AddActionLogWithContext(ctx, user, logclient.ACT_LEAVE_PROJECT, nil, userCred, false) return nil, err } + logclient.AddActionLogWithContext(ctx, user, logclient.ACT_LEAVE_PROJECT, nil, userCred, true) return nil, nil } @@ -1538,6 +1542,7 @@ func (user *SUser) PerformResetCredentials( return nil, errors.Wrapf(err, "DeleteAll %s", api.RECOVERY_SECRETS_TYPE) } } + logclient.AddActionLogWithContext(ctx, user, logclient.ACT_RESET_CREDENTIAL, nil, userCred, true) return nil, nil } diff --git a/pkg/util/logclient/consts.go b/pkg/util/logclient/consts.go index 09fa83d547d..ad123c9041f 100644 --- a/pkg/util/logclient/consts.go +++ b/pkg/util/logclient/consts.go @@ -143,6 +143,7 @@ const ( ACT_GUEST_CREATE_FROM_IMPORT = "guest_create_from_import" ACT_GUEST_PANICKED = "guest_panicked" ACT_HOST_MAINTAINING = "host_maintaining" + ACT_HOST_UNMAINTENANCE = "host_unmaintenance" ACT_MKDIR = "mkdir" ACT_DELETE_OBJECT = "delete_object" @@ -245,6 +246,11 @@ const ( ACT_CONSOLE = "console" ACT_WEBSSH = "webssh" ACT_SET_USER_PASSWORD = "set_user_password" + ACT_MAKESSHABLE = "make_sshable" + ACT_TRYSSHABLE = "try_sshable" + + ACT_ISO_ATTACH = "iso_attach" + ACT_ISO_DETACH = "iso_detach" ACT_SYNC_OS_INFO = "sync_os_info" @@ -280,6 +286,17 @@ const ( ACT_DELETE_SECURITY_GROUP_RULE = "delete_security_group_rule" ACT_CLEAN_PROJECT = "clean_project" + ACT_JOIN_PROJECT = "join_project" + ACT_LEAVE_PROJECT = "leave_project" + + ACT_SET_SCHED_TAG = "set_sched_tag" + ACT_RESET_CREDENTIAL = "reset_credential" + + ACT_AUTO_MIGRATE_ON_HOST_DOWN = "auto_migrate_on_host" + ACT_SET_RESERVE_RESOURCE_FOR_ISOLATED_DEVICES = "set_reserve_resource_for_isolated_devices" + + ACT_UNCONVERT_START = "unconverting" + ACT_UNCONVERT_COMPLETE = "unconverted" ACT_COLLECT_METRICS = "collect_metrics" diff --git a/pkg/util/logclient/consts_i18n.go b/pkg/util/logclient/consts_i18n.go index 116e6db65ca..9b9ca227928 100644 --- a/pkg/util/logclient/consts_i18n.go +++ b/pkg/util/logclient/consts_i18n.go @@ -451,6 +451,10 @@ func init() { EN("Host Maintaining"). CN("宿主机进入维护模式"), ) + t.Set(ACT_HOST_UNMAINTENANCE, i18n.NewTableEntry(). + EN("Host Unmaintenance"). + CN("宿主机退出维护模式"), + ) t.Set(ACT_MKDIR, i18n.NewTableEntry(). EN("Mkdir"). @@ -1373,6 +1377,16 @@ func init() { CN("WebSSH"), ) + o.Set(ACT_TRYSSHABLE, i18n.NewTableEntry(). + EN("Try Sshable"). + CN("探测免密登录"), + ) + + o.Set(ACT_MAKESSHABLE, i18n.NewTableEntry(). + EN("Make Sshable"). + CN("设置免密登录"), + ) + o.Set(ACT_CLOUDACCOUNT_SYNC_NETWORK, i18n.NewTableEntry(). EN("Probe Network"). CN("探测网络配置"), @@ -1483,4 +1497,36 @@ func init() { CN("删除费率"), ) + o.Set(ACT_JOIN_PROJECT, i18n.NewTableEntry(). + EN("Join Project"). + CN("加入项目"), + ) + o.Set(ACT_LEAVE_PROJECT, i18n.NewTableEntry(). + EN("Leave Project"). + CN("移除项目"), + ) + o.Set(ACT_RESET_CREDENTIAL, i18n.NewTableEntry(). + EN("Reset Credential"). + CN("重置账号密码"), + ) + o.Set(ACT_SET_SCHED_TAG, i18n.NewTableEntry(). + EN("Set Scheduler Tag"). + CN("设置调度标签"), + ) + o.Set(ACT_AUTO_MIGRATE_ON_HOST_DOWN, i18n.NewTableEntry(). + EN("Auto Migrate On Host Down"). + CN("宕机自动迁移"), + ) + o.Set(ACT_SET_RESERVE_RESOURCE_FOR_ISOLATED_DEVICES, i18n.NewTableEntry(). + EN("Set Reserve Resource For Isolated Devices"). + CN("透传设备设置预留资源"), + ) + o.Set(ACT_UNCONVERT_START, i18n.NewTableEntry(). + EN("Start Unconvert hypervisor"). + CN("开始回收为物理机"), + ) + o.Set(ACT_UNCONVERT_COMPLETE, i18n.NewTableEntry(). + EN("Unconvert Hypervisor Complete"). + CN("回收为物理机"), + ) } From b63b1aff50b4c056ac3d472429d267ef63459f9c Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Sun, 22 Dec 2024 17:09:38 +0800 Subject: [PATCH 2/2] fix(region): add set cmt bound action --- cmd/climc/shell/compute/hosts.go | 21 +++++++------------ cmd/climc/shell/compute/storages.go | 1 + pkg/apis/compute/host.go | 5 +++++ pkg/apis/compute/storage.go | 4 ++++ pkg/cloudcommon/db/opslog_const.go | 2 ++ pkg/compute/models/hosts.go | 27 ++++++++++++++++++++++-- pkg/compute/models/storages.go | 22 ++++++++++++++++++- pkg/mcclient/options/compute/host.go | 10 +++++++++ pkg/mcclient/options/compute/storage.go | 28 ++++++++++++++++--------- pkg/util/logclient/consts.go | 1 + pkg/util/logclient/consts_i18n.go | 4 ++++ 11 files changed, 98 insertions(+), 27 deletions(-) diff --git a/cmd/climc/shell/compute/hosts.go b/cmd/climc/shell/compute/hosts.go index 90ec0597f14..ad88f65f27f 100644 --- a/cmd/climc/shell/compute/hosts.go +++ b/cmd/climc/shell/compute/hosts.go @@ -54,6 +54,7 @@ func init() { cmd.Perform("class-metadata", &options.ResourceMetadataOptions{}) cmd.Perform("set-class-metadata", &options.ResourceMetadataOptions{}) cmd.PerformClass("validate-ipmi", &compute.HostValidateIPMI{}) + cmd.Perform("set-commit-bound", &compute.HostSetCommitBoundOptions{}) cmd.BatchPerform("enable", &options.BaseIdsOptions{}) cmd.BatchPerform("disable", &options.BaseIdsOptions{}) @@ -201,14 +202,12 @@ func init() { }) type HostUpdateOptions struct { - ID string `help:"ID or Name of Host"` - Name string `help:"New name of the host"` - Desc string `help:"New Description of the host"` - CpuCommitBound float64 `help:"CPU overcommit upper bound at this host"` - MemoryCommitBound float64 `help:"Memory overcommit upper bound at this host"` - MemoryReserved string `help:"Memory reserved"` - CpuReserved int64 `help:"CPU reserved"` - HostType string `help:"Change host type, CAUTION!!!!" choices:"hypervisor|kubelet|esxi|baremetal"` + ID string `help:"ID or Name of Host"` + Name string `help:"New name of the host"` + Desc string `help:"New Description of the host"` + MemoryReserved string `help:"Memory reserved"` + CpuReserved int64 `help:"CPU reserved"` + HostType string `help:"Change host type, CAUTION!!!!" choices:"hypervisor|kubelet|esxi|baremetal"` // AccessIp string `help:"Change access ip, CAUTION!!!!"` AccessMac string `help:"Change baremetal access MAC, CAUTION!!!!"` Uuid string `help:"Change baremetal UUID, CAUTION!!!!"` @@ -234,12 +233,6 @@ func init() { if len(args.Desc) > 0 { params.Add(jsonutils.NewString(args.Desc), "description") } - if args.CpuCommitBound > 0.0 { - params.Add(jsonutils.NewFloat64(args.CpuCommitBound), "cpu_cmtbound") - } - if args.MemoryCommitBound > 0.0 { - params.Add(jsonutils.NewFloat64(args.MemoryCommitBound), "mem_cmtbound") - } if len(args.MemoryReserved) > 0 { params.Add(jsonutils.NewString(args.MemoryReserved), "mem_reserved") } diff --git a/cmd/climc/shell/compute/storages.go b/cmd/climc/shell/compute/storages.go index 878c1462dfb..81dcb24b9ad 100644 --- a/cmd/climc/shell/compute/storages.go +++ b/cmd/climc/shell/compute/storages.go @@ -47,6 +47,7 @@ func init() { cmd.Perform("private", &options.BaseIdOptions{}) cmd.Get("hardware-info", &options.BaseIdOptions{}) cmd.Perform("set-hardware-info", &compute.StorageSetHardwareInfoOptions{}) + cmd.Perform("set-commit-bound", &compute.StorageSetCommitBoundOptions{}) type StorageCephRunOptions struct { ID string `help:"ID or name of ceph storage"` diff --git a/pkg/apis/compute/host.go b/pkg/apis/compute/host.go index df8cab915dd..8802964fef7 100644 --- a/pkg/apis/compute/host.go +++ b/pkg/apis/compute/host.go @@ -663,3 +663,8 @@ type HostLoginInfoOutput struct { type HostPerformStartInput struct { } + +type HostSetCommitBoundInput struct { + CpuCmtbound *float32 + MemCmtbound *float32 +} diff --git a/pkg/apis/compute/storage.go b/pkg/apis/compute/storage.go index 81d7dc55206..8df47acbd04 100644 --- a/pkg/apis/compute/storage.go +++ b/pkg/apis/compute/storage.go @@ -258,3 +258,7 @@ type StorageUpdateInput struct { HardwareInfo *StorageHardwareInfo `json:"hardware_info"` MasterHost string } + +type StorageSetCmtBoundInput struct { + Cmtbound *float32 +} diff --git a/pkg/cloudcommon/db/opslog_const.go b/pkg/cloudcommon/db/opslog_const.go index fb7ec2862c4..11d2ad01412 100644 --- a/pkg/cloudcommon/db/opslog_const.go +++ b/pkg/cloudcommon/db/opslog_const.go @@ -339,4 +339,6 @@ const ( ACT_REBUILD = "rebuild" ACT_REBUILD_FAILED = "rebuild_failed" + + ACT_SET_COMMIT_BOUND = "set_commit_bound" ) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 898c1f1f79e..a0a1c9b75c7 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -139,7 +139,7 @@ type SHost struct { // 预留CPU大小 CpuReserved int `nullable:"true" default:"0" list:"domain" update:"domain" create:"domain_optional"` // CPU超分比 - CpuCmtbound float32 `nullable:"true" default:"8" list:"domain" update:"domain" create:"domain_optional"` + CpuCmtbound float32 `nullable:"true" default:"8" list:"domain" create:"domain_optional"` // CPUMicrocode CpuMicrocode string `width:"64" charset:"ascii" nullable:"true" get:"domain" update:"domain" create:"domain_optional"` // CPU架构 @@ -150,7 +150,7 @@ type SHost struct { // 预留内存大小 MemReserved int `nullable:"true" default:"0" list:"domain" update:"domain" create:"domain_optional"` // 内存超分比 - MemCmtbound float32 `nullable:"true" default:"1" list:"domain" update:"domain" create:"domain_optional"` + MemCmtbound float32 `nullable:"true" default:"1" list:"domain" create:"domain_optional"` // 页大小 PageSizeKB int `nullable:"false" default:"4" list:"domain" update:"domain" create:"domain_optional"` EnableNumaAllocate bool `nullable:"true" default:"false" list:"domain" update:"domain" create:"domain_optional"` @@ -1057,6 +1057,29 @@ func (hh *SHost) saveUpdates(doUpdate func() error, doSchedClean bool) (map[stri return diff, nil } +func (hh *SHost) PerformSetCommitBound( + ctx context.Context, + userCred mcclient.TokenCredential, + query jsonutils.JSONObject, + input api.HostSetCommitBoundInput, +) (jsonutils.JSONObject, error) { + _, err := db.Update(hh, func() error { + if input.CpuCmtbound != nil { + hh.CpuCmtbound = *input.CpuCmtbound + } + if input.MemCmtbound != nil { + hh.MemCmtbound = *input.MemCmtbound + } + return nil + }) + if err != nil { + return nil, err + } + db.OpsLog.LogEvent(hh, db.ACT_SET_COMMIT_BOUND, input, userCred) + logclient.AddActionLogWithContext(ctx, hh, logclient.ACT_SET_COMMIT_BOUND, input, userCred, true) + return nil, nil +} + func (hh *SHost) PerformUpdateStorage( ctx context.Context, userCred mcclient.TokenCredential, diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 1a55b240cfc..eb0e9d3d732 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -88,7 +88,7 @@ type SStorage struct { // example: ssd MediumType string `width:"32" charset:"ascii" nullable:"false" list:"user" update:"domain" create:"domain_required"` // 超售比 - Cmtbound float32 `nullable:"true" default:"1" list:"domain" update:"domain"` + Cmtbound float32 `nullable:"true" default:"1" list:"domain"` // 存储配置信息 StorageConf jsonutils.JSONObject `nullable:"true" get:"domain" list:"domain" update:"domain"` @@ -1930,6 +1930,26 @@ func (self *SStorage) PerformSetSchedtag(ctx context.Context, userCred mcclient. return PerformSetResourceSchedtag(self, ctx, userCred, query, data) } +func (self *SStorage) PerformSetCommitBound( + ctx context.Context, + userCred mcclient.TokenCredential, + query jsonutils.JSONObject, + input api.StorageSetCmtBoundInput, +) (jsonutils.JSONObject, error) { + _, err := db.Update(self, func() error { + if input.Cmtbound != nil { + self.Cmtbound = *input.Cmtbound + } + return nil + }) + if err != nil { + return nil, err + } + db.OpsLog.LogEvent(self, db.ACT_SET_COMMIT_BOUND, input, userCred) + logclient.AddActionLogWithContext(ctx, self, logclient.ACT_SET_COMMIT_BOUND, input, userCred, true) + return nil, nil +} + func (self *SStorage) GetSchedtagJointManager() ISchedtagJointManager { return StorageschedtagManager } diff --git a/pkg/mcclient/options/compute/host.go b/pkg/mcclient/options/compute/host.go index 482e5c82c3e..66a758d3d21 100644 --- a/pkg/mcclient/options/compute/host.go +++ b/pkg/mcclient/options/compute/host.go @@ -126,6 +126,16 @@ func (o *HostAutoMigrateOnHostDownOptions) Params() (jsonutils.JSONObject, error return options.StructToParams(o) } +type HostSetCommitBoundOptions struct { + options.BaseIdOptions + CpuCmtbound *float32 `help:"Cpu commit bound"` + MemCmtBound *float32 `help:"Mem commit bound"` +} + +func (o *HostSetCommitBoundOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + type HostStatusStatisticsOptions struct { HostListOptions options.StatusStatisticsOptions diff --git a/pkg/mcclient/options/compute/storage.go b/pkg/mcclient/options/compute/storage.go index b452668b2e5..9e78bbf120a 100644 --- a/pkg/mcclient/options/compute/storage.go +++ b/pkg/mcclient/options/compute/storage.go @@ -49,16 +49,15 @@ func (opts *StorageListOptions) GetContextId() string { type StorageUpdateOptions struct { options.BaseUpdateOptions - CommitBound float64 `help:"Upper bound of storage overcommit rate" json:"cmtbound"` - MediumType string `help:"Medium type" choices:"ssd|rotate"` - RbdRadosMonOpTimeout int64 `help:"ceph rados_mon_op_timeout"` - RbdRadosOsdOpTimeout int64 `help:"ceph rados_osd_op_timeout"` - RbdClientMountTimeout int64 `help:"ceph client_mount_timeout"` - RbdEnableMessengerV2 bool `help:"ceph enable Messenger V2"` - RbdKey string `help:"ceph rbd key"` - Reserved string `help:"Reserved storage space"` - Capacity int `help:"Capacity for storage"` - MasterHost string `help:"slvm storage master host"` + MediumType string `help:"Medium type" choices:"ssd|rotate"` + RbdRadosMonOpTimeout int64 `help:"ceph rados_mon_op_timeout"` + RbdRadosOsdOpTimeout int64 `help:"ceph rados_osd_op_timeout"` + RbdClientMountTimeout int64 `help:"ceph client_mount_timeout"` + RbdEnableMessengerV2 bool `help:"ceph enable Messenger V2"` + RbdKey string `help:"ceph rbd key"` + Reserved string `help:"Reserved storage space"` + Capacity int `help:"Capacity for storage"` + MasterHost string `help:"slvm storage master host"` } func (opts *StorageUpdateOptions) Params() (jsonutils.JSONObject, error) { @@ -124,3 +123,12 @@ type StorageSetHardwareInfoOptions struct { func (o *StorageSetHardwareInfoOptions) Params() (jsonutils.JSONObject, error) { return jsonutils.Marshal(o), nil } + +type StorageSetCommitBoundOptions struct { + options.BaseIdOptions + Cmtbound *float32 `help:"Storage commit bound"` +} + +func (o *StorageSetCommitBoundOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} diff --git a/pkg/util/logclient/consts.go b/pkg/util/logclient/consts.go index ad123c9041f..6d65254716c 100644 --- a/pkg/util/logclient/consts.go +++ b/pkg/util/logclient/consts.go @@ -297,6 +297,7 @@ const ( ACT_UNCONVERT_START = "unconverting" ACT_UNCONVERT_COMPLETE = "unconverted" + ACT_SET_COMMIT_BOUND = "set_commit_bound" ACT_COLLECT_METRICS = "collect_metrics" diff --git a/pkg/util/logclient/consts_i18n.go b/pkg/util/logclient/consts_i18n.go index 9b9ca227928..6073104f5a5 100644 --- a/pkg/util/logclient/consts_i18n.go +++ b/pkg/util/logclient/consts_i18n.go @@ -1529,4 +1529,8 @@ func init() { EN("Unconvert Hypervisor Complete"). CN("回收为物理机"), ) + o.Set(ACT_SET_COMMIT_BOUND, i18n.NewTableEntry(). + EN("Set Commit Bound"). + CN("设置超售比"), + ) }