fakevpc.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 esxi
  15. import (
  16. "time"
  17. "yunion.io/x/pkg/errors"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  19. )
  20. type sFakeVpc struct {
  21. client *SESXiClient
  22. }
  23. func (vpc *sFakeVpc) GetId() string {
  24. return vpc.client.GetId()
  25. }
  26. func (vpc *sFakeVpc) GetName() string {
  27. return vpc.client.GetName()
  28. }
  29. func (vpc *sFakeVpc) GetGlobalId() string {
  30. return vpc.client.GetGlobalId()
  31. }
  32. func (vpc *sFakeVpc) GetCreatedAt() time.Time {
  33. return time.Time{}
  34. }
  35. func (vpc *sFakeVpc) GetDescription() string {
  36. return "fake vpc for esxi"
  37. }
  38. func (vpc *sFakeVpc) GetStatus() string {
  39. return "'"
  40. }
  41. func (vpc *sFakeVpc) Refresh() error {
  42. return nil
  43. }
  44. func (vpc *sFakeVpc) IsEmulated() bool {
  45. return true
  46. }
  47. func (vpc *sFakeVpc) GetSysTags() map[string]string {
  48. return nil
  49. }
  50. func (vpc *sFakeVpc) GetTags() (map[string]string, error) {
  51. return nil, nil
  52. }
  53. func (vpc *sFakeVpc) SetTags(tags map[string]string, replace bool) error {
  54. return errors.ErrNotSupported
  55. }
  56. func (vpc *sFakeVpc) GetGlobalVpcId() string {
  57. return ""
  58. }
  59. func (vpc *sFakeVpc) IsSupportSetExternalAccess() bool {
  60. return false
  61. }
  62. func (vpc *sFakeVpc) GetExternalAccessMode() string {
  63. return ""
  64. }
  65. func (vpc *sFakeVpc) AttachInternetGateway(igwId string) error {
  66. return errors.ErrNotSupported
  67. }
  68. func (vpc *sFakeVpc) GetRegion() cloudprovider.ICloudRegion {
  69. return vpc.client
  70. }
  71. func (vpc *sFakeVpc) GetIsDefault() bool {
  72. return true
  73. }
  74. func (vpc *sFakeVpc) GetCidrBlock() string {
  75. return ""
  76. }
  77. func (vpc *sFakeVpc) GetCidrBlock6() string {
  78. return ""
  79. }
  80. func (vpc *sFakeVpc) CreateIWire(opts *cloudprovider.SWireCreateOptions) (cloudprovider.ICloudWire, error) {
  81. return nil, errors.ErrNotSupported
  82. }
  83. func (vpc *sFakeVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
  84. return nil, errors.ErrNotSupported
  85. }
  86. func (vpc *sFakeVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
  87. return nil, errors.ErrNotSupported
  88. }
  89. func (vpc *sFakeVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudRouteTable, error) {
  90. return nil, errors.ErrNotSupported
  91. }
  92. func (vpc *sFakeVpc) Delete() error {
  93. return errors.ErrNotSupported
  94. }
  95. func (vpc *sFakeVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) {
  96. wires, err := vpc.GetIWires()
  97. if err != nil {
  98. return nil, errors.Wrap(err, "GetIWires")
  99. }
  100. for i := range wires {
  101. if wires[i].GetGlobalId() == wireId {
  102. return wires[i], nil
  103. }
  104. }
  105. return nil, errors.ErrNotFound
  106. }
  107. func (vpc *sFakeVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
  108. return nil, errors.ErrNotSupported
  109. }
  110. func (vpc *sFakeVpc) CreateINatGateway(opts *cloudprovider.NatGatewayCreateOptions) (cloudprovider.ICloudNatGateway, error) {
  111. return nil, errors.ErrNotSupported
  112. }
  113. func (vpc *sFakeVpc) GetICloudVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
  114. return nil, errors.ErrNotSupported
  115. }
  116. func (vpc *sFakeVpc) GetICloudAccepterVpcPeeringConnections() ([]cloudprovider.ICloudVpcPeeringConnection, error) {
  117. return nil, errors.ErrNotSupported
  118. }
  119. func (vpc *sFakeVpc) GetICloudVpcPeeringConnectionById(id string) (cloudprovider.ICloudVpcPeeringConnection, error) {
  120. return nil, errors.ErrNotSupported
  121. }
  122. func (vpc *sFakeVpc) CreateICloudVpcPeeringConnection(opts *cloudprovider.VpcPeeringConnectionCreateOptions) (cloudprovider.ICloudVpcPeeringConnection, error) {
  123. return nil, errors.ErrNotSupported
  124. }
  125. func (vpc *sFakeVpc) AcceptICloudVpcPeeringConnection(id string) error {
  126. return errors.ErrNotSupported
  127. }
  128. func (vpc *sFakeVpc) GetAuthorityOwnerId() string {
  129. return ""
  130. }
  131. func (vpc *sFakeVpc) ProposeJoinICloudInterVpcNetwork(opts *cloudprovider.SVpcJointInterVpcNetworkOption) error {
  132. return errors.ErrNotSupported
  133. }
  134. func (vpc *sFakeVpc) GetICloudIPv6Gateways() ([]cloudprovider.ICloudIPv6Gateway, error) {
  135. return nil, errors.ErrNotSupported
  136. }
  137. func (vpc *sFakeVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
  138. nets, err := vpc.client.GetNetworks()
  139. if err != nil {
  140. return nil, errors.Wrap(err, "client.GetNetworks")
  141. }
  142. wires := make([]cloudprovider.ICloudWire, len(nets))
  143. for i := range nets {
  144. wires[i] = &sWire{
  145. network: nets[i],
  146. client: vpc.client,
  147. }
  148. }
  149. return wires, nil
  150. }