region.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 qingcloud
  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/jsonutils"
  21. )
  22. var regions = map[string]string{
  23. "pek3": "北京3区",
  24. "sh1": "上海1区",
  25. "gd2": "广东2区",
  26. "ap2": "亚太二区",
  27. }
  28. type SRegion struct {
  29. multicloud.SRegion
  30. multicloud.SNoObjectStorageRegion
  31. multicloud.SNoLbRegion
  32. client *SQingCloudClient
  33. Region string
  34. RegionName string
  35. }
  36. func (self *SRegion) GetId() string {
  37. return self.Region
  38. }
  39. func (self *SRegion) GetGlobalId() string {
  40. return fmt.Sprintf("%s/%s", api.CLOUD_PROVIDER_QINGCLOUD, self.Region)
  41. }
  42. func (self *SRegion) GetProvider() string {
  43. return api.CLOUD_PROVIDER_QINGCLOUD
  44. }
  45. func (self *SRegion) GetCloudEnv() string {
  46. return api.CLOUD_PROVIDER_QINGCLOUD
  47. }
  48. func (self *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo {
  49. geo, ok := map[string]cloudprovider.SGeographicInfo{
  50. "pek3": api.RegionBeijing,
  51. "sh1": api.RegionShanghai,
  52. "gd2": api.RegionGuangzhou,
  53. "ap2": api.RegionSingapore,
  54. }[self.Region]
  55. if ok {
  56. return geo
  57. }
  58. return cloudprovider.SGeographicInfo{}
  59. }
  60. func (self *SRegion) GetName() string {
  61. return self.RegionName
  62. }
  63. func (self *SRegion) GetI18n() cloudprovider.SModelI18nTable {
  64. table := cloudprovider.SModelI18nTable{}
  65. table["name"] = cloudprovider.NewSModelI18nEntry(self.GetName()).CN(self.GetName()).EN(self.Region)
  66. return table
  67. }
  68. func (self *SRegion) GetStatus() string {
  69. return api.CLOUD_REGION_STATUS_INSERVER
  70. }
  71. func (self *SRegion) GetClient() *SQingCloudClient {
  72. return self.client
  73. }
  74. func (self *SRegion) CreateEIP(opts *cloudprovider.SEip) (cloudprovider.ICloudEIP, error) {
  75. return nil, cloudprovider.ErrNotImplemented
  76. }
  77. func (region *SRegion) CreateISecurityGroup(conf *cloudprovider.SecurityGroupCreateInput) (cloudprovider.ICloudSecurityGroup, error) {
  78. return nil, cloudprovider.ErrNotImplemented
  79. }
  80. func (region *SRegion) GetISecurityGroupById(secgroupId string) (cloudprovider.ICloudSecurityGroup, error) {
  81. return nil, cloudprovider.ErrNotImplemented
  82. }
  83. func (self *SRegion) CreateIVpc(opts *cloudprovider.VpcCreateOptions) (cloudprovider.ICloudVpc, error) {
  84. return nil, cloudprovider.ErrNotImplemented
  85. }
  86. func (self *SRegion) GetIVpcs() ([]cloudprovider.ICloudVpc, error) {
  87. return nil, cloudprovider.ErrNotImplemented
  88. }
  89. func (self *SRegion) GetIVpcById(id string) (cloudprovider.ICloudVpc, error) {
  90. return nil, cloudprovider.ErrNotImplemented
  91. }
  92. func (region *SRegion) GetCapabilities() []string {
  93. return region.client.GetCapabilities()
  94. }
  95. func (self *SRegion) GetIEipById(eipId string) (cloudprovider.ICloudEIP, error) {
  96. return nil, cloudprovider.ErrNotImplemented
  97. }
  98. func (self *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) {
  99. return nil, cloudprovider.ErrNotImplemented
  100. }
  101. func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
  102. return nil, cloudprovider.ErrNotImplemented
  103. }
  104. func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
  105. return nil, cloudprovider.ErrNotImplemented
  106. }
  107. func (self *SRegion) ec2Request(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
  108. return self.client.ec2Request(apiName, self.Region, params)
  109. }