wire.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 bingocloud
  15. import (
  16. "fmt"
  17. "yunion.io/x/pkg/errors"
  18. api "yunion.io/x/cloudmux/pkg/apis/compute"
  19. "yunion.io/x/cloudmux/pkg/cloudprovider"
  20. "yunion.io/x/cloudmux/pkg/multicloud"
  21. )
  22. type SWire struct {
  23. multicloud.STagBase
  24. multicloud.SResourceBase
  25. cluster *SCluster
  26. vpc *SVpc
  27. }
  28. func (self *SWire) GetId() string {
  29. return fmt.Sprintf("%s/%s", self.vpc.GetGlobalId(), self.cluster.GetGlobalId())
  30. }
  31. func (self *SWire) GetGlobalId() string {
  32. return self.GetId()
  33. }
  34. func (self *SWire) GetName() string {
  35. return fmt.Sprintf("%s-%s", self.vpc.GetName(), self.cluster.GetName())
  36. }
  37. func (self *SWire) GetBandwidth() int {
  38. return 1000
  39. }
  40. func (self *SWire) GetStatus() string {
  41. return api.WIRE_STATUS_AVAILABLE
  42. }
  43. func (self *SWire) GetIVpc() cloudprovider.ICloudVpc {
  44. return self.vpc
  45. }
  46. func (self *SWire) IsEmulated() bool {
  47. return true
  48. }
  49. func (self *SWire) GetIZone() cloudprovider.ICloudZone {
  50. return self.cluster
  51. }
  52. func (self *SVpc) GetIWireById(id string) (cloudprovider.ICloudWire, error) {
  53. wires, err := self.GetIWires()
  54. if err != nil {
  55. return nil, err
  56. }
  57. for i := range wires {
  58. if wires[i].GetGlobalId() == id {
  59. return wires[i], nil
  60. }
  61. }
  62. return nil, errors.Wrapf(cloudprovider.ErrNotFound, "%s", id)
  63. }
  64. func (self *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
  65. clusters, err := self.region.GetClusters()
  66. if err != nil {
  67. return nil, err
  68. }
  69. var ret []cloudprovider.ICloudWire
  70. for i := range clusters {
  71. wire := &SWire{
  72. vpc: self,
  73. cluster: &clusters[i],
  74. }
  75. ret = append(ret, wire)
  76. }
  77. return ret, nil
  78. }