wire.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 baidu
  15. import (
  16. "fmt"
  17. api "yunion.io/x/cloudmux/pkg/apis/compute"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  19. "yunion.io/x/cloudmux/pkg/multicloud"
  20. )
  21. type SWire struct {
  22. multicloud.SResourceBase
  23. SBaiduTag
  24. zone *SZone
  25. vpc *SVpc
  26. }
  27. func (wire *SWire) GetId() string {
  28. return fmt.Sprintf("%s-%s", wire.vpc.GetId(), wire.zone.GetId())
  29. }
  30. func (wire *SWire) GetName() string {
  31. return wire.GetId()
  32. }
  33. func (wire *SWire) IsEmulated() bool {
  34. return true
  35. }
  36. func (wire *SWire) GetStatus() string {
  37. return api.WIRE_STATUS_AVAILABLE
  38. }
  39. func (wire *SWire) Refresh() error {
  40. return nil
  41. }
  42. func (wire *SWire) GetGlobalId() string {
  43. return fmt.Sprintf("%s-%s", wire.vpc.GetGlobalId(), wire.zone.GetGlobalId())
  44. }
  45. func (wire *SWire) GetIVpc() cloudprovider.ICloudVpc {
  46. return wire.vpc
  47. }
  48. func (wire *SWire) GetIZone() cloudprovider.ICloudZone {
  49. return wire.zone
  50. }
  51. func (wire *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
  52. networks, err := wire.vpc.region.GetNetworks(wire.vpc.VpcId, wire.zone.ZoneName)
  53. if err != nil {
  54. return nil, err
  55. }
  56. ret := []cloudprovider.ICloudNetwork{}
  57. for i := range networks {
  58. networks[i].wire = wire
  59. ret = append(ret, &networks[i])
  60. }
  61. return ret, nil
  62. }
  63. func (wire *SWire) GetBandwidth() int {
  64. return 10000
  65. }
  66. func (wire *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
  67. net, err := wire.vpc.region.CreateNetwork(wire.zone.ZoneName, wire.vpc.VpcId, opts)
  68. if err != nil {
  69. return nil, err
  70. }
  71. net.wire = wire
  72. return net, nil
  73. }
  74. func (wire *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) {
  75. net, err := wire.vpc.region.GetNetwork(id)
  76. if err != nil {
  77. return nil, err
  78. }
  79. net.wire = wire
  80. return net, nil
  81. }