mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
init model
This commit is contained in:
@@ -43,6 +43,7 @@ const (
|
||||
ALIYUN_BSS_API_VERSION = "2017-12-14"
|
||||
|
||||
ALIYUN_RAM_API_VERSION = "2015-05-01"
|
||||
ALIYUN_API_VERION_RDS = "2014-08-15"
|
||||
)
|
||||
|
||||
type SAliyunClient struct {
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/multicloud/objectstore"
|
||||
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -28,6 +30,7 @@ import (
|
||||
)
|
||||
|
||||
type SBucket struct {
|
||||
objectstore.SBucket
|
||||
region *SRegion
|
||||
|
||||
Name string
|
||||
|
||||
@@ -24,7 +24,7 @@ func convertChargeType(ct TChargeType) string {
|
||||
switch ct {
|
||||
case PrePaidInstanceChargeType:
|
||||
return api.BILLING_TYPE_PREPAID
|
||||
case PostPaidInstanceChargeType:
|
||||
case PostPaidInstanceChargeType, PostPaidDBInstanceChargeType:
|
||||
return api.BILLING_TYPE_POSTPAID
|
||||
default:
|
||||
return api.BILLING_TYPE_PREPAID
|
||||
|
||||
@@ -0,0 +1,443 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/log"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
type SReadOnlyDBInstanceIds struct {
|
||||
ReadOnlyDBInstanceId []string
|
||||
}
|
||||
|
||||
type SDBInstanceId struct {
|
||||
DBInstanceId []string
|
||||
}
|
||||
|
||||
type SDBInstanceExtra struct {
|
||||
DBInstanceId SDBInstanceId
|
||||
}
|
||||
|
||||
type SDBInstance struct {
|
||||
multicloud.SDBInstanceBase
|
||||
|
||||
region *SRegion
|
||||
|
||||
AccountMaxQuantity int
|
||||
AccountType string
|
||||
CanTempUpgrade bool
|
||||
Category string
|
||||
AvailabilityValue string
|
||||
DBInstanceDescription string
|
||||
DBInstanceId string
|
||||
ConnectionMode string
|
||||
ConnectionString string
|
||||
CurrentKernelVersion string
|
||||
DBInstanceCPU int
|
||||
CreateTime time.Time
|
||||
DBInstanceClass string
|
||||
DBInstanceClassType string
|
||||
DBInstanceNetType string
|
||||
DBInstanceStatus string
|
||||
DBInstanceType string
|
||||
DBInstanceDiskUsed int64
|
||||
DBInstanceStorage int
|
||||
DBInstanceStorageType string
|
||||
DBInstanceMemory int
|
||||
DBMaxQuantity int
|
||||
IPType string
|
||||
LatestKernelVersion string
|
||||
DispenseMode string
|
||||
Engine string
|
||||
EngineVersion string
|
||||
ExpireTime time.Time
|
||||
InstanceNetworkType string
|
||||
LockMode string
|
||||
LockReason string
|
||||
MutriORsignle bool
|
||||
MaintainTime string
|
||||
MaxConnections int
|
||||
MaxIOPS int
|
||||
Port int
|
||||
PayType TChargeType
|
||||
ReadOnlyDBInstanceIds SReadOnlyDBInstanceIds
|
||||
RegionId string
|
||||
ResourceGroupId string
|
||||
VSwitchId string
|
||||
VpcCloudInstanceId string
|
||||
VpcId string
|
||||
ZoneId string
|
||||
Extra SDBInstanceExtra
|
||||
SecurityIPList string
|
||||
SecurityIPMode string
|
||||
SupportCreateSuperAccount string
|
||||
SupportUpgradeAccountType string
|
||||
TempUpgradeTimeEnd time.Time
|
||||
TempUpgradeTimeStart time.Time
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetName() string {
|
||||
if len(rds.DBInstanceDescription) > 0 {
|
||||
return rds.DBInstanceDescription
|
||||
}
|
||||
return rds.DBInstanceId
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetId() string {
|
||||
return rds.DBInstanceId
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetGlobalId() string {
|
||||
return rds.GetId()
|
||||
}
|
||||
|
||||
// Creating 创建中
|
||||
// Running 使用中
|
||||
// Deleting 删除中
|
||||
// Rebooting 重启中
|
||||
// DBInstanceClassChanging 升降级中
|
||||
// TRANSING 迁移中
|
||||
// EngineVersionUpgrading 迁移版本中
|
||||
// TransingToOthers 迁移数据到其他RDS中
|
||||
// GuardDBInstanceCreating 生产灾备实例中
|
||||
// Restoring 备份恢复中
|
||||
// Importing 数据导入中
|
||||
// ImportingFromOthers 从其他RDS实例导入数据中
|
||||
// DBInstanceNetTypeChanging 内外网切换中
|
||||
// GuardSwitching 容灾切换中
|
||||
// INS_CLONING 实例克隆中
|
||||
func (rds *SDBInstance) GetStatus() string {
|
||||
switch rds.DBInstanceStatus {
|
||||
case "Creating", "DBInstanceClassChanging", "GuardDBInstanceCreating", "DBInstanceNetTypeChanging", "GuardSwitching":
|
||||
return api.DBINSTANCE_DEPLOYING
|
||||
case "Running":
|
||||
return api.DBINSTANCE_RUNNING
|
||||
case "Deleting":
|
||||
return api.DBINSTANCE_DELETING
|
||||
case "Rebooting":
|
||||
return api.DBINSTANCE_REBOOTING
|
||||
case "TRANSING", "EngineVersionUpgrading", "TransingToOthers":
|
||||
return api.DBINSTANCE_MIGRATING
|
||||
case "Restoring":
|
||||
return api.DBINSTANCE_RESTORING
|
||||
case "Importing", "ImportingFromOthers":
|
||||
return api.DBINSTANCE_IMPORTING
|
||||
case "INS_CLONING":
|
||||
return api.DBINSTANCE_CLONING
|
||||
default:
|
||||
return api.DBINSTANCE_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetBillingType() string {
|
||||
return convertChargeType(rds.PayType)
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetExpiredAt() time.Time {
|
||||
return rds.ExpireTime
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetCreatedAt() time.Time {
|
||||
return rds.CreateTime
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetEngine() string {
|
||||
return rds.Engine
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetEngineVersion() string {
|
||||
return rds.EngineVersion
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetInstanceType() string {
|
||||
return rds.DBInstanceClass
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetVcpuCount() int {
|
||||
if rds.DBInstanceCPU == 0 {
|
||||
rds.Refresh()
|
||||
}
|
||||
return rds.DBInstanceCPU
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetVmemSizeMB() int {
|
||||
if rds.DBInstanceMemory == 0 {
|
||||
rds.Refresh()
|
||||
}
|
||||
return rds.DBInstanceMemory
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetDiskSizeGB() int {
|
||||
if rds.DBInstanceStorage == 0 {
|
||||
rds.Refresh()
|
||||
}
|
||||
return rds.DBInstanceStorage
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetPort() int {
|
||||
if rds.Port == 0 {
|
||||
rds.Refresh()
|
||||
}
|
||||
return rds.Port
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetMaintainTime() string {
|
||||
return rds.MaintainTime
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetIVpcId() string {
|
||||
return rds.VpcId
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) Refresh() error {
|
||||
instance, err := rds.region.GetDBInstanceDetail(rds.DBInstanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(rds, instance)
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetIZoneId() string {
|
||||
if len(rds.ZoneId) > 0 {
|
||||
zone, err := rds.region.getZoneById(rds.ZoneId)
|
||||
if err != nil {
|
||||
log.Errorf("SDBInstances.getZoneById %s error: %v", rds.ZoneId, err)
|
||||
return ""
|
||||
}
|
||||
return zone.GetGlobalId()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetDBNetwork() (*cloudprovider.SDBInstanceNetwork, error) {
|
||||
netInfo, err := rds.region.GetDBInstanceNetInfo(rds.DBInstanceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
network := &cloudprovider.SDBInstanceNetwork{}
|
||||
for _, net := range netInfo {
|
||||
if net.IPType == "Private" {
|
||||
network.IP = net.IPAddress
|
||||
network.NetworkId = net.VSwitchId
|
||||
return network, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("failed to found network for aliyun rds %s", rds.DBInstanceId)
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetExtraIps() ([]cloudprovider.SExtraIp, error) {
|
||||
netInfo, err := rds.region.GetDBInstanceNetInfo(rds.DBInstanceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ips := []cloudprovider.SExtraIp{}
|
||||
for _, net := range netInfo {
|
||||
if net.IPType == "Public" || net.IPType == "Inner" {
|
||||
ips = append(ips, cloudprovider.SExtraIp{
|
||||
IP: net.IPAddress,
|
||||
URL: net.ConnectionString,
|
||||
})
|
||||
}
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstances(ids []string, offset int, limit int) ([]SDBInstance, int, error) {
|
||||
if limit > 50 || limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
params := make(map[string]string)
|
||||
params["RegionId"] = region.RegionId
|
||||
params["PageSize"] = fmt.Sprintf("%d", limit)
|
||||
params["PageNumber"] = fmt.Sprintf("%d", (offset/limit)+1)
|
||||
|
||||
body, err := region.rdsRequest("DescribeDBInstances", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "GetDBInstances")
|
||||
}
|
||||
instances := []SDBInstance{}
|
||||
err = body.Unmarshal(&instances, "Items", "DBInstance")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "GetDBInstances.Unmarshal")
|
||||
}
|
||||
total, _ := body.Int("TotalRecordCount")
|
||||
return instances, int(total), nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetIDBInstances() ([]cloudprovider.ICloudDBInstance, error) {
|
||||
instances := []SDBInstance{}
|
||||
for {
|
||||
part, total, err := region.GetDBInstances([]string{}, len(instances), 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
instances = append(instances, part...)
|
||||
if len(instances) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
idbinstances := []cloudprovider.ICloudDBInstance{}
|
||||
for i := 0; i < len(instances); i++ {
|
||||
instances[i].region = region
|
||||
idbinstances = append(idbinstances, &instances[i])
|
||||
}
|
||||
return idbinstances, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceDetail(instanceId string) (*SDBInstance, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["DBInstanceId"] = instanceId
|
||||
body, err := region.rdsRequest("DescribeDBInstanceAttribute", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDBInstanceDetail")
|
||||
}
|
||||
instances := []SDBInstance{}
|
||||
err = body.Unmarshal(&instances, "Items", "DBInstanceAttribute")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDBInstanceDetail.Unmarshal")
|
||||
}
|
||||
if len(instances) == 1 {
|
||||
instances[0].region = region
|
||||
return &instances[0], nil
|
||||
}
|
||||
if len(instances) == 0 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
return nil, cloudprovider.ErrDuplicateId
|
||||
}
|
||||
|
||||
type SDBInstanceWeight struct {
|
||||
}
|
||||
|
||||
type SDBInstanceWeights struct {
|
||||
DBInstanceWeight []SDBInstanceWeight
|
||||
}
|
||||
|
||||
type SsecurityIPGroup struct {
|
||||
}
|
||||
|
||||
type SSecurityIPGroups struct {
|
||||
securityIPGroup []SsecurityIPGroup
|
||||
}
|
||||
|
||||
type SDBInstanceNetwork struct {
|
||||
ConnectionString string
|
||||
ConnectionStringType string
|
||||
DBInstanceWeights SDBInstanceWeights
|
||||
IPAddress string
|
||||
IPType string
|
||||
Port int
|
||||
SecurityIPGroups SSecurityIPGroups
|
||||
Upgradeable string
|
||||
VPCId string
|
||||
VSwitchId string
|
||||
}
|
||||
|
||||
func (network *SDBInstanceNetwork) GetGlobalId() string {
|
||||
return network.IPAddress
|
||||
}
|
||||
|
||||
func (network *SDBInstanceNetwork) GetINetworkId() string {
|
||||
return network.VSwitchId
|
||||
}
|
||||
|
||||
func (network *SDBInstanceNetwork) GetIP() string {
|
||||
return network.IPAddress
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceNetInfo(instanceId string) ([]SDBInstanceNetwork, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["DBInstanceId"] = instanceId
|
||||
body, err := region.rdsRequest("DescribeDBInstanceNetInfo", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDBInstanceNetwork")
|
||||
}
|
||||
networks := []SDBInstanceNetwork{}
|
||||
err = body.Unmarshal(&networks, "DBInstanceNetInfos", "DBInstanceNetInfo")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return networks, nil
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetIDBInstanceParameters() ([]cloudprovider.ICloudDBInstanceParameter, error) {
|
||||
parameters, err := rds.region.GetDBInstanceParameters(rds.DBInstanceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iparameters := []cloudprovider.ICloudDBInstanceParameter{}
|
||||
for i := 0; i < len(parameters); i++ {
|
||||
iparameters = append(iparameters, ¶meters[i])
|
||||
}
|
||||
return iparameters, nil
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetIDBInstanceBackups() ([]cloudprovider.ICloudDBInstanceBackup, error) {
|
||||
backups := []SDBInstanceBackup{}
|
||||
for {
|
||||
parts, total, err := rds.region.GetDBInstanceBackups(rds.DBInstanceId, "", len(backups), 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
backups = append(backups, parts...)
|
||||
if len(backups) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
ibackups := []cloudprovider.ICloudDBInstanceBackup{}
|
||||
for i := 0; i < len(backups); i++ {
|
||||
ibackups = append(ibackups, &backups[i])
|
||||
}
|
||||
return ibackups, nil
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetIDBInstanceDatabases() ([]cloudprovider.ICloudDBInstanceDatabase, error) {
|
||||
databases := []SDBInstanceDatabase{}
|
||||
for {
|
||||
parts, total, err := rds.region.GetDBInstanceDatabases(rds.DBInstanceId, "", len(databases), 500)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
databases = append(databases, parts...)
|
||||
if len(databases) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
idatabase := []cloudprovider.ICloudDBInstanceDatabase{}
|
||||
for i := 0; i < len(databases); i++ {
|
||||
idatabase = append(idatabase, &databases[i])
|
||||
}
|
||||
return idatabase, nil
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetIDBInstanceAccounts() ([]cloudprovider.ICloudDBInstanceAccount, error) {
|
||||
accounts := []SDBInstanceAccount{}
|
||||
for {
|
||||
parts, total, err := rds.region.GetDBInstanceAccounts(rds.DBInstanceId, len(accounts), 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
accounts = append(accounts, parts...)
|
||||
if len(accounts) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
iaccounts := []cloudprovider.ICloudDBInstanceAccount{}
|
||||
for i := 0; i < len(accounts); i++ {
|
||||
iaccounts = append(iaccounts, &accounts[i])
|
||||
}
|
||||
return iaccounts, nil
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
)
|
||||
|
||||
type SDatabasePrivilege struct {
|
||||
AccountPrivilege string
|
||||
AccountPrivilegeDetail string
|
||||
DBName string
|
||||
}
|
||||
|
||||
type SDatabasePrivileges struct {
|
||||
DatabasePrivilege []SDatabasePrivilege
|
||||
}
|
||||
|
||||
type SDBInstanceAccount struct {
|
||||
multicloud.SDBInstanceAccountBase
|
||||
|
||||
AccountDescription string
|
||||
AccountName string
|
||||
AccountStatus string
|
||||
AccountType string
|
||||
DBInstanceId string
|
||||
DatabasePrivileges SDatabasePrivileges
|
||||
PrivExceeded string
|
||||
}
|
||||
|
||||
func (account *SDBInstanceAccount) GetId() string {
|
||||
return account.AccountName
|
||||
}
|
||||
|
||||
func (account *SDBInstanceAccount) GetGlobalId() string {
|
||||
return account.AccountName
|
||||
}
|
||||
|
||||
func (account *SDBInstanceAccount) GetName() string {
|
||||
return account.AccountName
|
||||
}
|
||||
|
||||
func (account *SDBInstanceAccount) GetStatus() string {
|
||||
switch account.AccountStatus {
|
||||
case "Available":
|
||||
return api.DBINSTANCE_USER_AVAILABLE
|
||||
case "Unavailable":
|
||||
return api.DBINSTANCE_USER_UNAVAILABLE
|
||||
}
|
||||
return account.AccountStatus
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceAccounts(instanceId string, offset int, limit int) ([]SDBInstanceAccount, int, error) {
|
||||
if limit > 50 || limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
params := map[string]string{
|
||||
"RegionId": region.RegionId,
|
||||
"PageSize": fmt.Sprintf("%d", limit),
|
||||
"PageNumber": fmt.Sprintf("%d", (offset/limit)+1),
|
||||
"DBInstanceId": instanceId,
|
||||
}
|
||||
body, err := region.rdsRequest("DescribeAccounts", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "DescribeAccounts")
|
||||
}
|
||||
accounts := []SDBInstanceAccount{}
|
||||
err = body.Unmarshal(&accounts, "Accounts", "DBInstanceAccount")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "Unmarshal")
|
||||
}
|
||||
total, _ := body.Int("TotalRecordCount")
|
||||
return accounts, int(total), nil
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SDBInstanceBackup struct {
|
||||
multicloud.SDBInstanceBackupBase
|
||||
|
||||
BackupDBNames string
|
||||
BackupIntranetDownloadURL string
|
||||
BackupDownloadURL string
|
||||
BackupEndTime time.Time
|
||||
BackupId string
|
||||
BackupLocation string
|
||||
BackupMethod string
|
||||
BackupMode string
|
||||
BackupScale string
|
||||
BackupSize int
|
||||
BackupStartTime time.Time
|
||||
BackupStatus string
|
||||
BackupType string
|
||||
DBInstanceId string
|
||||
HostInstanceID int
|
||||
MetaStatus string
|
||||
StoreStatus string
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetId() string {
|
||||
return backup.BackupId
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetGlobalId() string {
|
||||
return backup.BackupId
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetName() string {
|
||||
return backup.BackupId
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetStartTime() time.Time {
|
||||
return backup.BackupStartTime
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetEndTime() time.Time {
|
||||
return backup.BackupEndTime
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetBackupType() string {
|
||||
switch backup.BackupType {
|
||||
case "FullBackup":
|
||||
return api.BACKUP_TYPE_FULL_BACKUP
|
||||
case "IncrementalBackup":
|
||||
return api.BACKUP_TYPE_INCREMENTALBACKUP
|
||||
default:
|
||||
log.Errorf("Unknown backup type %s", backup.BackupType)
|
||||
return api.BACKUP_TYPE_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetStatus() string {
|
||||
switch backup.BackupStatus {
|
||||
case "Success":
|
||||
return api.DBINSTANCE_BACKUP_READY
|
||||
case "Failed":
|
||||
return api.DBINSTANCE_BACKUP_FAILED
|
||||
default:
|
||||
return api.DBINSTANCE_BACKUP_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetBackupSizeMb() int {
|
||||
return backup.BackupSize / 1024 / 1024
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetDBNames() string {
|
||||
return backup.BackupDBNames
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetDownloadURL() string {
|
||||
return backup.BackupDownloadURL
|
||||
}
|
||||
|
||||
func (backup *SDBInstanceBackup) GetIntranetDownloadURL() string {
|
||||
return backup.BackupIntranetDownloadURL
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceBackups(instanceId, backupId string, offset int, limit int) ([]SDBInstanceBackup, int, error) {
|
||||
if limit > 50 || limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
params := map[string]string{
|
||||
"RegionId": region.RegionId,
|
||||
"PageSize": fmt.Sprintf("%d", limit),
|
||||
"PageNumber": fmt.Sprintf("%d", (offset/limit)+1),
|
||||
"DBInstanceId": instanceId,
|
||||
}
|
||||
if len(backupId) > 0 {
|
||||
params["BackupId"] = backupId
|
||||
}
|
||||
body, err := region.rdsRequest("DescribeBackups", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "DescribeBackups")
|
||||
}
|
||||
backups := []SDBInstanceBackup{}
|
||||
err = body.Unmarshal(&backups, "Items", "Backup")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "Unmarshal")
|
||||
}
|
||||
total, _ := body.Int("TotalRecordCount")
|
||||
return backups, int(total), nil
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SDBInstanceDatabase struct {
|
||||
multicloud.SDBInstanceDatabaseBase
|
||||
|
||||
CharacterSetName string
|
||||
DBDescription string
|
||||
DBInstanceId string
|
||||
DBName string
|
||||
DBStatus string
|
||||
Engine string
|
||||
}
|
||||
|
||||
func (database *SDBInstanceDatabase) GetId() string {
|
||||
return database.DBName
|
||||
}
|
||||
|
||||
func (database *SDBInstanceDatabase) GetGlobalId() string {
|
||||
return database.DBName
|
||||
}
|
||||
|
||||
func (database *SDBInstanceDatabase) GetName() string {
|
||||
return database.DBName
|
||||
}
|
||||
|
||||
func (database *SDBInstanceDatabase) GetStatus() string {
|
||||
switch database.DBStatus {
|
||||
case "Creating":
|
||||
return api.DBINSTANCE_DATABASE_CREATING
|
||||
case "Running":
|
||||
return api.DBINSTANCE_DATABASE_RUNNING
|
||||
case "Deleting":
|
||||
return api.DBINSTANCE_DATABASE_DELETING
|
||||
}
|
||||
return database.DBStatus
|
||||
}
|
||||
|
||||
func (database *SDBInstanceDatabase) GetCharacterSet() string {
|
||||
return database.CharacterSetName
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceDatabases(instanceId, dbName string, offset int, limit int) ([]SDBInstanceDatabase, int, error) {
|
||||
if limit > 500 || limit <= 0 {
|
||||
limit = 500
|
||||
}
|
||||
params := map[string]string{
|
||||
"RegionId": region.RegionId,
|
||||
"PageSize": fmt.Sprintf("%d", limit),
|
||||
"PageNumber": fmt.Sprintf("%d", (offset/limit)+1),
|
||||
"DBInstanceId": instanceId,
|
||||
}
|
||||
if len(dbName) > 0 {
|
||||
params["DBName"] = dbName
|
||||
}
|
||||
body, err := region.rdsRequest("DescribeDatabases", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "DescribeDatabases")
|
||||
}
|
||||
databases := []SDBInstanceDatabase{}
|
||||
err = body.Unmarshal(&databases, "Databases", "Database")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "Unmarshal")
|
||||
}
|
||||
total, _ := body.Int("TotalRecordCount")
|
||||
return databases, int(total), nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
type SDBInstanceParameter struct {
|
||||
ParameterDescription string
|
||||
ParameterValue string
|
||||
ParameterName string
|
||||
}
|
||||
|
||||
func (param *SDBInstanceParameter) GetGlobalId() string {
|
||||
return param.ParameterName
|
||||
}
|
||||
|
||||
func (param *SDBInstanceParameter) GetKey() string {
|
||||
return param.ParameterName
|
||||
}
|
||||
|
||||
func (param *SDBInstanceParameter) GetValue() string {
|
||||
return param.ParameterValue
|
||||
}
|
||||
|
||||
func (param *SDBInstanceParameter) GetDescription() string {
|
||||
return param.ParameterDescription
|
||||
}
|
||||
|
||||
func (region *SRegion) GetDBInstanceParameters(instanceId string) ([]SDBInstanceParameter, error) {
|
||||
params := map[string]string{
|
||||
"RegionId": region.RegionId,
|
||||
"DBInstanceId": instanceId,
|
||||
"ClientToken": utils.GenRequestId(20),
|
||||
}
|
||||
|
||||
body, err := region.rdsRequest("DescribeParameters", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "DescribeParameters")
|
||||
}
|
||||
parameters1 := []SDBInstanceParameter{}
|
||||
err = body.Unmarshal(¶meters1, "ConfigParameters", "DBInstanceParameter")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Unmarshal.ConfigParameters")
|
||||
}
|
||||
parameters2 := []SDBInstanceParameter{}
|
||||
err = body.Unmarshal(¶meters1, "RunningParameters", "DBInstanceParameter")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Unmarshal.RunningParameters")
|
||||
}
|
||||
return append(parameters1, parameters2...), nil
|
||||
}
|
||||
@@ -111,6 +111,14 @@ func (self *SRegion) ecsRequest(apiName string, params map[string]string) (jsonu
|
||||
return jsonRequest(client, "ecs.aliyuncs.com", ALIYUN_API_VERSION, apiName, params, self.client.Debug)
|
||||
}
|
||||
|
||||
func (self *SRegion) rdsRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
client, err := self.getSdkClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return jsonRequest(client, "rds.aliyuncs.com", ALIYUN_API_VERION_RDS, apiName, params, self.client.Debug)
|
||||
}
|
||||
|
||||
func (self *SRegion) vpcRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
client, err := self.getSdkClient()
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/util/aliyun"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type DBInstanceListOptions struct {
|
||||
Id []string `help:"IDs of instances to show"`
|
||||
Limit int `help:"page size"`
|
||||
Offset int `help:"page offset"`
|
||||
}
|
||||
shellutils.R(&DBInstanceListOptions{}, "dbinstance-list", "List dbintances", func(cli *aliyun.SRegion, args *DBInstanceListOptions) error {
|
||||
instances, total, e := cli.GetDBInstances(args.Id, args.Offset, args.Limit)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printList(instances, total, args.Offset, args.Limit, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
type DBInstanceIdOptions struct {
|
||||
ID string `help:"ID of instances to show"`
|
||||
}
|
||||
shellutils.R(&DBInstanceIdOptions{}, "dbinstance-show", "Show dbintance", func(cli *aliyun.SRegion, args *DBInstanceIdOptions) error {
|
||||
instance, err := cli.GetDBInstanceDetail(args.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(instance)
|
||||
return nil
|
||||
})
|
||||
|
||||
shellutils.R(&DBInstanceIdOptions{}, "dbinstance-network-list", "Show dbintance network info", func(cli *aliyun.SRegion, args *DBInstanceIdOptions) error {
|
||||
networks, err := cli.GetDBInstanceNetInfo(args.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(networks, 0, 0, 0, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
type DBInstanceIdExtraOptions struct {
|
||||
ID string `help:"ID of instances to show"`
|
||||
Limit int `help:"page size"`
|
||||
Offset int `help:"page offset"`
|
||||
}
|
||||
|
||||
shellutils.R(&DBInstanceIdExtraOptions{}, "dbinstance-backup-list", "List dbintance backups", func(cli *aliyun.SRegion, args *DBInstanceIdExtraOptions) error {
|
||||
backups, _, err := cli.GetDBInstanceBackups(args.ID, "", args.Offset, args.Limit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(backups, 0, 0, 0, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
shellutils.R(&DBInstanceIdExtraOptions{}, "dbinstance-database-list", "List dbintance databases", func(cli *aliyun.SRegion, args *DBInstanceIdExtraOptions) error {
|
||||
databases, _, err := cli.GetDBInstanceDatabases(args.ID, "", args.Offset, args.Limit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(databases, 0, 0, 0, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
shellutils.R(&DBInstanceIdExtraOptions{}, "dbinstance-account-list", "List dbintance account", func(cli *aliyun.SRegion, args *DBInstanceIdExtraOptions) error {
|
||||
accounts, _, err := cli.GetDBInstanceAccounts(args.ID, args.Offset, args.Limit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(accounts, 0, 0, 0, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -28,9 +28,10 @@ import (
|
||||
type TChargeType string
|
||||
|
||||
const (
|
||||
PrePaidInstanceChargeType TChargeType = "PrePaid"
|
||||
PostPaidInstanceChargeType TChargeType = "PostPaid"
|
||||
DefaultInstanceChargeType = PostPaidInstanceChargeType
|
||||
PrePaidInstanceChargeType TChargeType = "PrePaid"
|
||||
PostPaidInstanceChargeType TChargeType = "PostPaid"
|
||||
PostPaidDBInstanceChargeType TChargeType = "Postpaid"
|
||||
DefaultInstanceChargeType = PostPaidInstanceChargeType
|
||||
)
|
||||
|
||||
type SpotStrategyType string
|
||||
|
||||
@@ -29,9 +29,11 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/objectstore"
|
||||
)
|
||||
|
||||
type SBucket struct {
|
||||
objectstore.SBucket
|
||||
region *SRegion
|
||||
|
||||
Name string
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/aws/aws-sdk-go/service/iam"
|
||||
"github.com/aws/aws-sdk-go/service/rds"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -63,6 +64,7 @@ type SRegion struct {
|
||||
ec2Client *ec2.EC2
|
||||
iamClient *iam.IAM
|
||||
s3Client *s3.S3
|
||||
rdsClient *rds.RDS
|
||||
|
||||
izones []cloudprovider.ICloudZone
|
||||
ivpcs []cloudprovider.ICloudVpc
|
||||
@@ -116,6 +118,20 @@ func (self *SRegion) getIamClient() (*iam.IAM, error) {
|
||||
return self.iamClient, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) getRdsClient() (*rds.RDS, error) {
|
||||
if self.rdsClient == nil {
|
||||
s, err := self.getAwsSession()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
self.rdsClient = rds.New(s)
|
||||
}
|
||||
|
||||
return self.rdsClient, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetS3Client() (*s3.S3, error) {
|
||||
if self.s3Client == nil {
|
||||
s, err := self.getAwsSession()
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/multicloud/objectstore"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/storage"
|
||||
"github.com/Microsoft/azure-vhd-utils/vhdcore/common"
|
||||
"github.com/Microsoft/azure-vhd-utils/vhdcore/diskstream"
|
||||
@@ -77,6 +79,7 @@ type AccountProperties struct {
|
||||
}
|
||||
|
||||
type SStorageAccount struct {
|
||||
objectstore.SBucket
|
||||
region *SRegion
|
||||
|
||||
accountKey string
|
||||
|
||||
@@ -18,15 +18,19 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/multicloud/objectstore"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/util/huawei/obs"
|
||||
)
|
||||
|
||||
type SBucket struct {
|
||||
objectstore.SBucket
|
||||
region *SRegion
|
||||
|
||||
Name string
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/multicloud/objectstore"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -29,6 +31,7 @@ import (
|
||||
)
|
||||
|
||||
type SBucket struct {
|
||||
objectstore.SBucket
|
||||
region *SRegion
|
||||
|
||||
Name string
|
||||
|
||||
@@ -25,14 +25,18 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/multicloud/objectstore"
|
||||
|
||||
"yunion.io/x/log"
|
||||
|
||||
"context"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
|
||||
type SBucket struct {
|
||||
objectstore.SBucket
|
||||
region *SRegion
|
||||
|
||||
projectId string
|
||||
|
||||
Reference in New Issue
Block a user