yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/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 google 16 17 import ( 18 "fmt" 19 20 "yunion.io/x/jsonutils" 21 "yunion.io/x/pkg/errors" 22 23 api "yunion.io/x/cloudmux/pkg/apis/compute" 24 "yunion.io/x/cloudmux/pkg/multicloud" 25 ) 26 27 type SSqlserverDatabaseDetails struct { 28 CompatibilityLevel int 29 RecoveryModel string 30 } 31 32 type SDBInstanceDatabase struct { 33 multicloud.SResourceBase 34 GoogleTags 35 rds *SDBInstance 36 Kind string 37 Collation string 38 Etag string 39 Name string 40 Instance string 41 SelfLink string 42 Charset string 43 Project string 44 SqlserverDatabaseDetails SSqlserverDatabaseDetails 45 } 46 47 func (region *SRegion) GetDBInstanceDatabases(instance string) ([]SDBInstanceDatabase, error) { 48 databases := []SDBInstanceDatabase{} 49 params := map[string]string{} 50 resource := fmt.Sprintf("instances/%s/databases", instance) 51 err := region.RdsListAll(resource, params, &databases) 52 if err != nil { 53 return nil, errors.Wrap(err, "RdsListAll") 54 } 55 return databases, nil 56 } 57 58 func (region *SRegion) DeleteDBInstanceDatabase(id string) error { 59 return region.rdsDelete(id) 60 } 61 62 func (database *SDBInstanceDatabase) Delete() error { 63 return database.rds.region.DeleteDBInstanceDatabase(database.SelfLink) 64 } 65 66 func (database *SDBInstanceDatabase) GetCharacterSet() string { 67 return database.Charset 68 } 69 70 func (database *SDBInstanceDatabase) GetGlobalId() string { 71 return database.Name 72 } 73 74 func (database *SDBInstanceDatabase) GetId() string { 75 return database.SelfLink 76 } 77 78 func (database *SDBInstanceDatabase) GetName() string { 79 return database.Name 80 } 81 82 func (database *SDBInstanceDatabase) GetStatus() string { 83 return api.DBINSTANCE_DATABASE_RUNNING 84 } 85 86 func (database *SDBInstanceDatabase) IsEmulated() bool { 87 return false 88 } 89 90 func (database *SDBInstanceDatabase) Refresh() error { 91 _database := SDBInstanceDatabase{} 92 err := database.rds.region.rdsGet(database.SelfLink, &_database) 93 if err != nil { 94 return errors.Wrap(err, "rdsGet") 95 } 96 return jsonutils.Update(database, _database) 97 } 98 99 func (region *SRegion) CreateDatabase(instanceId string, name, charset string) error { 100 body := map[string]interface{}{ 101 "charset": charset, 102 "name": name, 103 } 104 return region.rdsDo(instanceId, "databases", nil, jsonutils.Marshal(body)) 105 }