wire.go 2.5 KB

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