yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/dbinstance_database.go (about) 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 15 package azure 16 17 import ( 18 "fmt" 19 "net/url" 20 "strings" 21 22 "yunion.io/x/jsonutils" 23 "yunion.io/x/pkg/errors" 24 25 api "yunion.io/x/cloudmux/pkg/apis/compute" 26 "yunion.io/x/cloudmux/pkg/multicloud" 27 ) 28 29 type SDBInstanceDatabase struct { 30 region *SRegion 31 multicloud.SDBInstanceDatabaseBase 32 AzureTags 33 ID string `json:"id"` 34 Name string `json:"name"` 35 Type string `json:"type"` 36 Properties SDBInstanceDatabaseProperties `json:"properties"` 37 } 38 39 type SDBInstanceDatabaseProperties struct { 40 Charset string `json:"charset"` 41 Collation string `json:"collation"` 42 } 43 44 func (self *SRegion) ListSDBInstanceDatabase(Id string) ([]SDBInstanceDatabase, error) { 45 type databases struct { 46 Value []SDBInstanceDatabase 47 } 48 49 result := databases{} 50 err := self.get(fmt.Sprintf("%s/databases", Id), url.Values{}, &result) 51 if err != nil { 52 return nil, errors.Wrapf(err, "get(%s/databases)", Id) 53 } 54 return result.Value, nil 55 } 56 57 func (database *SDBInstanceDatabase) GetCharacterSet() string { 58 return database.Properties.Charset 59 } 60 61 func (database *SDBInstanceDatabase) GetName() string { 62 return database.Name 63 } 64 65 func (database *SDBInstanceDatabase) GetGlobalId() string { 66 return strings.ToLower(database.ID) 67 } 68 69 func (database *SDBInstanceDatabase) GetId() string { 70 return strings.ToLower(database.ID) 71 } 72 73 func (database *SDBInstanceDatabase) IsEmulated() bool { 74 return false 75 } 76 77 func (database *SDBInstanceDatabase) Refresh() error { 78 newdb := SDBInstanceDatabase{} 79 err := database.region.get(database.ID, url.Values{}, &newdb) 80 if err != nil { 81 return errors.Wrapf(err, "database.region.get(%s, url.Values{}, &newdb)", database.ID) 82 } 83 84 return jsonutils.Update(database, newdb) 85 } 86 87 func (database *SDBInstanceDatabase) GetStatus() string { 88 return api.DBINSTANCE_DATABASE_RUNNING 89 }