modelset.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 (
  16. "yunion.io/x/log"
  17. "yunion.io/x/onecloud/pkg/apihelper"
  18. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  19. mcclient_modulebase "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  20. mcclient_modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy"
  21. )
  22. type (
  23. ProxyEndpoints map[string]*ProxyEndpoint
  24. Forwards map[string]*Forward
  25. )
  26. func (set ProxyEndpoints) ModelManager() mcclient_modulebase.IBaseManager {
  27. return &mcclient_modules.ProxyEndpoints
  28. }
  29. func (set ProxyEndpoints) NewModel() db.IModel {
  30. return &ProxyEndpoint{}
  31. }
  32. func (set ProxyEndpoints) AddModel(i db.IModel) {
  33. m := i.(*ProxyEndpoint)
  34. set[m.Id] = m
  35. }
  36. func (set ProxyEndpoints) Copy() apihelper.IModelSet {
  37. setCopy := ProxyEndpoints{}
  38. for id, el := range set {
  39. setCopy[id] = el.Copy()
  40. }
  41. return setCopy
  42. }
  43. func (ms ProxyEndpoints) joinForwards(subEntries Forwards) bool {
  44. correct := true
  45. for _, subEntry := range subEntries {
  46. epId := subEntry.ProxyEndpointId
  47. m, ok := ms[epId]
  48. if !ok {
  49. log.Warningf("proxy_endpoint_id %s of forward %s(%s) is not present", epId, subEntry.Name, subEntry.Id)
  50. correct = false
  51. continue
  52. }
  53. subEntry.ProxyEndpoint = m
  54. if m.Forwards == nil {
  55. m.Forwards = Forwards{}
  56. }
  57. m.Forwards[subEntry.Id] = subEntry
  58. }
  59. return correct
  60. }
  61. func (set Forwards) ModelManager() mcclient_modulebase.IBaseManager {
  62. return &mcclient_modules.Forwards
  63. }
  64. func (set Forwards) NewModel() db.IModel {
  65. return &Forward{}
  66. }
  67. func (set Forwards) AddModel(i db.IModel) {
  68. m := i.(*Forward)
  69. set[m.Id] = m
  70. }
  71. func (set Forwards) Copy() apihelper.IModelSet {
  72. setCopy := Forwards{}
  73. for id, el := range set {
  74. setCopy[id] = el.Copy()
  75. }
  76. return setCopy
  77. }