diff --git a/pkg/cloudprovider/resources.go b/pkg/cloudprovider/resources.go index d7baf29d83..9293284250 100644 --- a/pkg/cloudprovider/resources.go +++ b/pkg/cloudprovider/resources.go @@ -329,6 +329,8 @@ type ICloudVM interface { GetIEIP() (ICloudEIP, error) + GetInternetMaxBandwidthOut() int + GetThroughput() int // GetStatus() string // GetRemoteStatus() string @@ -960,6 +962,7 @@ type ICloudDBInstance interface { GetZone2Id() string GetZone3Id() string GetIVpcId() string + GetIops() int GetDBNetworks() ([]SDBInstanceNetwork, error) GetIDBInstanceParameters() ([]ICloudDBInstanceParameter, error) @@ -1431,6 +1434,8 @@ type ICloudMongoDB interface { GetInstanceType() string GetMaintainTime() string GetPort() int + GetIops() int + GetNetworkAddress() string GetIBackups() ([]SMongoDBBackup, error) diff --git a/pkg/compute/models/dbinstances.go b/pkg/compute/models/dbinstances.go index 3955c0a54f..a791ed8071 100644 --- a/pkg/compute/models/dbinstances.go +++ b/pkg/compute/models/dbinstances.go @@ -106,6 +106,9 @@ type SDBInstance struct { // example: ha Category string `nullable:"false" list:"user" create:"optional"` + // 最大连接数 + Iops int `nullable:"true" list:"user" create:"optional"` + // 引擎 // example: MySQL Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"` @@ -1600,6 +1603,9 @@ func (self *SDBInstance) SyncWithCloudDBInstance(ctx context.Context, userCred m self.Category = ext.GetCategory() self.Status = ext.GetStatus() self.Port = ext.GetPort() + if iops := ext.GetIops(); iops > 0 { + self.Iops = iops + } self.ConnectionStr = ext.GetConnectionStr() self.InternalConnectionStr = ext.GetInternalConnectionStr() @@ -1688,6 +1694,7 @@ func (manager *SDBInstanceManager) newFromCloudDBInstance(ctx context.Context, u instance.Status = extInstance.GetStatus() instance.Port = extInstance.GetPort() + instance.Iops = extInstance.GetIops() instance.Engine = extInstance.GetEngine() instance.EngineVersion = extInstance.GetEngineVersion() instance.InstanceType = extInstance.GetInstanceType() diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index 57d46ea65a..b98d595354 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -129,6 +129,9 @@ type SDisk struct { // 最大连接数 Iops int `nullable:"true" list:"user" create:"optional"` + + // 磁盘吞吐量 + Throughput int `nullable:"true" list:"user" create:"optional"` } func (manager *SDiskManager) GetContextManagers() [][]db.IModelManager { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 1fc81e6a8d..d15e95b25e 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -165,6 +165,11 @@ type SGuest struct { SshableLastState tristate.TriState `default:"false" list:"user"` IsDaemon tristate.TriState `default:"false" list:"admin" create:"admin_optional" update:"admin"` + + // 最大内网带宽 + InternetMaxBandwidthOut int `nullable:"false" list:"user" create:"optional"` + // 磁盘吞吐量 + Throughput int `nullable:"true" list:"user" create:"optional"` } func (manager *SGuestManager) GetPropertyStatistics(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*apis.StatusStatistic, error) { @@ -2705,6 +2710,8 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token if !recycle { self.HostId = host.Id } + self.InternetMaxBandwidthOut = extVM.GetInternetMaxBandwidthOut() + self.Throughput = extVM.GetThroughput() instanceType := extVM.GetInstanceType() @@ -2791,6 +2798,8 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient. guest.Machine = extVM.GetMachine() guest.Hypervisor = extVM.GetHypervisor() guest.Hostname = extVM.GetHostname() + guest.InternetMaxBandwidthOut = extVM.GetInternetMaxBandwidthOut() + guest.Throughput = extVM.GetThroughput() guest.IsEmulated = extVM.IsEmulated() diff --git a/pkg/compute/models/mongodb.go b/pkg/compute/models/mongodb.go index fc2288651b..c7c646ebf1 100644 --- a/pkg/compute/models/mongodb.go +++ b/pkg/compute/models/mongodb.go @@ -96,6 +96,9 @@ type SMongoDB struct { // example: 3 ReplicationNum int `nullable:"false" default:"0" list:"user" create:"optional"` + // 最大连接数 + Iops int `nullable:"true" list:"user" create:"optional"` + // 实例IP地址 IpAddr string `nullable:"false" list:"user"` @@ -118,6 +121,9 @@ type SMongoDB struct { // 所属网络ID NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional" json:"network_id"` + + // 连接地址 + NetworkAddress string `width:"256" charset:"ascii" nullable:"true" list:"user" create:"optional"` } func (manager *SMongoDBManager) GetContextManagers() [][]db.IModelManager { @@ -495,6 +501,10 @@ func (self *SMongoDB) SyncWithCloudMongoDB(ctx context.Context, userCred mcclien self.MaintainTime = ext.GetMaintainTime() self.Status = ext.GetStatus() self.Port = ext.GetPort() + if iops := ext.GetIops(); iops > 0 { + self.Iops = iops + } + self.NetworkAddress = ext.GetNetworkAddress() if vpcId := ext.GetVpcId(); len(vpcId) > 0 { vpc, err := db.FetchByExternalIdAndManagerId(VpcManager, vpcId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery { @@ -567,6 +577,8 @@ func (self *SCloudregion) newFromCloudMongoDB(ctx context.Context, userCred mccl ins.MaintainTime = ext.GetMaintainTime() ins.Port = ext.GetPort() ins.ReplicationNum = ext.GetReplicationNum() + ins.Iops = ext.GetIops() + ins.NetworkAddress = ext.GetNetworkAddress() if zoneId := ext.GetZoneId(); len(zoneId) > 0 { zone, err := self.GetZoneBySuffix(zoneId) diff --git a/pkg/multicloud/aliyun/dbinstance.go b/pkg/multicloud/aliyun/dbinstance.go index c1078361bb..c828e0468c 100644 --- a/pkg/multicloud/aliyun/dbinstance.go +++ b/pkg/multicloud/aliyun/dbinstance.go @@ -60,6 +60,7 @@ type SDBInstance struct { DBInstanceId string ConnectionMode string ConnectionString string + ConnectionDomain string CurrentKernelVersion string DBInstanceCPU int CreateTime time.Time @@ -284,6 +285,17 @@ func (rds *SDBInstance) GetZone3Id() string { return rds.getZoneId(3) } +func (rds *SDBInstance) GetIOPS() int { + if rds.MaxIOPS == 0 { + rds.Refresh() + } + return rds.MaxIOPS +} + +func (rds *SDBInstance) GetNetworkAddress() string { + return rds.ConnectionDomain +} + func (rds *SDBInstance) getZone(index int) string { zoneStr := strings.Replace(rds.ZoneId, ")", "", -1) zoneInfo := strings.Split(zoneStr, ",") diff --git a/pkg/multicloud/aliyun/instance.go b/pkg/multicloud/aliyun/instance.go index 20e7d1239a..60b2f703d6 100644 --- a/pkg/multicloud/aliyun/instance.go +++ b/pkg/multicloud/aliyun/instance.go @@ -130,6 +130,7 @@ type SInstance struct { VlanId string VpcAttributes SVpcAttributes ZoneId string + Throughput int } // {"AutoReleaseTime":"","ClusterId":"","Cpu":1,"CreationTime":"2018-05-23T07:58Z","DedicatedHostAttribute":{"DedicatedHostId":"","DedicatedHostName":""},"Description":"","DeviceAvailable":true,"EipAddress":{"AllocationId":"","InternetChargeType":"","IpAddress":""},"ExpiredTime":"2018-05-30T16:00Z","GPUAmount":0,"GPUSpec":"","HostName":"iZ2ze57isp1ali72tzkjowZ","ImageId":"centos_7_04_64_20G_alibase_201701015.vhd","InnerIpAddress":{"IpAddress":[]},"InstanceChargeType":"PrePaid","InstanceId":"i-2ze57isp1ali72tzkjow","InstanceName":"gaoxianqi-test-7days","InstanceNetworkType":"vpc","InstanceType":"ecs.t5-lc2m1.nano","InstanceTypeFamily":"ecs.t5","InternetChargeType":"PayByBandwidth","InternetMaxBandwidthIn":-1,"InternetMaxBandwidthOut":0,"IoOptimized":true,"Memory":512,"NetworkInterfaces":{"NetworkInterface":[{"MacAddress":"00:16:3e:10:f0:c9","NetworkInterfaceId":"eni-2zecqsagtpztl6x5hu2r","PrimaryIpAddress":"192.168.220.214"}]},"OSName":"CentOS 7.4 64位","OSType":"linux","OperationLocks":{"LockReason":[]},"PublicIpAddress":{"IpAddress":[]},"Recyclable":false,"RegionId":"cn-beijing","ResourceGroupId":"","SaleCycle":"Week","SecurityGroupIds":{"SecurityGroupId":["sg-2zecqsagtpztl6x9zynl"]},"SerialNumber":"df05d9b4-df3d-4400-88d1-5f843f0dd088","SpotPriceLimit":0.000000,"SpotStrategy":"NoSpot","StartTime":"2018-05-23T07:58Z","Status":"Running","StoppedMode":"Not-applicable","VlanId":"","VpcAttributes":{"NatIpAddress":"","PrivateIpAddress":{"IpAddress":["192.168.220.214"]},"VSwitchId":"vsw-2ze9cqwza4upoyujq1thd","VpcId":"vpc-2zer4jy8ix3i8f0coc5uw"},"ZoneId":"cn-beijing-f"} @@ -976,6 +977,14 @@ func (self *SInstance) Renew(bc billing.SBillingCycle) error { return self.host.zone.region.RenewInstance(self.InstanceId, bc) } +func (self *SInstance) GetThroughput() int { + return self.Throughput +} + +func (self *SInstance) GetInternetMaxBandwidthOut() int { + return self.InternetMaxBandwidthOut +} + func billingCycle2Params(bc *billing.SBillingCycle, params map[string]string) error { if bc.GetMonths() > 0 { params["PeriodUnit"] = "Month" diff --git a/pkg/multicloud/aliyun/mongodb.go b/pkg/multicloud/aliyun/mongodb.go index fd2289a939..b0953b2398 100644 --- a/pkg/multicloud/aliyun/mongodb.go +++ b/pkg/multicloud/aliyun/mongodb.go @@ -31,19 +31,31 @@ import ( "yunion.io/x/onecloud/pkg/multicloud" ) +type SMOngoDBAttribute struct { + // 实例最大IOPS + MaxIops int + ReplicaSets struct { + ReplicaSet []struct { + ConnectionDomain string `json:"ConnectionDomain"` + } + } +} + type SMongoDB struct { region *SRegion multicloud.AliyunTags multicloud.SBillingBase multicloud.SResourceBase - ChargeType TChargeType `json:"ChargeType"` - LockMode string `json:"LockMode"` - DBInstanceClass string `json:"DBInstanceClass"` - ResourceGroupId string `json:"ResourceGroupId"` - DBInstanceId string `json:"DBInstanceId"` - ZoneId string `json:"ZoneId"` - MongosList struct { + ConnectionDomain string `json:"ConnectionDomain"` + NetworkAddress string + ChargeType TChargeType `json:"ChargeType"` + LockMode string `json:"LockMode"` + DBInstanceClass string `json:"DBInstanceClass"` + ResourceGroupId string `json:"ResourceGroupId"` + DBInstanceId string `json:"DBInstanceId"` + ZoneId string `json:"ZoneId"` + MongosList struct { MongosAttribute []struct { NodeId string `json:"NodeId"` NodeClass string `json:"NodeClass"` @@ -237,6 +249,16 @@ func (self *SMongoDB) GetVmemSizeMb() int { return 0 } +func (self *SMongoDB) GetIops() int { + iops, _ := self.region.GetIops(self.DBInstanceId) + return iops +} + +func (self *SMongoDB) GetNetworkAddress() string { + addr, _ := self.region.GetNetworkAddress(self.DBInstanceId) + return addr +} + func (self *SRegion) GetMongoDBsByType(mongoType string) ([]SMongoDB, error) { dbs := []SMongoDB{} for { @@ -281,6 +303,47 @@ func (self *SRegion) GetICloudMongoDBs() ([]cloudprovider.ICloudMongoDB, error) return ret, nil } +func (self *SRegion) GetIops(id string) (int, error) { + ret, err := self.GetMongoDBAttribute(id) + if err != nil { + return 0, errors.Wrapf(err, "DescribeDBInstanceAttribute err") + } + if len(ret) == 0 { + return 0, errors.Wrapf(err, "ret missing err") + } + return ret[0].MaxIops, nil +} + +func (self *SRegion) GetNetworkAddress(id string) (string, error) { + ret, err := self.GetMongoDBAttribute(id) + if err != nil { + return "", errors.Wrapf(err, "DescribeDBInstanceAttribute err") + } + addrList := make([]string, 0) + for _, v := range ret[0].ReplicaSets.ReplicaSet { + addrList = append(addrList, v.ConnectionDomain) + } + addrs := strings.Join(addrList, ",") + return addrs, nil +} + +func (self *SRegion) GetMongoDBAttribute(id string) ([]SMOngoDBAttribute, error) { + params := map[string]string{ + "Action": "DescribeDBInstanceAttribute", + "DBInstanceId": id, + } + resp, err := self.mongodbRequest("DescribeDBInstanceAttribute", params) + if err != nil { + return nil, errors.Wrapf(err, "DescribeDBInstanceAttribute err") + } + ret := []SMOngoDBAttribute{} + err = resp.Unmarshal(&ret, "DBInstances", "DBInstance") + if err != nil { + return nil, errors.Wrapf(err, "unmarshal err") + } + return ret, err +} + func (self *SRegion) GetMongoDBs(mongoType string, pageSize int, pageNum int) ([]SMongoDB, int, error) { if pageSize < 1 || pageSize > 100 { pageSize = 100 diff --git a/pkg/multicloud/aliyun/shell/mongodb.go b/pkg/multicloud/aliyun/shell/mongodb.go index 4d37945c5c..c4a1ab803c 100644 --- a/pkg/multicloud/aliyun/shell/mongodb.go +++ b/pkg/multicloud/aliyun/shell/mongodb.go @@ -49,6 +49,7 @@ func init() { } printObject(db) return nil + }) shellutils.R(&MongoDBIdOptions{}, "mongodb-delete", "Delete mongodb", func(cli *aliyun.SRegion, args *MongoDBIdOptions) error { diff --git a/pkg/multicloud/apsara/dbinstance.go b/pkg/multicloud/apsara/dbinstance.go index 2d3e617e41..d5b4e8cb8f 100644 --- a/pkg/multicloud/apsara/dbinstance.go +++ b/pkg/multicloud/apsara/dbinstance.go @@ -178,6 +178,10 @@ func (rds *SDBInstance) GetStorageType() string { return rds.DBInstanceStorageType } +func (rds *SDBInstance) GetIops() int { + return rds.MaxIOPS +} + func (rds *SDBInstance) GetEngine() string { switch rds.Engine { case "MySQL": diff --git a/pkg/multicloud/apsara/instance.go b/pkg/multicloud/apsara/instance.go index 4e790e82f8..1d08c34272 100644 --- a/pkg/multicloud/apsara/instance.go +++ b/pkg/multicloud/apsara/instance.go @@ -128,6 +128,7 @@ type SInstance struct { VlanId string VpcAttributes SVpcAttributes ZoneId string + DepartmentInfo } @@ -201,6 +202,10 @@ func (self *SInstance) GetInstanceType() string { return self.InstanceType } +func (self *SInstance) GetInternetMaxBandwidthOut() int { + return self.InternetMaxBandwidthOut +} + func (self *SInstance) getVpc() (*SVpc, error) { return self.host.zone.region.getVpc(self.VpcAttributes.VpcId) } diff --git a/pkg/multicloud/aws/instance.go b/pkg/multicloud/aws/instance.go index c2f18046eb..6206bf0484 100644 --- a/pkg/multicloud/aws/instance.go +++ b/pkg/multicloud/aws/instance.go @@ -72,31 +72,33 @@ type SInstance struct { InstanceId string ImageId string - HostName string - InstanceName string - InstanceType string - Cpu int - Memory int // MB - IoOptimized bool - KeyPairName string - CreationTime time.Time // LaunchTime - ExpiredTime time.Time - ProductCodes []string - PublicDNSName string - InnerIpAddress SIpAddress - PublicIpAddress SIpAddress - RootDeviceName string - Status string // state - VlanId string // subnet ID ? - VpcAttributes SVpcAttributes - SecurityGroupIds SSecurityGroupIds - NetworkInterfaces []SNetworkInterface - EipAddress SEipAddress - Disks []string - DeviceNames []string - OSName string - OSType string - Description string + HostName string + InstanceName string + InstanceType string + Cpu int + Memory int // MB + IoOptimized bool + KeyPairName string + CreationTime time.Time // LaunchTime + ExpiredTime time.Time + ProductCodes []string + PublicDNSName string + InnerIpAddress SIpAddress + PublicIpAddress SIpAddress + RootDeviceName string + Status string // state + VlanId string // subnet ID ? + VpcAttributes SVpcAttributes + SecurityGroupIds SSecurityGroupIds + NetworkInterfaces []SNetworkInterface + EipAddress SEipAddress + Disks []string + DeviceNames []string + OSName string + OSType string + Description string + InternetMaxBandwidthOut int + Throughput int TagSpec TagSpec @@ -241,6 +243,14 @@ func (self *SInstance) GetIHost() cloudprovider.ICloudHost { return self.host } +func (self *SInstance) GetThroughput() int { + return self.Throughput +} + +func (self *SInstance) GetInternetMaxBandwidthOut() int { + return self.InternetMaxBandwidthOut +} + func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) { disks, _, err := self.host.zone.region.GetDisks(self.InstanceId, "", "", nil, 0, 0) if err != nil { diff --git a/pkg/multicloud/dbinstance_base.go b/pkg/multicloud/dbinstance_base.go index 5642d736df..4f43befc5d 100644 --- a/pkg/multicloud/dbinstance_base.go +++ b/pkg/multicloud/dbinstance_base.go @@ -111,3 +111,7 @@ func (instance *SDBInstanceBase) CreateIBackup(conf *cloudprovider.SDBInstanceBa func (instance *SDBInstanceBase) RecoveryFromBackup(conf *cloudprovider.SDBInstanceRecoveryConfig) error { return errors.Wrapf(cloudprovider.ErrNotImplemented, "RecoveryFromBackup") } + +func (instance *SDBInstanceBase) GetIops() int { + return 0 +} diff --git a/pkg/multicloud/google/disk.go b/pkg/multicloud/google/disk.go index cf4bc1f63c..50be5571f0 100644 --- a/pkg/multicloud/google/disk.go +++ b/pkg/multicloud/google/disk.go @@ -34,6 +34,7 @@ type SDisk struct { multicloud.SDisk multicloud.GoogleTags + ProvisionedIops int CreationTimestamp time.Time SizeGB int Zone string @@ -156,6 +157,10 @@ func (disk *SDisk) GetAccessPath() string { return "" } +func (disk *SDisk) GetIops() int { + return disk.ProvisionedIops +} + func (disk *SDisk) Delete(ctx context.Context) error { return disk.storage.zone.region.Delete(disk.SelfLink) } diff --git a/pkg/multicloud/huawei/dbinstance.go b/pkg/multicloud/huawei/dbinstance.go index 7841038f56..c1d9179370 100644 --- a/pkg/multicloud/huawei/dbinstance.go +++ b/pkg/multicloud/huawei/dbinstance.go @@ -68,8 +68,7 @@ type SDBInstance struct { multicloud.HuaweiTags region *SRegion - flavorCache []SDBInstanceFlavor - + flavorCache []SDBInstanceFlavor BackupStrategy SBackupStrategy Created string //time.Time Datastore SDatastore @@ -79,6 +78,7 @@ type SDBInstance struct { Ha SHa Id string MaintenanceWindow string + MaxIops int Name string Nodes []SNonde Port int @@ -310,6 +310,10 @@ func (rds *SDBInstance) GetZone3Id() string { return "" } +func (rds *SDBInstance) GetIops() int { + return rds.MaxIops +} + type SRdsNetwork struct { SubnetId string IP string diff --git a/pkg/multicloud/instance_base.go b/pkg/multicloud/instance_base.go index 232fb39f55..95a6bb4099 100644 --- a/pkg/multicloud/instance_base.go +++ b/pkg/multicloud/instance_base.go @@ -78,3 +78,11 @@ func (self *SInstanceBase) GetOSArch() string { func (self *SInstanceBase) CreateDisk(ctx context.Context, opts *cloudprovider.GuestDiskCreateOptions) (string, error) { return "", errors.Wrapf(cloudprovider.ErrNotImplemented, "CreateDisk") } + +func (self *SInstanceBase) GetThroughput() int { + return 0 +} + +func (self *SInstanceBase) GetInternetMaxBandwidthOut() int { + return 0 +} diff --git a/pkg/multicloud/jdcloud/disk.go b/pkg/multicloud/jdcloud/disk.go index 86dc54efe0..de422cfb43 100644 --- a/pkg/multicloud/jdcloud/disk.go +++ b/pkg/multicloud/jdcloud/disk.go @@ -62,6 +62,10 @@ func (d *SDisk) GetGlobalId() string { return d.GetId() } +func (d *SDisk) GetIops() int { + return d.Iops +} + func (d *SDisk) GetStatus() string { switch d.Status { case "available", "in-use": diff --git a/pkg/multicloud/qcloud/mongodb.go b/pkg/multicloud/qcloud/mongodb.go index 27d68ba01b..7fa741057b 100644 --- a/pkg/multicloud/qcloud/mongodb.go +++ b/pkg/multicloud/qcloud/mongodb.go @@ -37,6 +37,8 @@ type SMongoDB struct { multicloud.SBillingBase region *SRegion + IOPS int + NetworkAddress string AutoRenewFlag int `json:"AutoRenewFlag"` CloneInstances []interface{} `json:"CloneInstances"` ClusterType int `json:"ClusterType"` @@ -299,6 +301,14 @@ func (self *SRegion) GetMongoDBs(ids []string, limit, offset int) ([]SMongoDB, i return dbs, int(totalCount), nil } +func (self *SMongoDB) GetIops() int { + return self.IOPS +} + +func (self *SMongoDB) GetNetworkAddress() string { + return self.NetworkAddress +} + func (self *SRegion) GetICloudMongoDBs() ([]cloudprovider.ICloudMongoDB, error) { dbs := []SMongoDB{} for { diff --git a/pkg/multicloud/qcloud/rds_tdsql.go b/pkg/multicloud/qcloud/rds_tdsql.go index 2315a034d3..f0e4b33ceb 100644 --- a/pkg/multicloud/qcloud/rds_tdsql.go +++ b/pkg/multicloud/qcloud/rds_tdsql.go @@ -29,8 +29,8 @@ import ( ) type STDSQL struct { - multicloud.SVirtualResourceBase - multicloud.SBillingBase + multicloud.SDBInstanceBase + // multicloud.SBillingBase multicloud.QcloudTags region *SRegion