modelsets.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 models
  15. import "yunion.io/x/onecloud/pkg/apihelper"
  16. type MonitorResModelSets struct {
  17. Servers Servers
  18. Hosts Hosts
  19. Rds Rds
  20. Redis Redis
  21. Oss Oss
  22. Accounts Accounts
  23. Storages Storages
  24. Domains Domains
  25. Projects Projects
  26. }
  27. func (m *MonitorResModelSets) NewEmpty() apihelper.IModelSets {
  28. return NewModelSets()
  29. }
  30. func (m *MonitorResModelSets) ModelSetList() []apihelper.IModelSet {
  31. return []apihelper.IModelSet{
  32. m.Servers,
  33. m.Hosts,
  34. m.Rds,
  35. m.Redis,
  36. m.Oss,
  37. m.Accounts,
  38. m.Storages,
  39. m.Domains,
  40. m.Projects,
  41. }
  42. }
  43. func (m *MonitorResModelSets) ApplyUpdates(mssNews apihelper.IModelSets) apihelper.ModelSetsUpdateResult {
  44. r := apihelper.ModelSetsUpdateResult{
  45. Changed: false,
  46. Correct: true,
  47. }
  48. mssList := m.ModelSetList()
  49. mssNewsList := mssNews.ModelSetList()
  50. for i, mss := range mssList {
  51. mssNews := mssNewsList[i]
  52. msR := apihelper.ModelSetApplyUpdates(mss, mssNews)
  53. if !r.Changed && msR.Changed {
  54. r.Changed = true
  55. }
  56. }
  57. return r
  58. }
  59. func (m *MonitorResModelSets) Copy() apihelper.IModelSets {
  60. //TODO CHECKE
  61. return m
  62. }
  63. func (m *MonitorResModelSets) CopyJoined() apihelper.IModelSets {
  64. //TODO CHECKE
  65. return m
  66. }
  67. func NewModelSets() *MonitorResModelSets {
  68. return &MonitorResModelSets{
  69. Servers: Servers{},
  70. Hosts: Hosts{},
  71. Rds: Rds{},
  72. Redis: Redis{},
  73. Oss: Oss{},
  74. Accounts: Accounts{},
  75. Storages: Storages{},
  76. Domains: Domains{},
  77. Projects: Projects{},
  78. }
  79. }