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