vpc.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 remotefile
  15. import (
  16. "yunion.io/x/pkg/utils"
  17. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. "yunion.io/x/cloudmux/pkg/multicloud"
  19. )
  20. type SVpc struct {
  21. multicloud.SVpc
  22. SResourceBase
  23. region *SRegion
  24. RegionId string
  25. CidrBlock string
  26. IsDefault bool
  27. }
  28. func (self *SVpc) Delete() error {
  29. return cloudprovider.ErrNotSupported
  30. }
  31. func (self *SVpc) GetCidrBlock() string {
  32. return self.CidrBlock
  33. }
  34. func (self *SVpc) GetIRouteTableById(id string) (cloudprovider.ICloudRouteTable, error) {
  35. return nil, cloudprovider.ErrNotSupported
  36. }
  37. func (self *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
  38. return nil, cloudprovider.ErrNotSupported
  39. }
  40. func (self *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
  41. wires, err := self.region.client.GetWires()
  42. if err != nil {
  43. return nil, err
  44. }
  45. zones, err := self.region.client.GetZones()
  46. if err != nil {
  47. return nil, err
  48. }
  49. zoneIds := []string{}
  50. for i := range zones {
  51. zoneIds = append(zoneIds, zones[i].Id)
  52. }
  53. ret := []cloudprovider.ICloudWire{}
  54. for i := range wires {
  55. if wires[i].VpcId != self.GetId() || !utils.IsInStringArray(wires[i].ZoneId, zoneIds) {
  56. continue
  57. }
  58. wires[i].region = self.region
  59. ret = append(ret, &wires[i])
  60. }
  61. return ret, nil
  62. }
  63. func (self *SVpc) CreateIWire(opts *cloudprovider.SWireCreateOptions) (cloudprovider.ICloudWire, error) {
  64. return nil, cloudprovider.ErrNotSupported
  65. }
  66. func (self *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
  67. secgroups, err := self.region.client.GetSecgroups()
  68. if err != nil {
  69. return nil, err
  70. }
  71. ret := []cloudprovider.ICloudSecurityGroup{}
  72. for i := range secgroups {
  73. if secgroups[i].VpcId != self.GetId() {
  74. continue
  75. }
  76. ret = append(ret, &secgroups[i])
  77. }
  78. return nil, cloudprovider.ErrNotFound
  79. }
  80. func (self *SVpc) GetIWireById(id string) (cloudprovider.ICloudWire, error) {
  81. wires, err := self.GetIWires()
  82. if err != nil {
  83. return nil, err
  84. }
  85. for i := range wires {
  86. if wires[i].GetGlobalId() == id {
  87. return wires[i], nil
  88. }
  89. }
  90. return nil, cloudprovider.ErrNotFound
  91. }
  92. func (self *SVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
  93. return nil, cloudprovider.ErrNotSupported
  94. }
  95. func (self *SVpc) CreateINatGateway(opts *cloudprovider.NatGatewayCreateOptions) (cloudprovider.ICloudNatGateway, error) {
  96. return nil, cloudprovider.ErrNotSupported
  97. }
  98. func (self *SVpc) GetICloudVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
  99. return nil, cloudprovider.ErrNotSupported
  100. }
  101. func (self *SVpc) GetICloudAccepterVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
  102. return nil, cloudprovider.ErrNotSupported
  103. }
  104. func (self *SVpc) GetICloudVpcPeeringConnectionById(id string) (cloudprovider.ICloudVpcPeeringConnection, error) {
  105. return nil, cloudprovider.ErrNotSupported
  106. }
  107. func (self *SVpc) CreateICloudVpcPeeringConnection(opts *cloudprovider.VpcPeeringConnectionCreateOptions) (cloudprovider.ICloudVpcPeeringConnection, error) {
  108. return nil, cloudprovider.ErrNotSupported
  109. }
  110. func (self *SVpc) AcceptICloudVpcPeeringConnection(id string) error {
  111. return cloudprovider.ErrNotSupported
  112. }
  113. func (self *SVpc) GetAuthorityOwnerId() string {
  114. return ""
  115. }
  116. func (self *SVpc) ProposeJoinICloudInterVpcNetwork(opts *cloudprovider.SVpcJointInterVpcNetworkOption) error {
  117. return cloudprovider.ErrNotSupported
  118. }
  119. func (self *SVpc) GetICloudIPv6Gateways() ([]cloudprovider.ICloudIPv6Gateway, error) {
  120. return nil, cloudprovider.ErrNotSupported
  121. }
  122. func (self *SVpc) GetIsDefault() bool {
  123. return self.IsDefault
  124. }
  125. func (self *SVpc) GetRegion() cloudprovider.ICloudRegion {
  126. return self.region
  127. }