routetable.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 openstack
  15. import (
  16. api "yunion.io/x/cloudmux/pkg/apis/compute"
  17. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. "yunion.io/x/cloudmux/pkg/multicloud"
  19. )
  20. type SRouteEntry struct {
  21. multicloud.SResourceBase
  22. OpenStackTags
  23. Destination string `json:"destination"`
  24. Nexthop string `json:"nexthop"`
  25. }
  26. func (route *SRouteEntry) GetId() string {
  27. return route.Destination + ":" + route.Nexthop
  28. }
  29. func (route *SRouteEntry) GetName() string {
  30. return ""
  31. }
  32. func (route *SRouteEntry) GetGlobalId() string {
  33. return route.GetId()
  34. }
  35. func (route *SRouteEntry) GetStatus() string {
  36. return ""
  37. }
  38. func (route *SRouteEntry) Refresh() error {
  39. return nil
  40. }
  41. func (route *SRouteEntry) IsEmulated() bool {
  42. return false
  43. }
  44. func (route *SRouteEntry) GetType() string {
  45. return api.ROUTE_ENTRY_TYPE_CUSTOM
  46. }
  47. func (route *SRouteEntry) GetCidr() string {
  48. return route.Destination
  49. }
  50. func (route *SRouteEntry) GetNextHopType() string {
  51. return route.Nexthop
  52. }
  53. func (route *SRouteEntry) GetNextHop() string {
  54. return route.Nexthop
  55. }
  56. type SRouteTable struct {
  57. multicloud.SResourceBase
  58. OpenStackTags
  59. vpc *SVpc
  60. entries []SRouteEntry
  61. router *SRouter
  62. }
  63. func (self *SRouteTable) GetDescription() string {
  64. return ""
  65. }
  66. func (self *SRouteTable) GetId() string {
  67. return self.GetGlobalId()
  68. }
  69. func (self *SRouteTable) GetGlobalId() string {
  70. return self.router.Id
  71. }
  72. func (self *SRouteTable) GetName() string {
  73. return self.router.Name
  74. }
  75. func (self *SRouteTable) GetRegionId() string {
  76. return self.vpc.region.GetId()
  77. }
  78. func (self *SRouteTable) GetType() cloudprovider.RouteTableType {
  79. return cloudprovider.RouteTableTypeSystem
  80. }
  81. func (self *SRouteTable) GetVpcId() string {
  82. return self.vpc.GetId()
  83. }
  84. func (self *SRouteTable) GetIRoutes() ([]cloudprovider.ICloudRoute, error) {
  85. ret := []cloudprovider.ICloudRoute{}
  86. for index := range self.entries {
  87. ret = append(ret, &self.entries[index])
  88. }
  89. return ret, nil
  90. }
  91. func (self *SRouteTable) GetStatus() string {
  92. return self.router.Status
  93. }
  94. func (self *SRouteTable) IsEmulated() bool {
  95. return false
  96. }
  97. func (self *SRouteTable) Refresh() error {
  98. return nil
  99. }
  100. func (self *SRouteTable) GetAssociations() []cloudprovider.RouteTableAssociation {
  101. result := []cloudprovider.RouteTableAssociation{}
  102. return result
  103. }
  104. func (self *SRouteTable) CreateRoute(route cloudprovider.RouteSet) error {
  105. return cloudprovider.ErrNotSupported
  106. }
  107. func (self *SRouteTable) UpdateRoute(route cloudprovider.RouteSet) error {
  108. return cloudprovider.ErrNotSupported
  109. }
  110. func (self *SRouteTable) RemoveRoute(route cloudprovider.RouteSet) error {
  111. return cloudprovider.ErrNotSupported
  112. }