wire.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 google
  15. import (
  16. "fmt"
  17. "time"
  18. "yunion.io/x/pkg/errors"
  19. api "yunion.io/x/cloudmux/pkg/apis/compute"
  20. "yunion.io/x/cloudmux/pkg/cloudprovider"
  21. "yunion.io/x/cloudmux/pkg/multicloud"
  22. )
  23. type SWire struct {
  24. multicloud.SResourceBase
  25. GoogleTags
  26. vpc *SVpc
  27. shareVpc *SXpnNetwork
  28. }
  29. func (wire *SWire) GetId() string {
  30. if wire.vpc != nil {
  31. return wire.vpc.GetGlobalId()
  32. }
  33. return wire.shareVpc.GetGlobalId()
  34. }
  35. func (wire *SWire) GetGlobalId() string {
  36. name := ""
  37. if wire.vpc != nil {
  38. name = wire.vpc.region.Name
  39. } else {
  40. name = wire.shareVpc.region.Name
  41. }
  42. return fmt.Sprintf("%s-%s", wire.GetId(), name)
  43. }
  44. func (wire *SWire) GetName() string {
  45. if wire.vpc != nil {
  46. return wire.vpc.GetName()
  47. }
  48. return wire.shareVpc.GetName()
  49. }
  50. func (wire *SWire) GetCreatedAt() time.Time {
  51. return time.Time{}
  52. }
  53. func (wire *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
  54. return nil, cloudprovider.ErrNotSupported
  55. }
  56. func (wire *SWire) GetIVpc() cloudprovider.ICloudVpc {
  57. if wire.vpc != nil {
  58. return wire.vpc
  59. }
  60. return wire.shareVpc
  61. }
  62. func (wire *SWire) GetIZone() cloudprovider.ICloudZone {
  63. return nil
  64. }
  65. func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
  66. network := SNetwork{wire: self}
  67. return []cloudprovider.ICloudNetwork{&network}, nil
  68. }
  69. func (self *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) {
  70. networks, err := self.GetINetworks()
  71. if err != nil {
  72. return nil, errors.Wrapf(err, "GetINetwork")
  73. }
  74. for i := range networks {
  75. if networks[i].GetGlobalId() == id {
  76. return networks[i], nil
  77. }
  78. }
  79. return nil, errors.Wrapf(cloudprovider.ErrNotFound, "%s", id)
  80. }
  81. func (wire *SWire) GetBandwidth() int {
  82. return 0
  83. }
  84. func (wire *SWire) GetStatus() string {
  85. return api.WIRE_STATUS_AVAILABLE
  86. }
  87. func (wire *SWire) IsEmulated() bool {
  88. return true
  89. }
  90. func (wire *SWire) Refresh() error {
  91. return nil
  92. }