yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcs/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 hcs 16 17 import ( 18 "fmt" 19 20 api "yunion.io/x/cloudmux/pkg/apis/compute" 21 "yunion.io/x/cloudmux/pkg/multicloud" 22 "yunion.io/x/cloudmux/pkg/multicloud/huawei" 23 ) 24 25 type SDBInstanceDatabase struct { 26 instance *SDBInstance 27 multicloud.SDBInstanceDatabaseBase 28 huawei.HuaweiTags 29 30 Name string 31 CharacterSet string 32 } 33 34 func (database *SDBInstanceDatabase) GetId() string { 35 return database.Name 36 } 37 38 func (database *SDBInstanceDatabase) GetGlobalId() string { 39 return database.Name 40 } 41 42 func (database *SDBInstanceDatabase) GetName() string { 43 return database.Name 44 } 45 46 func (database *SDBInstanceDatabase) GetStatus() string { 47 return api.DBINSTANCE_DATABASE_RUNNING 48 } 49 50 func (database *SDBInstanceDatabase) GetCharacterSet() string { 51 return database.CharacterSet 52 } 53 54 func (database *SDBInstanceDatabase) Delete() error { 55 return database.instance.region.DeleteDBInstanceDatabase(database.instance.Id, database.Name) 56 } 57 58 func (region *SRegion) DeleteDBInstanceDatabase(instanceId, database string) error { 59 resource := fmt.Sprintf("instances/%s/database/%s", instanceId, database) 60 err := region.rdsDelete(resource) 61 return err 62 } 63 64 // rds查询数据库列表 65 func (region *SRegion) GetDBInstanceDatabases(instanceId string) ([]SDBInstanceDatabase, error) { 66 resource := fmt.Sprintf("%s/database/detail", instanceId) 67 databases := []SDBInstanceDatabase{} 68 err := region.rdsList(resource, nil, databases) 69 if err != nil { 70 return nil, err 71 } 72 return databases, nil 73 }