vpc.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. "yunion.io/x/pkg/errors"
  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. multicloud.STagBase
  24. region *SRegion
  25. RequestId string `json:"requestId"`
  26. VlanNum string `json:"vlanNum"`
  27. AsGateway string `json:"asGateway"`
  28. DhcpOptionsId string `json:"dhcpOptionsId"`
  29. VpcName string `json:"vpcName"`
  30. OwnerId string `json:"ownerId"`
  31. WanCode string `json:"wanCode"`
  32. Shared string `json:"shared"`
  33. SubnetPolicy string `json:"subnetPolicy"`
  34. Description string `json:"description"`
  35. VpcId string `json:"vpcId"`
  36. IsPublicNetwork string `json:"isPublicNetwork"`
  37. GatewayId string `json:"gatewayId"`
  38. IsDefault string `json:"isDefault"`
  39. Provider string `json:"provider"`
  40. State string `json:"state"`
  41. CidrBlock string `json:"cidrBlock"`
  42. InstanceTenancy string `json:"instanceTenancy"`
  43. }
  44. func (self *SVpc) GetId() string {
  45. return self.VpcId
  46. }
  47. func (self *SVpc) GetGlobalId() string {
  48. return self.VpcId
  49. }
  50. func (self *SVpc) GetName() string {
  51. return self.VpcName
  52. }
  53. func (self *SVpc) Delete() error {
  54. return cloudprovider.ErrNotImplemented
  55. }
  56. func (self *SVpc) GetCidrBlock() string {
  57. return self.CidrBlock
  58. }
  59. func (self *SVpc) GetIRouteTableById(id string) (cloudprovider.ICloudRouteTable, error) {
  60. return nil, cloudprovider.ErrNotImplemented
  61. }
  62. func (self *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
  63. return nil, cloudprovider.ErrNotImplemented
  64. }
  65. func (self *SVpc) GetIsDefault() bool {
  66. return self.IsDefault == "true"
  67. }
  68. func (self *SVpc) GetRegion() cloudprovider.ICloudRegion {
  69. return self.region
  70. }
  71. func (self *SVpc) GetStatus() string {
  72. switch self.State {
  73. case "available":
  74. return api.VPC_STATUS_AVAILABLE
  75. default:
  76. return self.State
  77. }
  78. }
  79. func (self *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
  80. return []cloudprovider.ICloudSecurityGroup{}, nil
  81. }
  82. func (self *SRegion) GetVpcs(id string) ([]SVpc, error) {
  83. params := map[string]string{}
  84. if len(id) > 0 {
  85. params["VpcId"] = id
  86. }
  87. resp, err := self.invoke("DescribeVpcs", params)
  88. if err != nil {
  89. return nil, err
  90. }
  91. var vpcs []SVpc
  92. return vpcs, resp.Unmarshal(&vpcs, "vpcSet")
  93. }
  94. func (self *SRegion) GetIVpcs() ([]cloudprovider.ICloudVpc, error) {
  95. vpcs, err := self.GetVpcs("")
  96. if err != nil {
  97. return nil, errors.Wrapf(err, "GetVpcs")
  98. }
  99. var ret []cloudprovider.ICloudVpc
  100. for i := range vpcs {
  101. vpcs[i].region = self
  102. ret = append(ret, &vpcs[i])
  103. }
  104. return ret, nil
  105. }