wire.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "yunion.io/x/cloudmux/pkg/cloudprovider"
  16. type SWire struct {
  17. SResourceBase
  18. region *SRegion
  19. WireId string
  20. VpcId string
  21. ZoneId string
  22. Bandwidth int
  23. }
  24. func (self *SWire) GetIVpc() cloudprovider.ICloudVpc {
  25. vpcs, err := self.region.client.GetVpcs()
  26. if err != nil {
  27. return nil
  28. }
  29. for i := range vpcs {
  30. if vpcs[i].GetId() == self.VpcId {
  31. vpcs[i].region = self.region
  32. return &vpcs[i]
  33. }
  34. }
  35. return nil
  36. }
  37. func (self *SWire) GetIZone() cloudprovider.ICloudZone {
  38. zones, err := self.region.client.GetZones()
  39. if err != nil {
  40. return nil
  41. }
  42. for i := range zones {
  43. if zones[i].GetId() == self.ZoneId {
  44. zones[i].region = self.region
  45. return &zones[i]
  46. }
  47. }
  48. return nil
  49. }
  50. func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
  51. networks, err := self.region.client.GetNetworks()
  52. if err != nil {
  53. return nil, err
  54. }
  55. ret := []cloudprovider.ICloudNetwork{}
  56. for i := range networks {
  57. if networks[i].WireId != self.GetId() {
  58. continue
  59. }
  60. networks[i].wire = self
  61. ret = append(ret, &networks[i])
  62. }
  63. return ret, nil
  64. }
  65. func (self *SWire) GetBandwidth() int {
  66. return self.Bandwidth
  67. }
  68. func (self *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) {
  69. networks, err := self.GetINetworks()
  70. if err != nil {
  71. return nil, err
  72. }
  73. for i := range networks {
  74. if networks[i].GetGlobalId() == id {
  75. return networks[i], nil
  76. }
  77. }
  78. return nil, cloudprovider.ErrNotFound
  79. }
  80. func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
  81. return nil, cloudprovider.ErrNotSupported
  82. }