events.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package notifyclient
  15. import (
  16. "fmt"
  17. "strings"
  18. api "yunion.io/x/onecloud/pkg/apis/notify"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  20. )
  21. const (
  22. SYSTEM_ERROR = "SYSTEM_ERROR"
  23. SYSTEM_WARNING = "SYSTEM_WARNING"
  24. SERVER_CREATED = "SERVER_CREATED"
  25. SERVER_CREATED_ADMIN = "SERVER_CREATED_ADMIN"
  26. SERVER_DELETED = "SERVER_DELETED"
  27. SERVER_DELETED_ADMIN = "SERVER_DELETED_ADMIN"
  28. SERVER_REBUILD_ROOT = "SERVER_REBUILD_ROOT"
  29. SERVER_CHANGE_FLAVOR = "SERVER_CHANGE_FLAVOR"
  30. SERVER_PANICKED = "SERVER_PANICKED"
  31. IMAGE_ACTIVED = "IMAGE_ACTIVED"
  32. USER_LOGIN_EXCEPTION = "USER_LOGIN_EXCEPTION"
  33. )
  34. var (
  35. Event SEvent
  36. ActionCreate = api.ActionCreate
  37. ActionDelete = api.ActionDelete
  38. ActionUpdate = api.ActionUpdate
  39. ActionReset = api.ActionReset
  40. ActionRebuildRoot = api.ActionRebuildRoot
  41. ActionResetPassword = api.ActionResetPassword
  42. ActionChangeConfig = api.ActionChangeConfig
  43. ActionResize = api.ActionResize
  44. ActionExpiredRelease = api.ActionExpiredRelease
  45. ActionExecute = api.ActionExecute
  46. ActionMigrate = api.ActionMigrate
  47. ActionCreateBackupServer = api.ActionCreateBackupServer
  48. ActionDelBackupServer = api.ActionDelBackupServer
  49. ActionSyncStatus = api.ActionSyncStatus
  50. ActionNetOutOfSync = api.ActionNetOutOfSync
  51. ActionMysqlOutOfSync = api.ActionMysqlOutOfSync
  52. ActionServiceAbnormal = api.ActionServiceAbnormal
  53. ActionServerPanicked = api.ActionServerPanicked
  54. ActionHostDown = api.ActionHostDown
  55. ActionHostDownAutoMigrate = api.ActionHostDownAutoMigrate
  56. ActionPendingDelete = api.ActionPendingDelete
  57. ActionSyncCreate = api.ActionSyncCreate
  58. ActionSyncUpdate = api.ActionSyncUpdate
  59. ActionSyncDelete = api.ActionSyncDelete
  60. ActionSyncAccountStatus = api.ActionSyncAccountStatus
  61. ActionIsolatedDeviceCreate = api.ActionIsolatedDeviceCreate
  62. ActionIsolatedDeviceUpdate = api.ActionIsolatedDeviceUpdate
  63. ActionIsolatedDeviceDelete = api.ActionIsolatedDeviceDelete
  64. )
  65. type SEvent struct {
  66. resourceType string
  67. action api.SAction
  68. }
  69. func (se SEvent) WithResourceType(manager db.IModelManager) SEvent {
  70. se.resourceType = manager.Keyword()
  71. return se
  72. }
  73. func (se SEvent) WithAction(a api.SAction) SEvent {
  74. se.action = a
  75. return se
  76. }
  77. func (se SEvent) ResourceType() string {
  78. return se.resourceType
  79. }
  80. func (se SEvent) Action() string {
  81. return string(se.action)
  82. }
  83. func (se SEvent) String() string {
  84. return strings.ToUpper(fmt.Sprintf("%s_%s", se.ResourceType(), se.Action()))
  85. }