region.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 oceanbase
  15. import (
  16. "fmt"
  17. "net/url"
  18. api "yunion.io/x/cloudmux/pkg/apis/compute"
  19. "yunion.io/x/cloudmux/pkg/cloudprovider"
  20. "yunion.io/x/cloudmux/pkg/multicloud"
  21. "yunion.io/x/jsonutils"
  22. )
  23. type SRegion struct {
  24. multicloud.SRegion
  25. multicloud.SNoObjectStorageRegion
  26. multicloud.SNoLbRegion
  27. multicloud.SNoEipRegion
  28. multicloud.SNoSecurityGroupRegion
  29. multicloud.SNoVpcRegion
  30. multicloud.SRegionZoneBase
  31. client *SOceanBaseClient
  32. }
  33. func (region *SRegion) GetId() string {
  34. return fmt.Sprintf("%s/Default", api.CLOUD_PROVIDER_OCEANBASE)
  35. }
  36. func (region *SRegion) GetName() string {
  37. return OB_DEFAULT_REGION_NAME
  38. }
  39. func (region *SRegion) GetGlobalId() string {
  40. return region.GetId()
  41. }
  42. func (region *SRegion) GetProvider() string {
  43. return api.CLOUD_PROVIDER_OCEANBASE
  44. }
  45. func (region *SRegion) GetClient() *SOceanBaseClient {
  46. return region.client
  47. }
  48. func (region *SRegion) GetStatus() string {
  49. return api.CLOUD_REGION_STATUS_INSERVER
  50. }
  51. func (region *SRegion) list(resource string, params url.Values) (jsonutils.JSONObject, error) {
  52. return region.client.list(resource, params)
  53. }
  54. func (region *SRegion) delete(resource string, body map[string]interface{}) (jsonutils.JSONObject, error) {
  55. return region.client.delete(resource, body)
  56. }
  57. func (region *SRegion) put(resource string, body map[string]interface{}) (jsonutils.JSONObject, error) {
  58. return region.client.put(resource, body)
  59. }
  60. func (region *SRegion) GetCloudEnv() string {
  61. return api.CLOUD_PROVIDER_OCEANBASE
  62. }
  63. func (region *SRegion) GetI18n() cloudprovider.SModelI18nTable {
  64. table := cloudprovider.SModelI18nTable{}
  65. return table
  66. }
  67. func (region *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo {
  68. return cloudprovider.SGeographicInfo{}
  69. }
  70. func (region *SRegion) GetCapabilities() []string {
  71. return region.client.GetCapabilities()
  72. }
  73. func (region *SRegion) GetIDBInstances() ([]cloudprovider.ICloudDBInstance, error) {
  74. dbinstances, err := region.GetDBInstances()
  75. if err != nil {
  76. return nil, err
  77. }
  78. ret := []cloudprovider.ICloudDBInstance{}
  79. for i := range dbinstances {
  80. dbinstances[i].region = region
  81. ret = append(ret, &dbinstances[i])
  82. }
  83. return ret, nil
  84. }
  85. func (region *SRegion) GetIDBInstanceById(id string) (cloudprovider.ICloudDBInstance, error) {
  86. ret, err := region.GetDBInstance(id)
  87. if err != nil {
  88. return nil, err
  89. }
  90. return ret, nil
  91. }