error.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 predicates
  15. import (
  16. "fmt"
  17. )
  18. // Here are all the errors that may appear in the preselection predicates.
  19. const (
  20. ErrServerTypeIsNotMatch = `server type is not match`
  21. ErrExitIsNotMatch = `exit is not match`
  22. ErrWireIsNotMatch = `wire is not match`
  23. ErrNotSupportIpv6 = `not support ipv6`
  24. ErrNoPorts = `no ports`
  25. ErrNotOwner = `not owner`
  26. ErrNoEnoughStorage = `no enough storage`
  27. ErrNoAvailableNetwork = `no available network on this host`
  28. ErrNoEnoughAvailableGPUs = `no enough available GPUs`
  29. ErrNotSupportNest = `nested function not supported`
  30. ErrRequireMvs = `require mvs`
  31. ErrRequireNoMvs = `require not mvs`
  32. ErrHostIsSpecifiedForMigration = `host_id specified for migration`
  33. ErrHostCpuModelIsNotMatchForLiveMigrate = `host cpu mode not match for live migrate`
  34. ErrHostCpuMicrocodeNotMatchForLiveMigrate = `host cpu microcode not match for live migrate`
  35. ErrHostMemPageSizeNotMatchForLiveMigrate = `host mem page size not match for live migrate`
  36. ErrHostKernelNotMatchForLiveMigrate = `host kernel not match for live migrate`
  37. ErrMoreThanOneSizeUnspecificSplit = `more than 1 size unspecific split`
  38. ErrNoMoreSpaceForUnspecificSplit = `no more space for an unspecific split`
  39. ErrSubtotalOfSplitExceedsDiskSize = `subtotal of split exceeds disk size`
  40. ErrBaremetalHasAlreadyBeenOccupied = `baremetal has already been occupied`
  41. ErrPrepaidHostOccupied = `prepaid host occupied`
  42. ErrHostCpuArchitectureNotMatch = `host cpu architecture not match`
  43. ErrHostKvmVcpuMaxNotEnough = `host kvm vcpu max not enough`
  44. ErrUnknown = `unknown error`
  45. )
  46. // InsufficientResourceError is an error type that indicates what kind of resource limit is
  47. // hit and caused the unfitting failure.
  48. type InsufficientResourceError struct {
  49. // resourceName is the name of the resource that is insufficient
  50. ResourceName string
  51. requested int64
  52. total int64
  53. free int64
  54. }
  55. func NewInsufficientResourceError(resourceName string, requested, total, free int64) *InsufficientResourceError {
  56. return &InsufficientResourceError{
  57. ResourceName: resourceName,
  58. requested: requested,
  59. total: total,
  60. free: free,
  61. }
  62. }
  63. func (ire *InsufficientResourceError) Error() string {
  64. return fmt.Sprintf("no enough resource: %s, requested: %d, total: %d, free: %d",
  65. ire.ResourceName, ire.requested, ire.total, ire.free)
  66. }
  67. func (ire *InsufficientResourceError) GetReason() string {
  68. return ire.Error()
  69. }
  70. type UnexceptedResourceError struct {
  71. message string
  72. }
  73. func NewUnexceptedResourceError(message string) *UnexceptedResourceError {
  74. return &UnexceptedResourceError{
  75. message: message,
  76. }
  77. }
  78. func Error(message string) *UnexceptedResourceError {
  79. return NewUnexceptedResourceError(message)
  80. }
  81. func (ure *UnexceptedResourceError) Error() string {
  82. return ure.message
  83. }
  84. func (ure *UnexceptedResourceError) GetReason() string {
  85. return ure.Error()
  86. }
  87. type FailReason struct {
  88. Reason string
  89. Type string
  90. }
  91. func (r FailReason) GetReason() string {
  92. return r.Reason
  93. }
  94. func (r FailReason) GetType() string {
  95. return r.Type
  96. }
  97. const (
  98. NetworkOwnership = "network_ownership"
  99. NetworkPrivate = "network_private"
  100. NetworkPublic = "network_public"
  101. NetworkTypeMatch = "network_type"
  102. NetworkMatch = "network_match"
  103. NetworkWire = "network_wire"
  104. NetworkOwner = "network_owner"
  105. NetworkDomain = "network_domain"
  106. NetworkRange = "network_range"
  107. NetworkFreeCount = "network_free_count"
  108. NetworkPort = "network_port"
  109. StorageEnable = "storage_status"
  110. StorageMatch = "storage_match"
  111. StorageType = "storage_type"
  112. StorageOwnership = "storage_ownership"
  113. StorageMedium = "storage_medium"
  114. StorageCapacity = "storage_capacity"
  115. )