forked from yunionio/cloudmux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbinstance_database.go
105 lines (88 loc) · 2.83 KB
/
dbinstance_database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google
import (
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
api "yunion.io/x/cloudmux/pkg/apis/compute"
"yunion.io/x/cloudmux/pkg/multicloud"
)
type SSqlserverDatabaseDetails struct {
CompatibilityLevel int
RecoveryModel string
}
type SDBInstanceDatabase struct {
multicloud.SResourceBase
GoogleTags
rds *SDBInstance
Kind string
Collation string
Etag string
Name string
Instance string
SelfLink string
Charset string
Project string
SqlserverDatabaseDetails SSqlserverDatabaseDetails
}
func (region *SRegion) GetDBInstanceDatabases(instance string) ([]SDBInstanceDatabase, error) {
databases := []SDBInstanceDatabase{}
params := map[string]string{}
resource := fmt.Sprintf("instances/%s/databases", instance)
err := region.RdsListAll(resource, params, &databases)
if err != nil {
return nil, errors.Wrap(err, "RdsListAll")
}
return databases, nil
}
func (region *SRegion) DeleteDBInstanceDatabase(id string) error {
return region.rdsDelete(id)
}
func (database *SDBInstanceDatabase) Delete() error {
return database.rds.region.DeleteDBInstanceDatabase(database.SelfLink)
}
func (database *SDBInstanceDatabase) GetCharacterSet() string {
return database.Charset
}
func (database *SDBInstanceDatabase) GetGlobalId() string {
return database.Name
}
func (database *SDBInstanceDatabase) GetId() string {
return database.SelfLink
}
func (database *SDBInstanceDatabase) GetName() string {
return database.Name
}
func (database *SDBInstanceDatabase) GetStatus() string {
return api.DBINSTANCE_DATABASE_RUNNING
}
func (database *SDBInstanceDatabase) IsEmulated() bool {
return false
}
func (database *SDBInstanceDatabase) Refresh() error {
_database := SDBInstanceDatabase{}
err := database.rds.region.rdsGet(database.SelfLink, &_database)
if err != nil {
return errors.Wrap(err, "rdsGet")
}
return jsonutils.Update(database, _database)
}
func (region *SRegion) CreateDatabase(instanceId string, name, charset string) error {
body := map[string]interface{}{
"charset": charset,
"name": name,
}
return region.rdsDo(instanceId, "databases", nil, jsonutils.Marshal(body))
}