Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #21876: Automated cherry pick of #21875: Automated cherry pick of #21804: [WIP] fix: add more action log #21878

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions cmd/climc/shell/compute/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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!!!!"`
Expand All @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/climc/shell/compute/storages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/compute/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,8 @@ type HostLoginInfoOutput struct {

type HostPerformStartInput struct {
}

type HostSetCommitBoundInput struct {
CpuCmtbound *float32
MemCmtbound *float32
}
4 changes: 4 additions & 0 deletions pkg/apis/compute/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,7 @@ type StorageUpdateInput struct {
HardwareInfo *StorageHardwareInfo `json:"hardware_info"`
MasterHost string
}

type StorageSetCmtBoundInput struct {
Cmtbound *float32
}
2 changes: 2 additions & 0 deletions pkg/cloudcommon/db/opslog_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,6 @@ const (

ACT_REBUILD = "rebuild"
ACT_REBUILD_FAILED = "rebuild_failed"

ACT_SET_COMMIT_BOUND = "set_commit_bound"
)
3 changes: 3 additions & 0 deletions pkg/compute/models/guest_sshable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -109,6 +110,7 @@ func (guest *SGuest) GetDetailsSshable(
}
}

logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_TRYSSHABLE, nil, userCred, true)
return tryData.outputJSON(), nil
}

Expand Down Expand Up @@ -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,
}
Expand Down
32 changes: 30 additions & 2 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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架构
Expand All @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -4814,6 +4837,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)
}

Expand Down Expand Up @@ -6049,7 +6073,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
Expand Down Expand Up @@ -6538,6 +6564,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
}

Expand Down Expand Up @@ -7127,6 +7154,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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/compute/models/reservedips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/models/schedtags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/compute/models/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion pkg/compute/models/storages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/compute/tasks/disk_syncstatus_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/compute/tasks/guest_eject_iso_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions pkg/compute/tasks/guest_insert_iso_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))
}
}
Expand All @@ -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)
}

Expand All @@ -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()))
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/tasks/guest_reset_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/compute/tasks/guest_sync_isolated_device_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/compute/tasks/guest_syncstatus_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Loading
Loading