wire.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 cucloud
  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. multicloud.STagBase
  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.ZoneCode)
  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. return nil, cloudprovider.ErrNotImplemented
  68. }
  69. func (wire *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) {
  70. return nil, cloudprovider.ErrNotImplemented
  71. }