yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/rds_managed_sqlserver_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  	"net/url"
    19  	"strings"
    20  	"time"
    21  
    22  	"yunion.io/x/pkg/errors"
    23  
    24  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    25  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    26  	"yunion.io/x/cloudmux/pkg/multicloud"
    27  )
    28  
    29  type SManagedSQLServerDatabase struct {
    30  	multicloud.SDBInstanceDatabaseBase
    31  	AzureTags
    32  	rds *SManagedSQLServer
    33  
    34  	ID         string `json:"id"`
    35  	Location   string `json:"location"`
    36  	Name       string `json:"name"`
    37  	Properties struct {
    38  		Collation                string    `json:"collation"`
    39  		Creationdate             time.Time `json:"creationDate"`
    40  		Defaultsecondarylocation string    `json:"defaultSecondaryLocation"`
    41  		Status                   string    `json:"status"`
    42  	} `json:"properties"`
    43  	Type string `json:"type"`
    44  }
    45  
    46  func (self *SManagedSQLServerDatabase) GetName() string {
    47  	return self.Name
    48  }
    49  
    50  func (self *SManagedSQLServerDatabase) GetId() string {
    51  	return self.ID
    52  }
    53  
    54  func (self *SManagedSQLServerDatabase) GetStatus() string {
    55  	switch self.Properties.Status {
    56  	case "Online":
    57  		return api.DBINSTANCE_DATABASE_RUNNING
    58  	case "Creating":
    59  		return api.DBINSTANCE_DATABASE_CREATING
    60  	default:
    61  		return strings.ToLower(self.Properties.Status)
    62  	}
    63  }
    64  
    65  func (self *SManagedSQLServerDatabase) GetGlobalId() string {
    66  	return strings.ToLower(self.Name)
    67  }
    68  
    69  func (self *SManagedSQLServerDatabase) GetCharacterSet() string {
    70  	return self.Properties.Collation
    71  }
    72  
    73  func (self *SRegion) GetManagedSQLServerDatabases(id string) ([]SManagedSQLServerDatabase, error) {
    74  	result := struct {
    75  		Value []SManagedSQLServerDatabase
    76  	}{}
    77  	return result.Value, self.get(id+"/databases", url.Values{}, &result)
    78  }
    79  
    80  func (self *SManagedSQLServer) GetIDBInstanceDatabases() ([]cloudprovider.ICloudDBInstanceDatabase, error) {
    81  	dbs, err := self.region.GetManagedSQLServerDatabases(self.ID)
    82  	if err != nil {
    83  		return nil, errors.Wrapf(err, "GetSQLServerDatabases")
    84  	}
    85  	ret := []cloudprovider.ICloudDBInstanceDatabase{}
    86  	for i := range dbs {
    87  		dbs[i].rds = self
    88  		ret = append(ret, &dbs[i])
    89  	}
    90  	return ret, nil
    91  }