vpc.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 zstack
  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 SVpc struct {
  22. multicloud.SVpc
  23. ZStackTags
  24. region *SRegion
  25. iwires []cloudprovider.ICloudWire
  26. }
  27. func (vpc *SVpc) GetId() string {
  28. return fmt.Sprintf("%s/vpc", vpc.region.GetGlobalId())
  29. }
  30. func (vpc *SVpc) GetName() string {
  31. return fmt.Sprintf("%s-VPC", vpc.region.client.cpcfg.Name)
  32. }
  33. func (vpc *SVpc) GetGlobalId() string {
  34. return vpc.GetId()
  35. }
  36. func (vpc *SVpc) IsEmulated() bool {
  37. return true
  38. }
  39. func (vpc *SVpc) GetIsDefault() bool {
  40. return true
  41. }
  42. func (vpc *SVpc) GetCidrBlock() string {
  43. return ""
  44. }
  45. func (vpc *SVpc) GetStatus() string {
  46. return api.VPC_STATUS_AVAILABLE
  47. }
  48. func (vpc *SVpc) Refresh() error {
  49. return nil
  50. }
  51. func (vpc *SVpc) GetRegion() cloudprovider.ICloudRegion {
  52. return vpc.region
  53. }
  54. func (vpc *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) {
  55. if vpc.iwires == nil || len(vpc.iwires) == 0 {
  56. vpc.iwires = []cloudprovider.ICloudWire{}
  57. wires, err := vpc.region.GetWires("", "", "")
  58. if err != nil {
  59. return nil, err
  60. }
  61. for i := 0; i < len(wires); i++ {
  62. wires[i].vpc = vpc
  63. vpc.iwires = append(vpc.iwires, &wires[i])
  64. }
  65. }
  66. return vpc.iwires, nil
  67. }
  68. func (vpc *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) {
  69. wire, err := vpc.region.GetWire(wireId)
  70. if err != nil {
  71. return nil, err
  72. }
  73. wire.vpc = vpc
  74. return wire, nil
  75. }
  76. func (vpc *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
  77. return []cloudprovider.ICloudSecurityGroup{}, nil
  78. }
  79. func (vpc *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
  80. return nil, cloudprovider.ErrNotSupported
  81. }
  82. func (self *SVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudRouteTable, error) {
  83. return nil, cloudprovider.ErrNotSupported
  84. }
  85. func (vpc *SVpc) Delete() error {
  86. return nil
  87. }