mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
fix(region): vendor update (#25026)
This commit is contained in:
@@ -108,7 +108,7 @@ require (
|
||||
k8s.io/cri-api v0.28.15
|
||||
k8s.io/klog/v2 v2.90.1
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260613033805-ca0f41989760
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260615063032-12f801ccaf01
|
||||
yunion.io/x/executor v0.0.0-20260312022053-f538abd2b005
|
||||
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
@@ -1785,8 +1785,8 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260613033805-ca0f41989760 h1:2C7wz33wPgvtqBHA9BwrmLRLDPZc9ZGVLrLL0r1A7eo=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260613033805-ca0f41989760/go.mod h1:TbMuTWxcTdyL2Usn+WQdIw0jdlBYO66SzPRY8LZ3Wj0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260615063032-12f801ccaf01 h1:iuP8J8uMLcCLWSkCMxY7FQa3m3VouwftS266quUyvzk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260615063032-12f801ccaf01/go.mod h1:TbMuTWxcTdyL2Usn+WQdIw0jdlBYO66SzPRY8LZ3Wj0=
|
||||
yunion.io/x/executor v0.0.0-20260312022053-f538abd2b005 h1:3sWwcjGXGjG9mLBWa7AyLq+QSi0udTAx21pfVQRFMBE=
|
||||
yunion.io/x/executor v0.0.0-20260312022053-f538abd2b005/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -43,4 +43,6 @@ const (
|
||||
CNWARE = "cnware"
|
||||
KSYUN = "ksyun"
|
||||
ECLOUD = "ecloud"
|
||||
ROCKBASE = "rockbase"
|
||||
UCLOUD = "ucloud"
|
||||
)
|
||||
|
||||
@@ -19,13 +19,17 @@ import (
|
||||
)
|
||||
|
||||
type RockbaseCollect struct {
|
||||
SBaseCollectDriver
|
||||
SCollectByResourceIdDriver
|
||||
}
|
||||
|
||||
func (self *RockbaseCollect) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_ROCKBASE
|
||||
}
|
||||
|
||||
func (self *RockbaseCollect) IsSupportMetrics() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(&RockbaseCollect{})
|
||||
}
|
||||
|
||||
@@ -19,13 +19,17 @@ import (
|
||||
)
|
||||
|
||||
type UcloudCollect struct {
|
||||
SBaseCollectDriver
|
||||
SCollectByResourceIdDriver
|
||||
}
|
||||
|
||||
func (self *UcloudCollect) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_UCLOUD
|
||||
}
|
||||
|
||||
func (self *UcloudCollect) IsSupportMetrics() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(&UcloudCollect{})
|
||||
}
|
||||
|
||||
@@ -134,3 +134,7 @@ func (rockbase *SRockbaseGuestDriver) ValidateGuestChangeConfigInput(ctx context
|
||||
|
||||
return confs, nil
|
||||
}
|
||||
|
||||
func (self *SRockbaseGuestDriver) IsNeedCleanDisksAfterUndeploy() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -134,3 +134,7 @@ func (ucloud *SUCloudGuestDriver) ValidateGuestChangeConfigInput(ctx context.Con
|
||||
|
||||
return confs, nil
|
||||
}
|
||||
|
||||
func (self *SUCloudGuestDriver) IsNeedCleanDisksAfterUndeploy() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ func handleServerRemoteConsole(ctx context.Context, w http.ResponseWriter, r *ht
|
||||
session.VMRC, session.ZSTACK, session.CTYUN,
|
||||
session.HUAWEI, session.HCS, session.APSARA,
|
||||
session.JDCLOUD, session.CLOUDPODS, session.PROXMOX,
|
||||
session.VOLCENGINE, session.BAIDU, session.CNWARE, session.KSYUN, session.ECLOUD:
|
||||
session.VOLCENGINE, session.BAIDU, session.CNWARE, session.KSYUN, session.ECLOUD, session.ROCKBASE, session.UCLOUD:
|
||||
responsePublicCloudConsole(ctx, info, w)
|
||||
case session.VNC:
|
||||
handleDataSession(ctx, info, w, "no-vnc", url.Values{"password": {info.GetPassword()}}, true)
|
||||
|
||||
@@ -56,6 +56,8 @@ const (
|
||||
CNWARE = api.CNWARE
|
||||
KSYUN = api.KSYUN
|
||||
ECLOUD = api.ECLOUD
|
||||
ROCKBASE = api.ROCKBASE
|
||||
UCLOUD = api.UCLOUD
|
||||
)
|
||||
|
||||
type RemoteConsoleInfo struct {
|
||||
@@ -138,7 +140,7 @@ func (info *RemoteConsoleInfo) GetConnectParams() (string, error) {
|
||||
return info.getQcloudURL()
|
||||
case CLOUDPODS:
|
||||
return info.getCloudpodsURL()
|
||||
case OPENSTACK, VMRC, ZSTACK, CTYUN, HUAWEI, HCS, JDCLOUD, PROXMOX, SANGFOR, BAIDU, CNWARE, KSYUN, ECLOUD:
|
||||
case OPENSTACK, VMRC, ZSTACK, CTYUN, HUAWEI, HCS, JDCLOUD, PROXMOX, SANGFOR, BAIDU, CNWARE, KSYUN, ECLOUD, ROCKBASE, UCLOUD:
|
||||
return info.Url, nil
|
||||
case VOLCENGINE:
|
||||
return info.getVolcEngineURL()
|
||||
|
||||
Vendored
+1
-1
@@ -2603,7 +2603,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.3.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260613033805-ca0f41989760
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20260615063032-12f801ccaf01
|
||||
## explicit; go 1.24
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+13
-10
@@ -38,7 +38,7 @@ type SDisk struct {
|
||||
|
||||
Status string `json:"Status"`
|
||||
DeviceName string `json:"DeviceName"`
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
Tag string `json:"Tag"`
|
||||
Version string `json:"Version"`
|
||||
Name string `json:"Name"`
|
||||
@@ -50,7 +50,7 @@ type SDisk struct {
|
||||
ExpiredTime int64 `json:"ExpiredTime"`
|
||||
SnapshotCount int `json:"SnapshotCount"`
|
||||
IsExpire string `json:"IsExpire"`
|
||||
UDiskID string `json:"UDiskId"`
|
||||
UDiskId string `json:"UDiskId"`
|
||||
ChargeType string `json:"ChargeType"`
|
||||
UHostName string `json:"UHostName"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
@@ -62,7 +62,7 @@ func (self *SDisk) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetId() string {
|
||||
return self.UDiskID
|
||||
return self.UDiskId
|
||||
}
|
||||
|
||||
func (self *SDisk) GetName() string {
|
||||
@@ -136,7 +136,10 @@ func (self *SDisk) GetCreatedAt() time.Time {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetExpiredAt() time.Time {
|
||||
return time.Unix(self.ExpiredTime, 0)
|
||||
if strings.EqualFold(self.ChargeType, "Year") || strings.EqualFold(self.ChargeType, "Month") {
|
||||
return time.Unix(self.ExpiredTime, 0)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
@@ -160,12 +163,12 @@ func (self *SDisk) GetIsAutoDelete() bool {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetTemplateId() string {
|
||||
if strings.Contains(self.DiskType, "SystemDisk") && len(self.UHostID) > 0 {
|
||||
ins, err := self.storage.zone.region.GetInstance(self.UHostID)
|
||||
if strings.Contains(self.DiskType, "SystemDisk") && len(self.UHostId) > 0 {
|
||||
ins, err := self.storage.zone.region.GetInstance(self.UHostId)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return ins.ImageID
|
||||
return ins.ImageId
|
||||
}
|
||||
|
||||
return ""
|
||||
@@ -271,12 +274,12 @@ func (self *SDisk) Resize(ctx context.Context, newSizeMB int64) error {
|
||||
}
|
||||
|
||||
if self.Status == "InUse" {
|
||||
err := self.storage.zone.region.DetachDisk(self.Zone, self.UHostID, self.UDiskID)
|
||||
err := self.storage.zone.region.DetachDisk(self.Zone, self.UHostId, self.UDiskId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer self.storage.zone.region.AttachDisk(self.Zone, self.UHostID, self.UDiskID)
|
||||
defer self.storage.zone.region.AttachDisk(self.Zone, self.UHostId, self.UDiskId)
|
||||
err = cloudprovider.WaitStatusWithDelay(self, api.DISK_READY, 10*time.Second, 5*time.Second, 60*time.Second)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DiskResize")
|
||||
@@ -306,7 +309,7 @@ func (self *SRegion) GetDisk(diskId string) (*SDisk, error) {
|
||||
}
|
||||
|
||||
for i := range disks {
|
||||
if disks[i].UDiskID == diskId {
|
||||
if disks[i].UDiskId == diskId {
|
||||
return &disks[i], nil
|
||||
}
|
||||
}
|
||||
|
||||
+10
-7
@@ -44,7 +44,7 @@ type SEip struct {
|
||||
ChargeType string `json:"ChargeType"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
EIPAddr []EIPAddr `json:"EIPAddr"`
|
||||
EIPID string `json:"EIPId"`
|
||||
EIPId string `json:"EIPId"`
|
||||
Expire bool `json:"Expire"`
|
||||
ExpireTime int64 `json:"ExpireTime"`
|
||||
Name string `json:"Name"`
|
||||
@@ -67,7 +67,7 @@ type EIPAddr struct {
|
||||
}
|
||||
|
||||
type Resource struct {
|
||||
ResourceID string `json:"ResourceID"`
|
||||
ResourceId string `json:"ResourceID"`
|
||||
ResourceName string `json:"ResourceName"`
|
||||
ResourceType string `json:"ResourceType"`
|
||||
Zone string `json:"Zone"`
|
||||
@@ -75,12 +75,12 @@ type Resource struct {
|
||||
|
||||
type ShareBandwidthSet struct {
|
||||
ShareBandwidth int `json:"ShareBandwidth"`
|
||||
ShareBandwidthID string `json:"ShareBandwidthId"`
|
||||
ShareBandwidthId string `json:"ShareBandwidthId"`
|
||||
ShareBandwidthName string `json:"ShareBandwidthName"`
|
||||
}
|
||||
|
||||
func (self *SEip) GetId() string {
|
||||
return self.EIPID
|
||||
return self.EIPId
|
||||
}
|
||||
|
||||
func (self *SEip) GetName() string {
|
||||
@@ -139,7 +139,10 @@ func (self *SEip) GetCreatedAt() time.Time {
|
||||
}
|
||||
|
||||
func (self *SEip) GetExpiredAt() time.Time {
|
||||
return time.Unix(self.ExpireTime, 0)
|
||||
if strings.EqualFold(self.ChargeType, "Year") || strings.EqualFold(self.ChargeType, "Month") {
|
||||
return time.Unix(self.ExpireTime, 0)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SEip) GetIpAddr() string {
|
||||
@@ -171,7 +174,7 @@ func (self *SEip) GetAssociationType() string {
|
||||
|
||||
// 已绑定的资源类型, 枚举值为: uhost, 云主机;natgw:NAT网关;ulb:负载均衡器;upm: 物理机; hadoophost: 大数据集群;fortresshost:堡垒机;udockhost:容器;udhost:私有专区主机;vpngw:IPSec VPN;ucdr:云灾备;dbaudit:数据库审计。
|
||||
func (self *SEip) GetAssociationExternalId() string {
|
||||
return self.Resource.ResourceID
|
||||
return self.Resource.ResourceId
|
||||
}
|
||||
|
||||
func (self *SEip) GetBandwidth() int {
|
||||
@@ -203,7 +206,7 @@ func (self *SEip) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
}
|
||||
|
||||
func (self *SEip) Dissociate() error {
|
||||
return self.region.DissociateEip(self.GetId(), self.Resource.ResourceID)
|
||||
return self.region.DissociateEip(self.GetId(), self.Resource.ResourceId)
|
||||
}
|
||||
|
||||
func (self *SEip) ChangeBandwidth(bw int) error {
|
||||
|
||||
+36
-2
@@ -20,6 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/imagetools"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
@@ -38,7 +39,7 @@ type SImage struct {
|
||||
Zone string `json:"Zone"`
|
||||
ImageDescription string `json:"ImageDescription"`
|
||||
OSName string `json:"OsName"`
|
||||
ImageID string `json:"ImageId"`
|
||||
ImageId string `json:"ImageId"`
|
||||
State string `json:"State"`
|
||||
ImageName string `json:"ImageName"`
|
||||
OSType string `json:"OsType"`
|
||||
@@ -52,7 +53,7 @@ func (self *SImage) GetMinRamSizeMb() int {
|
||||
}
|
||||
|
||||
func (self *SImage) GetId() string {
|
||||
return self.ImageID
|
||||
return self.ImageId
|
||||
}
|
||||
|
||||
func (self *SImage) GetName() string {
|
||||
@@ -226,3 +227,36 @@ func (self *SRegion) DeleteImage(imageId string) error {
|
||||
|
||||
return self.DoAction("TerminateCustomImage", params, nil)
|
||||
}
|
||||
|
||||
// https://docs.ucloud.cn/api/uhost-api/create_custom_image
|
||||
func (self *SRegion) SaveImage(instanceId string, opts *cloudprovider.SaveImageOptions) (*SImage, error) {
|
||||
params := NewRockbaseParams()
|
||||
params.Set("UHostId", instanceId)
|
||||
params.Set("ImageName", opts.Name)
|
||||
if len(opts.Notes) > 0 {
|
||||
params.Set("ImageDescription", opts.Notes)
|
||||
}
|
||||
|
||||
ret := struct {
|
||||
ImageId string
|
||||
}{}
|
||||
err := self.DoAction("CreateCustomImage", params, &ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateCustomImage")
|
||||
}
|
||||
if len(ret.ImageId) == 0 {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "CreateCustomImage empty ImageId")
|
||||
}
|
||||
|
||||
image, err := self.GetImage(ret.ImageId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetImage(%s)", ret.ImageId)
|
||||
}
|
||||
image.storageCache = self.getStoragecache()
|
||||
img := &image
|
||||
err = cloudprovider.WaitStatus(img, api.CACHED_IMAGE_STATUS_ACTIVE, 10*time.Second, 30*time.Minute)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "wait image ready")
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
+30
-20
@@ -42,12 +42,12 @@ type SInstance struct {
|
||||
|
||||
osInfo *imagetools.ImageInfo
|
||||
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
Zone string `json:"Zone"`
|
||||
LifeCycle string `json:"LifeCycle"`
|
||||
OSName string `json:"OsName"`
|
||||
ImageID string `json:"ImageId"`
|
||||
BasicImageID string `json:"BasicImageId"`
|
||||
ImageId string `json:"ImageId"`
|
||||
BasicImageId string `json:"BasicImageId"`
|
||||
BasicImageName string `json:"BasicImageName"`
|
||||
Tag string `json:"Tag"`
|
||||
Name string `json:"Name"`
|
||||
@@ -102,7 +102,7 @@ func (self *SInstance) GetError() error {
|
||||
}
|
||||
|
||||
type DiskSet struct {
|
||||
DiskID string `json:"DiskId"`
|
||||
DiskId string `json:"DiskId"`
|
||||
DiskType string `json:"DiskType"`
|
||||
Drive string `json:"Drive"`
|
||||
IsBoot bool `json:"IsBoot"`
|
||||
@@ -117,19 +117,19 @@ type IPSet struct {
|
||||
IPId string `json:"IPId"` // IP资源ID (内网IP无对应的资源ID)
|
||||
MAC string `json:"Mac"`
|
||||
VpcId string `json:"VPCId"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
SubnetId string `json:"SubnetId"`
|
||||
}
|
||||
|
||||
type SVncInfo struct {
|
||||
VNCIP string `json:"VncIP"`
|
||||
VNCPassword string `json:"VncPassword"`
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
Action string `json:"Action"`
|
||||
VNCPort int64 `json:"VncPort"`
|
||||
}
|
||||
|
||||
func (self *SInstance) GetId() string {
|
||||
return self.UHostID
|
||||
return self.UHostId
|
||||
}
|
||||
|
||||
func (self *SInstance) GetName() string {
|
||||
@@ -177,13 +177,14 @@ func (self *SInstance) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) Refresh() error {
|
||||
new, err := self.host.zone.region.GetInstance(self.GetId())
|
||||
vm, err := self.host.zone.region.GetInstance(self.GetId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
new.host = self.host
|
||||
return jsonutils.Update(self, new)
|
||||
self.DiskSet = nil
|
||||
self.IPSet = nil
|
||||
self.osInfo = nil
|
||||
return jsonutils.Update(self, vm)
|
||||
}
|
||||
|
||||
// 计费模式,枚举值为: Year,按年付费; Month,按月付费; Dynamic,按需付费(需开启权限);
|
||||
@@ -201,10 +202,9 @@ func (self *SInstance) GetCreatedAt() time.Time {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetExpiredAt() time.Time {
|
||||
if self.AutoRenew != "Yes" {
|
||||
if strings.EqualFold(self.ChargeType, "Year") || strings.EqualFold(self.ChargeType, "Month") {
|
||||
return time.Unix(self.ExpireTime, 0)
|
||||
}
|
||||
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
@@ -221,11 +221,11 @@ func (self *SInstance) GetLocalDisk(diskId, storageType string, sizeGB int, isBo
|
||||
disk := SDisk{
|
||||
SDisk: multicloud.SDisk{},
|
||||
Status: "Available",
|
||||
UHostID: self.GetId(),
|
||||
UHostId: self.GetId(),
|
||||
Name: diskId,
|
||||
Zone: self.host.zone.GetId(),
|
||||
DiskType: diskType,
|
||||
UDiskID: diskId,
|
||||
UDiskId: diskId,
|
||||
UHostName: self.GetName(),
|
||||
CreateTime: self.CreateTime,
|
||||
SizeGB: sizeGB,
|
||||
@@ -240,10 +240,10 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
disks := []SDisk{}
|
||||
for _, disk := range self.DiskSet {
|
||||
if utils.IsInStringArray(disk.DiskType, []string{api.STORAGE_ROCKBASE_LOCAL_NORMAL, api.STORAGE_ROCKBASE_LOCAL_SSD}) {
|
||||
localDisks = append(localDisks, self.GetLocalDisk(disk.DiskID, disk.DiskType, disk.Size, disk.IsBoot))
|
||||
localDisks = append(localDisks, self.GetLocalDisk(disk.DiskId, disk.DiskType, disk.Size, disk.IsBoot))
|
||||
continue
|
||||
}
|
||||
disk, err := self.host.zone.region.GetDisk(disk.DiskID)
|
||||
disk, err := self.host.zone.region.GetDisk(disk.DiskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -280,7 +280,7 @@ func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
|
||||
nics := make([]cloudprovider.ICloudNic, 0)
|
||||
|
||||
for _, ip := range self.IPSet {
|
||||
if len(ip.SubnetID) == 0 {
|
||||
if len(ip.SubnetId) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -455,8 +455,8 @@ func (self *SInstance) RebuildRoot(ctx context.Context, desc *cloudprovider.SMan
|
||||
}
|
||||
|
||||
for _, disk := range self.DiskSet {
|
||||
if disk.Type == "SystemDisk" {
|
||||
return disk.DiskID, nil
|
||||
if strings.EqualFold(disk.Type, "SystemDisk") || strings.EqualFold(disk.Type, "Boot") {
|
||||
return disk.DiskId, nil
|
||||
}
|
||||
}
|
||||
return "", errors.Wrapf(cloudprovider.ErrNotFound, "SystemDisk not found")
|
||||
@@ -506,6 +506,14 @@ func (self *SInstance) ChangeConfig2(ctx context.Context, instanceType string) e
|
||||
return self.host.zone.region.ResizeVM(self.GetId(), i.CPU, i.MemoryMB)
|
||||
}
|
||||
|
||||
func (self *SInstance) SaveImage(opts *cloudprovider.SaveImageOptions) (cloudprovider.ICloudImage, error) {
|
||||
image, err := self.host.zone.region.SaveImage(self.GetId(), opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "SaveImage")
|
||||
}
|
||||
return image, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) GetVNCInfo(input *cloudprovider.ServerVncInput) (*cloudprovider.ServerVncOutput, error) {
|
||||
return self.host.zone.region.GetInstanceVNCUrl(self.GetId())
|
||||
}
|
||||
@@ -558,6 +566,8 @@ func (self *SRegion) GetInstanceVNCUrl(instanceId string) (*cloudprovider.Server
|
||||
Port: vnc.VNCPort,
|
||||
Password: vnc.VNCPassword,
|
||||
Hypervisor: api.HYPERVISOR_ROCKBASE,
|
||||
Protocol: "vnc",
|
||||
InstanceId: instanceId,
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ func (self *SInstanceNic) InClassicNetwork() bool {
|
||||
func (self *SInstanceNic) GetINetworkId() string {
|
||||
for _, ip := range self.instance.IPSet {
|
||||
if ip.IP == self.ipAddr {
|
||||
return ip.SubnetID
|
||||
return ip.SubnetId
|
||||
}
|
||||
}
|
||||
return ""
|
||||
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
// 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 rockbase
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
const (
|
||||
// https://docs.ucloud.cn/cloudwatch/metric/intro
|
||||
ROCKBASE_PRODUCT_KEY_UHOST = "uhost"
|
||||
)
|
||||
|
||||
type SMetricSample struct {
|
||||
Timestamp int64
|
||||
Value float64
|
||||
}
|
||||
|
||||
type SMetricResult struct {
|
||||
ResourceId string
|
||||
ResourceName string
|
||||
TagMap map[string]string
|
||||
Values []SMetricSample
|
||||
}
|
||||
|
||||
type SQueryMetricDataItem struct {
|
||||
Metric string
|
||||
Results []SMetricResult
|
||||
}
|
||||
|
||||
type SQueryMetricDataResp struct {
|
||||
InvalidResourceIds []string
|
||||
List []SQueryMetricDataItem
|
||||
}
|
||||
|
||||
var uhostMetricNames = map[cloudprovider.TMetricType]string{
|
||||
cloudprovider.VM_METRIC_TYPE_CPU_USAGE: "uhost_cpu_used",
|
||||
cloudprovider.VM_METRIC_TYPE_MEM_USAGE: "cloudwatch_memory_usage",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_USAGE: "cloudwatch_sys_disk_used_per",
|
||||
cloudprovider.VM_METRIC_TYPE_NET_BPS_RX: "uhost_net_in_flow",
|
||||
cloudprovider.VM_METRIC_TYPE_NET_BPS_TX: "uhost_net_out_flow",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_BPS: "uhost_disk_read",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_BPS: "uhost_disk_write",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_IOPS: "uhost_disk_read_times",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_IOPS: "uhost_disk_write_times",
|
||||
}
|
||||
|
||||
var uhostMetricNameTypes map[string]cloudprovider.TMetricType
|
||||
|
||||
func init() {
|
||||
uhostMetricNameTypes = make(map[string]cloudprovider.TMetricType, len(uhostMetricNames))
|
||||
for metricType, name := range uhostMetricNames {
|
||||
uhostMetricNameTypes[name] = metricType
|
||||
}
|
||||
}
|
||||
|
||||
func pickMetricPeriod(start, end time.Time, interval int) int {
|
||||
if interval > 0 {
|
||||
return interval
|
||||
}
|
||||
d := end.Sub(start)
|
||||
switch {
|
||||
case d <= time.Hour:
|
||||
return 60
|
||||
case d <= 12*time.Hour:
|
||||
return 60
|
||||
case d <= 24*time.Hour:
|
||||
return 300
|
||||
default:
|
||||
return 3600
|
||||
}
|
||||
}
|
||||
|
||||
// https://docs.ucloud.cn/api/cloudwatch-api/query_metric_data_set
|
||||
func (self *SRegion) QueryMetricDataSet(productKey string, resourceIds []string, metricNames []string, start, end time.Time, period int) (*SQueryMetricDataResp, error) {
|
||||
params := NewRockbaseParams()
|
||||
params.Set("Region", self.GetId())
|
||||
params.Set("ProductKey", productKey)
|
||||
params.Set("StartTime", int(start.Unix()))
|
||||
params.Set("EndTime", int(end.Unix()))
|
||||
params.Set("CalcMethod", "avg")
|
||||
params.Set("Period", period)
|
||||
|
||||
idx := 0
|
||||
for _, resourceId := range resourceIds {
|
||||
for _, metricName := range metricNames {
|
||||
params.Set(fmt.Sprintf("MetricInfos.%d.Metric", idx), metricName)
|
||||
params.Set(fmt.Sprintf("MetricInfos.%d.ResourceId", idx), resourceId)
|
||||
idx++
|
||||
}
|
||||
}
|
||||
if idx == 0 {
|
||||
return nil, errors.Wrap(cloudprovider.ErrMissingParameter, "metric infos")
|
||||
}
|
||||
|
||||
params = self.client.commonParams(params)
|
||||
params.SetAction("QueryMetricDataSet")
|
||||
resp, err := jsonRequest(self.client, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "QueryMetricDataSet")
|
||||
}
|
||||
ret := SQueryMetricDataResp{}
|
||||
err = resp.Unmarshal(&ret, "Data")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unmarshal Data")
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetUhostMetrics(resourceIds []string, start, end time.Time, interval int) ([]cloudprovider.MetricValues, error) {
|
||||
metricNames := make([]string, 0, len(uhostMetricNames))
|
||||
for _, name := range uhostMetricNames {
|
||||
metricNames = append(metricNames, name)
|
||||
}
|
||||
period := pickMetricPeriod(start, end, interval)
|
||||
data, err := self.QueryMetricDataSet(ROCKBASE_PRODUCT_KEY_UHOST, resourceIds, metricNames, start, end, period)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "QueryMetricDataSet")
|
||||
}
|
||||
ret := []cloudprovider.MetricValues{}
|
||||
for _, item := range data.List {
|
||||
metricType, ok := uhostMetricNameTypes[item.Metric]
|
||||
if !ok {
|
||||
log.Warningf("unknown uhost metric %s", item.Metric)
|
||||
continue
|
||||
}
|
||||
for _, result := range item.Results {
|
||||
metric := cloudprovider.MetricValues{
|
||||
Id: result.ResourceId,
|
||||
MetricType: metricType,
|
||||
Values: []cloudprovider.MetricValue{},
|
||||
}
|
||||
for _, sample := range result.Values {
|
||||
value := sample.Value
|
||||
switch metricType {
|
||||
case cloudprovider.VM_METRIC_TYPE_NET_BPS_RX, cloudprovider.VM_METRIC_TYPE_NET_BPS_TX:
|
||||
// uhost network metrics unit is bps (bits per second)
|
||||
value = value / 8.0
|
||||
}
|
||||
metric.Values = append(metric.Values, cloudprovider.MetricValue{
|
||||
Timestamp: time.Unix(sample.Timestamp, 0),
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
if len(metric.Values) > 0 {
|
||||
ret = append(ret, metric)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRockbaseClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
switch opts.ResourceType {
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
|
||||
return self.GetEcsMetrics(opts)
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.ResourceType)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SRockbaseClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
region := self.GetRegion(opts.RegionExtId)
|
||||
if region == nil {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "region %s", opts.RegionExtId)
|
||||
}
|
||||
resourceIds := opts.ResourceIds
|
||||
if len(resourceIds) == 0 && len(opts.ResourceId) > 0 {
|
||||
resourceIds = []string{opts.ResourceId}
|
||||
}
|
||||
if len(resourceIds) == 0 {
|
||||
return nil, errors.Wrap(cloudprovider.ErrMissingParameter, "resource_id")
|
||||
}
|
||||
return region.GetUhostMetrics(resourceIds, opts.StartTime, opts.EndTime, opts.Interval)
|
||||
}
|
||||
+5
-5
@@ -40,15 +40,15 @@ type SNetwork struct {
|
||||
Name string `json:"Name"`
|
||||
Netmask string `json:"Netmask"`
|
||||
Remark string `json:"Remark"`
|
||||
RouteTableID string `json:"RouteTableId"`
|
||||
RouteTableId string `json:"RouteTableId"`
|
||||
Subnet string `json:"Subnet"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
SubnetId string `json:"SubnetId"`
|
||||
SubnetName string `json:"SubnetName"`
|
||||
SubnetType int `json:"SubnetType"`
|
||||
Tag string `json:"Tag"`
|
||||
VpcId string `json:"VPCId"`
|
||||
VPCName string `json:"VPCName"`
|
||||
VRouterID string `json:"VRouterId"`
|
||||
VRouterId string `json:"VRouterId"`
|
||||
Zone string `json:"Zone"`
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (self *SNetwork) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetId() string {
|
||||
return self.SubnetID
|
||||
return self.SubnetId
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetName() string {
|
||||
@@ -153,7 +153,7 @@ func (self *SRegion) getNetwork(networkId string) (*SNetwork, error) {
|
||||
}
|
||||
|
||||
for i := range networks {
|
||||
if networks[i].SubnetID == networkId {
|
||||
if networks[i].SubnetId == networkId {
|
||||
vpc, err := self.GetVpc(networks[i].VpcId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+3
-3
@@ -22,9 +22,9 @@ import (
|
||||
type SProject struct {
|
||||
multicloud.SProjectBase
|
||||
RockbaseTags
|
||||
ProjectID string `json:"ProjectId"`
|
||||
ProjectId string `json:"ProjectId"`
|
||||
ProjectName string `json:"ProjectName"`
|
||||
ParentID string `json:"ParentId"`
|
||||
ParentId string `json:"ParentId"`
|
||||
ParentName string `json:"ParentName"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
IsDefault bool `json:"IsDefault"`
|
||||
@@ -33,7 +33,7 @@ type SProject struct {
|
||||
}
|
||||
|
||||
func (self *SProject) GetId() string {
|
||||
return self.ProjectID
|
||||
return self.ProjectId
|
||||
}
|
||||
|
||||
func (self *SProject) GetName() string {
|
||||
|
||||
+4
@@ -188,3 +188,7 @@ func (self *SRockbaseProvider) GetObjectCannedAcls(regionId string) []string {
|
||||
func (self *SRockbaseProvider) GetCapabilities() []string {
|
||||
return self.client.GetCapabilities()
|
||||
}
|
||||
|
||||
func (self *SRockbaseProvider) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
return self.client.GetMetrics(opts)
|
||||
}
|
||||
|
||||
+5
-5
@@ -30,7 +30,7 @@ type SRegion struct {
|
||||
multicloud.SNoLbRegion
|
||||
client *SRockbaseClient
|
||||
|
||||
RegionID string `json:"Region"`
|
||||
RegionId string `json:"Region"`
|
||||
LocalName string `json:"LocalName"`
|
||||
CountryCode string `json:"CountryCode"`
|
||||
Category string `json:"Category"`
|
||||
@@ -39,7 +39,7 @@ type SRegion struct {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetId() string {
|
||||
return self.RegionID
|
||||
return self.RegionId
|
||||
}
|
||||
|
||||
func (self *SRegion) GetName() string {
|
||||
@@ -154,7 +154,7 @@ func (self *SRegion) GetEip(eipId string) (*SEip, error) {
|
||||
}
|
||||
|
||||
for i := range eips {
|
||||
if eips[i].EIPID == eipId {
|
||||
if eips[i].EIPId == eipId {
|
||||
eips[i].region = self
|
||||
return &eips[i], nil
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func (self *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSn
|
||||
}
|
||||
|
||||
for i := range snapshots {
|
||||
if snapshots[i].SnapshotID == snapshotId {
|
||||
if snapshots[i].SnapshotId == snapshotId {
|
||||
snapshot := snapshots[i]
|
||||
snapshot.region = self
|
||||
return &snapshot, nil
|
||||
@@ -398,7 +398,7 @@ func (self *SRegion) GetInstance(instanceId string) (*SInstance, error) {
|
||||
}
|
||||
|
||||
for i := range instances {
|
||||
if instances[i].UHostID == instanceId {
|
||||
if instances[i].UHostId == instanceId {
|
||||
return &instances[i], nil
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -271,10 +271,10 @@ func (self *SRockbaseClient) GetSubAccounts() ([]cloudprovider.SSubAccount, erro
|
||||
subAccounts := make([]cloudprovider.SSubAccount, 0)
|
||||
for _, project := range projects {
|
||||
subAccount := cloudprovider.SSubAccount{}
|
||||
subAccount.Id = project.ProjectID
|
||||
subAccount.Id = project.ProjectId
|
||||
subAccount.Name = fmt.Sprintf("%s-%s", self.cpcfg.Name, project.ProjectName)
|
||||
// ucloud账号ID中可能包含/。因此使用::作为分割符号
|
||||
subAccount.Account = fmt.Sprintf("%s::%s", self.accessKeyId, project.ProjectID)
|
||||
subAccount.Account = fmt.Sprintf("%s::%s", self.accessKeyId, project.ProjectId)
|
||||
subAccount.HealthStatus = api.CLOUD_PROVIDER_HEALTH_NORMAL
|
||||
|
||||
subAccounts = append(subAccounts, subAccount)
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ func (self *SecurityGroupRule) GetPriority() int {
|
||||
|
||||
func (self *SecurityGroupRule) Delete() error {
|
||||
params := NewRockbaseParams()
|
||||
params.Set("FWId", self.secgroup.FWID)
|
||||
params.Set("FWId", self.secgroup.FWId)
|
||||
idx := 0
|
||||
for _, rule := range self.secgroup.Rule {
|
||||
if rule.GetGlobalId() == self.GetGlobalId() {
|
||||
|
||||
+5
-5
@@ -34,8 +34,8 @@ type SSecurityGroup struct {
|
||||
region *SRegion
|
||||
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
FWID string `json:"FWId"`
|
||||
GroupID string `json:"GroupId"`
|
||||
FWId string `json:"FWId"`
|
||||
GroupId string `json:"GroupId"`
|
||||
Name string `json:"Name"`
|
||||
Remark string `json:"Remark"`
|
||||
ResourceCount int `json:"ResourceCount"`
|
||||
@@ -49,7 +49,7 @@ func (self *SSecurityGroup) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetId() string {
|
||||
return self.FWID
|
||||
return self.FWId
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetName() string {
|
||||
@@ -133,7 +133,7 @@ func (self *SRegion) CreateSecurityGroup(name, description string) (string, erro
|
||||
|
||||
func (self *SSecurityGroup) CreateRule(opts *cloudprovider.SecurityGroupRuleCreateOptions) (cloudprovider.ISecurityGroupRule, error) {
|
||||
params := NewRockbaseParams()
|
||||
params.Set("FWId", self.FWID)
|
||||
params.Set("FWId", self.FWId)
|
||||
idx := 0
|
||||
for _, rule := range self.Rule {
|
||||
params.Set(fmt.Sprintf("Rule.%d", idx), rule.String())
|
||||
@@ -210,5 +210,5 @@ func (self *SRegion) GetSecurityGroups(secGroupId string, resourceId string, nam
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) Delete() error {
|
||||
return self.region.DeleteSecurityGroup(self.FWID)
|
||||
return self.region.DeleteSecurityGroup(self.FWId)
|
||||
}
|
||||
|
||||
+7
-7
@@ -36,15 +36,15 @@ type SSnapshot struct {
|
||||
Name string `json:"Name"`
|
||||
UDiskName string `json:"UDiskName"`
|
||||
ExpiredTime int64 `json:"ExpiredTime"`
|
||||
UDiskID string `json:"UDiskId"`
|
||||
SnapshotID string `json:"SnapshotId"`
|
||||
UDiskId string `json:"UDiskId"`
|
||||
SnapshotId string `json:"SnapshotId"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
SizeGB int32 `json:"Size"`
|
||||
Status string `json:"Status"`
|
||||
IsUDiskAvailable bool `json:"IsUDiskAvailable"`
|
||||
Version string `json:"Version"`
|
||||
DiskType int `json:"DiskType"`
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
@@ -52,7 +52,7 @@ func (self *SSnapshot) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetId() string {
|
||||
return self.SnapshotID
|
||||
return self.SnapshotId
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetName() string {
|
||||
@@ -82,7 +82,7 @@ func (self *SSnapshot) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) Refresh() error {
|
||||
disk, err := self.region.GetDisk(self.UDiskID)
|
||||
disk, err := self.region.GetDisk(self.UDiskId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (self *SSnapshot) GetSizeMb() int32 {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetDiskId() string {
|
||||
return self.UDiskID
|
||||
return self.UDiskId
|
||||
}
|
||||
|
||||
// 磁盘类型,0:数据盘,1:系统盘
|
||||
@@ -123,7 +123,7 @@ func (self *SSnapshot) GetDiskType() string {
|
||||
// https://docs.ucloud.cn/api/udisk-api/delete_udisk_snapshot
|
||||
func (self *SSnapshot) Delete() error {
|
||||
zoneId := ""
|
||||
idisk, err := self.region.GetDisk(self.UDiskID)
|
||||
idisk, err := self.region.GetDisk(self.UDiskId)
|
||||
if err == nil {
|
||||
zoneId = idisk.Zone
|
||||
} else if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
|
||||
+5
-7
@@ -69,7 +69,7 @@ func (self *SStoragecache) GetICloudImages() ([]cloudprovider.ICloudImage, error
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetICustomizedCloudImages() ([]cloudprovider.ICloudImage, error) {
|
||||
images, err := self.region.GetImages("", "Custom")
|
||||
images, err := self.region.GetImages("Custom", "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetImages")
|
||||
}
|
||||
@@ -83,8 +83,11 @@ func (self *SStoragecache) GetICustomizedCloudImages() ([]cloudprovider.ICloudIm
|
||||
|
||||
func (self *SStoragecache) GetIImageById(extId string) (cloudprovider.ICloudImage, error) {
|
||||
image, err := self.region.GetImage(extId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
image.storageCache = self
|
||||
return &image, err
|
||||
return &image, nil
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetPath() string {
|
||||
@@ -208,11 +211,6 @@ func (self *SStoragecache) uploadImage(ctx context.Context, image *cloudprovider
|
||||
return imgId, err
|
||||
}
|
||||
|
||||
// https://docs.ucloud.cn/api/uhost-api/create_custom_image
|
||||
func (self *SRegion) createIImage(snapshotId, imageName, imageDesc string) (string, error) {
|
||||
return "", cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
/*func (self *SRegion) GetBucketDomain(name string) (string, error) {
|
||||
params := NewRockbaseParams()
|
||||
params.Set("BucketName", name)
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ type SBucket struct {
|
||||
// projectId string
|
||||
|
||||
Domain Domain `json:"Domain"`
|
||||
BucketID string `json:"BucketId"`
|
||||
BucketId string `json:"BucketId"`
|
||||
Region string `json:"Region"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
Biz string `json:"Biz"`
|
||||
@@ -53,7 +53,7 @@ type SBucket struct {
|
||||
Type string `json:"Type"`
|
||||
Tag string `json:"Tag"`
|
||||
HasUserDomain int64 `json:"HasUserDomain"`
|
||||
CDNDomainID []string `json:"CdnDomainId"`
|
||||
CDNDomainId []string `json:"CdnDomainId"`
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
@@ -254,7 +254,7 @@ func (b *SBucket) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (b *SBucket) GetGlobalId() string {
|
||||
return b.BucketID
|
||||
return b.BucketId
|
||||
}
|
||||
|
||||
func (b *SBucket) GetName() string {
|
||||
|
||||
+13
-10
@@ -38,7 +38,7 @@ type SDisk struct {
|
||||
|
||||
Status string `json:"Status"`
|
||||
DeviceName string `json:"DeviceName"`
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
Tag string `json:"Tag"`
|
||||
Version string `json:"Version"`
|
||||
Name string `json:"Name"`
|
||||
@@ -50,7 +50,7 @@ type SDisk struct {
|
||||
ExpiredTime int64 `json:"ExpiredTime"`
|
||||
SnapshotCount int `json:"SnapshotCount"`
|
||||
IsExpire string `json:"IsExpire"`
|
||||
UDiskID string `json:"UDiskId"`
|
||||
UDiskId string `json:"UDiskId"`
|
||||
ChargeType string `json:"ChargeType"`
|
||||
UHostName string `json:"UHostName"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
@@ -62,7 +62,7 @@ func (self *SDisk) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetId() string {
|
||||
return self.UDiskID
|
||||
return self.UDiskId
|
||||
}
|
||||
|
||||
func (self *SDisk) GetName() string {
|
||||
@@ -136,7 +136,10 @@ func (self *SDisk) GetCreatedAt() time.Time {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetExpiredAt() time.Time {
|
||||
return time.Unix(self.ExpiredTime, 0)
|
||||
if strings.EqualFold(self.ChargeType, "Year") || strings.EqualFold(self.ChargeType, "Month") {
|
||||
return time.Unix(self.ExpiredTime, 0)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
@@ -160,12 +163,12 @@ func (self *SDisk) GetIsAutoDelete() bool {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetTemplateId() string {
|
||||
if strings.Contains(self.DiskType, "SystemDisk") && len(self.UHostID) > 0 {
|
||||
ins, err := self.storage.zone.region.GetInstance(self.UHostID)
|
||||
if strings.Contains(self.DiskType, "SystemDisk") && len(self.UHostId) > 0 {
|
||||
ins, err := self.storage.zone.region.GetInstance(self.UHostId)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return ins.ImageID
|
||||
return ins.ImageId
|
||||
}
|
||||
|
||||
return ""
|
||||
@@ -271,12 +274,12 @@ func (self *SDisk) Resize(ctx context.Context, newSizeMB int64) error {
|
||||
}
|
||||
|
||||
if self.Status == "InUse" {
|
||||
err := self.storage.zone.region.DetachDisk(self.Zone, self.UHostID, self.UDiskID)
|
||||
err := self.storage.zone.region.DetachDisk(self.Zone, self.UHostId, self.UDiskId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer self.storage.zone.region.AttachDisk(self.Zone, self.UHostID, self.UDiskID)
|
||||
defer self.storage.zone.region.AttachDisk(self.Zone, self.UHostId, self.UDiskId)
|
||||
err = cloudprovider.WaitStatusWithDelay(self, api.DISK_READY, 10*time.Second, 5*time.Second, 60*time.Second)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DiskResize")
|
||||
@@ -306,7 +309,7 @@ func (self *SRegion) GetDisk(diskId string) (*SDisk, error) {
|
||||
}
|
||||
|
||||
for i := range disks {
|
||||
if disks[i].UDiskID == diskId {
|
||||
if disks[i].UDiskId == diskId {
|
||||
return &disks[i], nil
|
||||
}
|
||||
}
|
||||
|
||||
+10
-7
@@ -44,7 +44,7 @@ type SEip struct {
|
||||
ChargeType string `json:"ChargeType"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
EIPAddr []EIPAddr `json:"EIPAddr"`
|
||||
EIPID string `json:"EIPId"`
|
||||
EIPId string `json:"EIPId"`
|
||||
Expire bool `json:"Expire"`
|
||||
ExpireTime int64 `json:"ExpireTime"`
|
||||
Name string `json:"Name"`
|
||||
@@ -67,7 +67,7 @@ type EIPAddr struct {
|
||||
}
|
||||
|
||||
type Resource struct {
|
||||
ResourceID string `json:"ResourceID"`
|
||||
ResourceId string `json:"ResourceID"`
|
||||
ResourceName string `json:"ResourceName"`
|
||||
ResourceType string `json:"ResourceType"`
|
||||
Zone string `json:"Zone"`
|
||||
@@ -75,12 +75,12 @@ type Resource struct {
|
||||
|
||||
type ShareBandwidthSet struct {
|
||||
ShareBandwidth int `json:"ShareBandwidth"`
|
||||
ShareBandwidthID string `json:"ShareBandwidthId"`
|
||||
ShareBandwidthId string `json:"ShareBandwidthId"`
|
||||
ShareBandwidthName string `json:"ShareBandwidthName"`
|
||||
}
|
||||
|
||||
func (self *SEip) GetId() string {
|
||||
return self.EIPID
|
||||
return self.EIPId
|
||||
}
|
||||
|
||||
func (self *SEip) GetName() string {
|
||||
@@ -139,7 +139,10 @@ func (self *SEip) GetCreatedAt() time.Time {
|
||||
}
|
||||
|
||||
func (self *SEip) GetExpiredAt() time.Time {
|
||||
return time.Unix(self.ExpireTime, 0)
|
||||
if strings.EqualFold(self.ChargeType, "Year") || strings.EqualFold(self.ChargeType, "Month") {
|
||||
return time.Unix(self.ExpireTime, 0)
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SEip) GetIpAddr() string {
|
||||
@@ -171,7 +174,7 @@ func (self *SEip) GetAssociationType() string {
|
||||
|
||||
// 已绑定的资源类型, 枚举值为: uhost, 云主机;natgw:NAT网关;ulb:负载均衡器;upm: 物理机; hadoophost: 大数据集群;fortresshost:堡垒机;udockhost:容器;udhost:私有专区主机;vpngw:IPSec VPN;ucdr:云灾备;dbaudit:数据库审计。
|
||||
func (self *SEip) GetAssociationExternalId() string {
|
||||
return self.Resource.ResourceID
|
||||
return self.Resource.ResourceId
|
||||
}
|
||||
|
||||
func (self *SEip) GetBandwidth() int {
|
||||
@@ -203,7 +206,7 @@ func (self *SEip) Associate(conf *cloudprovider.AssociateConfig) error {
|
||||
}
|
||||
|
||||
func (self *SEip) Dissociate() error {
|
||||
return self.region.DissociateEip(self.GetId(), self.Resource.ResourceID)
|
||||
return self.region.DissociateEip(self.GetId(), self.Resource.ResourceId)
|
||||
}
|
||||
|
||||
func (self *SEip) ChangeBandwidth(bw int) error {
|
||||
|
||||
+36
-2
@@ -20,6 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/imagetools"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
@@ -38,7 +39,7 @@ type SImage struct {
|
||||
Zone string `json:"Zone"`
|
||||
ImageDescription string `json:"ImageDescription"`
|
||||
OSName string `json:"OsName"`
|
||||
ImageID string `json:"ImageId"`
|
||||
ImageId string `json:"ImageId"`
|
||||
State string `json:"State"`
|
||||
ImageName string `json:"ImageName"`
|
||||
OSType string `json:"OsType"`
|
||||
@@ -52,7 +53,7 @@ func (self *SImage) GetMinRamSizeMb() int {
|
||||
}
|
||||
|
||||
func (self *SImage) GetId() string {
|
||||
return self.ImageID
|
||||
return self.ImageId
|
||||
}
|
||||
|
||||
func (self *SImage) GetName() string {
|
||||
@@ -226,3 +227,36 @@ func (self *SRegion) DeleteImage(imageId string) error {
|
||||
|
||||
return self.DoAction("TerminateCustomImage", params, nil)
|
||||
}
|
||||
|
||||
// https://docs.ucloud.cn/api/uhost-api/create_custom_image
|
||||
func (self *SRegion) SaveImage(instanceId string, opts *cloudprovider.SaveImageOptions) (*SImage, error) {
|
||||
params := NewUcloudParams()
|
||||
params.Set("UHostId", instanceId)
|
||||
params.Set("ImageName", opts.Name)
|
||||
if len(opts.Notes) > 0 {
|
||||
params.Set("ImageDescription", opts.Notes)
|
||||
}
|
||||
|
||||
ret := struct {
|
||||
ImageId string
|
||||
}{}
|
||||
err := self.DoAction("CreateCustomImage", params, &ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateCustomImage")
|
||||
}
|
||||
if len(ret.ImageId) == 0 {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "CreateCustomImage empty ImageId")
|
||||
}
|
||||
|
||||
image, err := self.GetImage(ret.ImageId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetImage(%s)", ret.ImageId)
|
||||
}
|
||||
image.storageCache = self.getStoragecache()
|
||||
img := &image
|
||||
err = cloudprovider.WaitStatus(img, api.CACHED_IMAGE_STATUS_ACTIVE, 10*time.Second, 30*time.Minute)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "wait image ready")
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
+30
-20
@@ -42,12 +42,12 @@ type SInstance struct {
|
||||
|
||||
osInfo *imagetools.ImageInfo
|
||||
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
Zone string `json:"Zone"`
|
||||
LifeCycle string `json:"LifeCycle"`
|
||||
OSName string `json:"OsName"`
|
||||
ImageID string `json:"ImageId"`
|
||||
BasicImageID string `json:"BasicImageId"`
|
||||
ImageId string `json:"ImageId"`
|
||||
BasicImageId string `json:"BasicImageId"`
|
||||
BasicImageName string `json:"BasicImageName"`
|
||||
Tag string `json:"Tag"`
|
||||
Name string `json:"Name"`
|
||||
@@ -102,7 +102,7 @@ func (self *SInstance) GetError() error {
|
||||
}
|
||||
|
||||
type DiskSet struct {
|
||||
DiskID string `json:"DiskId"`
|
||||
DiskId string `json:"DiskId"`
|
||||
DiskType string `json:"DiskType"`
|
||||
Drive string `json:"Drive"`
|
||||
IsBoot bool `json:"IsBoot"`
|
||||
@@ -117,19 +117,19 @@ type IPSet struct {
|
||||
IPId string `json:"IPId"` // IP资源ID (内网IP无对应的资源ID)
|
||||
MAC string `json:"Mac"`
|
||||
VpcId string `json:"VPCId"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
SubnetId string `json:"SubnetId"`
|
||||
}
|
||||
|
||||
type SVncInfo struct {
|
||||
VNCIP string `json:"VncIP"`
|
||||
VNCPassword string `json:"VncPassword"`
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
Action string `json:"Action"`
|
||||
VNCPort int64 `json:"VncPort"`
|
||||
}
|
||||
|
||||
func (self *SInstance) GetId() string {
|
||||
return self.UHostID
|
||||
return self.UHostId
|
||||
}
|
||||
|
||||
func (self *SInstance) GetName() string {
|
||||
@@ -177,13 +177,14 @@ func (self *SInstance) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) Refresh() error {
|
||||
new, err := self.host.zone.region.GetInstance(self.GetId())
|
||||
vm, err := self.host.zone.region.GetInstance(self.GetId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
new.host = self.host
|
||||
return jsonutils.Update(self, new)
|
||||
self.DiskSet = nil
|
||||
self.IPSet = nil
|
||||
self.osInfo = nil
|
||||
return jsonutils.Update(self, vm)
|
||||
}
|
||||
|
||||
// 计费模式,枚举值为: Year,按年付费; Month,按月付费; Dynamic,按需付费(需开启权限);
|
||||
@@ -201,10 +202,9 @@ func (self *SInstance) GetCreatedAt() time.Time {
|
||||
}
|
||||
|
||||
func (self *SInstance) GetExpiredAt() time.Time {
|
||||
if self.AutoRenew != "Yes" {
|
||||
if strings.EqualFold(self.ChargeType, "Year") || strings.EqualFold(self.ChargeType, "Month") {
|
||||
return time.Unix(self.ExpireTime, 0)
|
||||
}
|
||||
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
@@ -221,11 +221,11 @@ func (self *SInstance) GetLocalDisk(diskId, storageType string, sizeGB int, isBo
|
||||
disk := SDisk{
|
||||
SDisk: multicloud.SDisk{},
|
||||
Status: "Available",
|
||||
UHostID: self.GetId(),
|
||||
UHostId: self.GetId(),
|
||||
Name: diskId,
|
||||
Zone: self.host.zone.GetId(),
|
||||
DiskType: diskType,
|
||||
UDiskID: diskId,
|
||||
UDiskId: diskId,
|
||||
UHostName: self.GetName(),
|
||||
CreateTime: self.CreateTime,
|
||||
SizeGB: sizeGB,
|
||||
@@ -240,10 +240,10 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
disks := []SDisk{}
|
||||
for _, disk := range self.DiskSet {
|
||||
if utils.IsInStringArray(disk.DiskType, api.UCLOUD_LOCAL_STORAGES) {
|
||||
localDisks = append(localDisks, self.GetLocalDisk(disk.DiskID, disk.DiskType, disk.Size, disk.IsBoot))
|
||||
localDisks = append(localDisks, self.GetLocalDisk(disk.DiskId, disk.DiskType, disk.Size, disk.IsBoot))
|
||||
continue
|
||||
}
|
||||
disk, err := self.host.zone.region.GetDisk(disk.DiskID)
|
||||
disk, err := self.host.zone.region.GetDisk(disk.DiskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -280,7 +280,7 @@ func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
|
||||
nics := make([]cloudprovider.ICloudNic, 0)
|
||||
|
||||
for _, ip := range self.IPSet {
|
||||
if len(ip.SubnetID) == 0 {
|
||||
if len(ip.SubnetId) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -455,8 +455,8 @@ func (self *SInstance) RebuildRoot(ctx context.Context, desc *cloudprovider.SMan
|
||||
}
|
||||
|
||||
for _, disk := range self.DiskSet {
|
||||
if disk.Type == "SystemDisk" {
|
||||
return disk.DiskID, nil
|
||||
if strings.EqualFold(disk.Type, "SystemDisk") || strings.EqualFold(disk.Type, "Boot") {
|
||||
return disk.DiskId, nil
|
||||
}
|
||||
}
|
||||
return "", errors.Wrapf(cloudprovider.ErrNotFound, "SystemDisk not found")
|
||||
@@ -506,6 +506,14 @@ func (self *SInstance) ChangeConfig2(ctx context.Context, instanceType string) e
|
||||
return self.host.zone.region.ResizeVM(self.GetId(), i.CPU, i.MemoryMB)
|
||||
}
|
||||
|
||||
func (self *SInstance) SaveImage(opts *cloudprovider.SaveImageOptions) (cloudprovider.ICloudImage, error) {
|
||||
image, err := self.host.zone.region.SaveImage(self.GetId(), opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "SaveImage")
|
||||
}
|
||||
return image, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) GetVNCInfo(input *cloudprovider.ServerVncInput) (*cloudprovider.ServerVncOutput, error) {
|
||||
return self.host.zone.region.GetInstanceVNCUrl(self.GetId())
|
||||
}
|
||||
@@ -558,6 +566,8 @@ func (self *SRegion) GetInstanceVNCUrl(instanceId string) (*cloudprovider.Server
|
||||
Port: vnc.VNCPort,
|
||||
Password: vnc.VNCPassword,
|
||||
Hypervisor: api.HYPERVISOR_UCLOUD,
|
||||
Protocol: "vnc",
|
||||
InstanceId: instanceId,
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ func (self *SInstanceNic) InClassicNetwork() bool {
|
||||
func (self *SInstanceNic) GetINetworkId() string {
|
||||
for _, ip := range self.instance.IPSet {
|
||||
if ip.IP == self.ipAddr {
|
||||
return ip.SubnetID
|
||||
return ip.SubnetId
|
||||
}
|
||||
}
|
||||
return ""
|
||||
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
// 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 ucloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
const (
|
||||
// https://docs.ucloud.cn/cloudwatch/metric/intro
|
||||
UCLOUD_PRODUCT_KEY_UHOST = "uhost"
|
||||
)
|
||||
|
||||
type SMetricSample struct {
|
||||
Timestamp int64
|
||||
Value float64
|
||||
}
|
||||
|
||||
type SMetricResult struct {
|
||||
ResourceId string
|
||||
ResourceName string
|
||||
TagMap map[string]string
|
||||
Values []SMetricSample
|
||||
}
|
||||
|
||||
type SQueryMetricDataItem struct {
|
||||
Metric string
|
||||
Results []SMetricResult
|
||||
}
|
||||
|
||||
type SQueryMetricDataResp struct {
|
||||
InvalidResourceIds []string
|
||||
List []SQueryMetricDataItem
|
||||
}
|
||||
|
||||
var uhostMetricNames = map[cloudprovider.TMetricType]string{
|
||||
cloudprovider.VM_METRIC_TYPE_CPU_USAGE: "uhost_cpu_used",
|
||||
cloudprovider.VM_METRIC_TYPE_MEM_USAGE: "cloudwatch_memory_usage",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_USAGE: "cloudwatch_sys_disk_used_per",
|
||||
cloudprovider.VM_METRIC_TYPE_NET_BPS_RX: "uhost_net_in_flow",
|
||||
cloudprovider.VM_METRIC_TYPE_NET_BPS_TX: "uhost_net_out_flow",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_BPS: "uhost_disk_read",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_BPS: "uhost_disk_write",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_IOPS: "uhost_disk_read_times",
|
||||
cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_IOPS: "uhost_disk_write_times",
|
||||
}
|
||||
|
||||
var uhostMetricNameTypes map[string]cloudprovider.TMetricType
|
||||
|
||||
func init() {
|
||||
uhostMetricNameTypes = make(map[string]cloudprovider.TMetricType, len(uhostMetricNames))
|
||||
for metricType, name := range uhostMetricNames {
|
||||
uhostMetricNameTypes[name] = metricType
|
||||
}
|
||||
}
|
||||
|
||||
func pickMetricPeriod(start, end time.Time, interval int) int {
|
||||
if interval > 0 {
|
||||
return interval
|
||||
}
|
||||
d := end.Sub(start)
|
||||
switch {
|
||||
case d <= time.Hour:
|
||||
return 60
|
||||
case d <= 12*time.Hour:
|
||||
return 60
|
||||
case d <= 24*time.Hour:
|
||||
return 300
|
||||
default:
|
||||
return 3600
|
||||
}
|
||||
}
|
||||
|
||||
// https://docs.ucloud.cn/api/cloudwatch-api/query_metric_data_set
|
||||
func (self *SRegion) QueryMetricDataSet(productKey string, resourceIds []string, metricNames []string, start, end time.Time, period int) (*SQueryMetricDataResp, error) {
|
||||
params := NewUcloudParams()
|
||||
params.Set("Region", self.GetId())
|
||||
params.Set("ProductKey", productKey)
|
||||
params.Set("StartTime", int(start.Unix()))
|
||||
params.Set("EndTime", int(end.Unix()))
|
||||
params.Set("CalcMethod", "avg")
|
||||
params.Set("Period", period)
|
||||
|
||||
idx := 0
|
||||
for _, resourceId := range resourceIds {
|
||||
for _, metricName := range metricNames {
|
||||
params.Set(fmt.Sprintf("MetricInfos.%d.Metric", idx), metricName)
|
||||
params.Set(fmt.Sprintf("MetricInfos.%d.ResourceId", idx), resourceId)
|
||||
idx++
|
||||
}
|
||||
}
|
||||
if idx == 0 {
|
||||
return nil, errors.Wrap(cloudprovider.ErrMissingParameter, "metric infos")
|
||||
}
|
||||
|
||||
params = self.client.commonParams(params)
|
||||
params.SetAction("QueryMetricDataSet")
|
||||
resp, err := jsonRequest(self.client, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "QueryMetricDataSet")
|
||||
}
|
||||
ret := SQueryMetricDataResp{}
|
||||
err = resp.Unmarshal(&ret, "Data")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unmarshal Data")
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetUhostMetrics(resourceIds []string, start, end time.Time, interval int) ([]cloudprovider.MetricValues, error) {
|
||||
metricNames := make([]string, 0, len(uhostMetricNames))
|
||||
for _, name := range uhostMetricNames {
|
||||
metricNames = append(metricNames, name)
|
||||
}
|
||||
period := pickMetricPeriod(start, end, interval)
|
||||
data, err := self.QueryMetricDataSet(UCLOUD_PRODUCT_KEY_UHOST, resourceIds, metricNames, start, end, period)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "QueryMetricDataSet")
|
||||
}
|
||||
ret := []cloudprovider.MetricValues{}
|
||||
for _, item := range data.List {
|
||||
metricType, ok := uhostMetricNameTypes[item.Metric]
|
||||
if !ok {
|
||||
log.Warningf("unknown uhost metric %s", item.Metric)
|
||||
continue
|
||||
}
|
||||
for _, result := range item.Results {
|
||||
metric := cloudprovider.MetricValues{
|
||||
Id: result.ResourceId,
|
||||
MetricType: metricType,
|
||||
Values: []cloudprovider.MetricValue{},
|
||||
}
|
||||
for _, sample := range result.Values {
|
||||
value := sample.Value
|
||||
switch metricType {
|
||||
case cloudprovider.VM_METRIC_TYPE_NET_BPS_RX, cloudprovider.VM_METRIC_TYPE_NET_BPS_TX:
|
||||
// uhost network metrics unit is bps (bits per second)
|
||||
value = value / 8.0
|
||||
}
|
||||
metric.Values = append(metric.Values, cloudprovider.MetricValue{
|
||||
Timestamp: time.Unix(sample.Timestamp, 0),
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
if len(metric.Values) > 0 {
|
||||
ret = append(ret, metric)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SUcloudClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
switch opts.ResourceType {
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
|
||||
return self.GetEcsMetrics(opts)
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.ResourceType)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SUcloudClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
region := self.GetRegion(opts.RegionExtId)
|
||||
if region == nil {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "region %s", opts.RegionExtId)
|
||||
}
|
||||
resourceIds := opts.ResourceIds
|
||||
if len(resourceIds) == 0 && len(opts.ResourceId) > 0 {
|
||||
resourceIds = []string{opts.ResourceId}
|
||||
}
|
||||
if len(resourceIds) == 0 {
|
||||
return nil, errors.Wrap(cloudprovider.ErrMissingParameter, "resource_id")
|
||||
}
|
||||
return region.GetUhostMetrics(resourceIds, opts.StartTime, opts.EndTime, opts.Interval)
|
||||
}
|
||||
+5
-5
@@ -40,15 +40,15 @@ type SNetwork struct {
|
||||
Name string `json:"Name"`
|
||||
Netmask string `json:"Netmask"`
|
||||
Remark string `json:"Remark"`
|
||||
RouteTableID string `json:"RouteTableId"`
|
||||
RouteTableId string `json:"RouteTableId"`
|
||||
Subnet string `json:"Subnet"`
|
||||
SubnetID string `json:"SubnetId"`
|
||||
SubnetId string `json:"SubnetId"`
|
||||
SubnetName string `json:"SubnetName"`
|
||||
SubnetType int `json:"SubnetType"`
|
||||
Tag string `json:"Tag"`
|
||||
VpcId string `json:"VPCId"`
|
||||
VPCName string `json:"VPCName"`
|
||||
VRouterID string `json:"VRouterId"`
|
||||
VRouterId string `json:"VRouterId"`
|
||||
Zone string `json:"Zone"`
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (self *SNetwork) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetId() string {
|
||||
return self.SubnetID
|
||||
return self.SubnetId
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetName() string {
|
||||
@@ -153,7 +153,7 @@ func (self *SRegion) getNetwork(networkId string) (*SNetwork, error) {
|
||||
}
|
||||
|
||||
for i := range networks {
|
||||
if networks[i].SubnetID == networkId {
|
||||
if networks[i].SubnetId == networkId {
|
||||
vpc, err := self.GetVpc(networks[i].VpcId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+3
-3
@@ -22,9 +22,9 @@ import (
|
||||
type SProject struct {
|
||||
multicloud.SProjectBase
|
||||
UcloudTags
|
||||
ProjectID string `json:"ProjectId"`
|
||||
ProjectId string `json:"ProjectId"`
|
||||
ProjectName string `json:"ProjectName"`
|
||||
ParentID string `json:"ParentId"`
|
||||
ParentId string `json:"ParentId"`
|
||||
ParentName string `json:"ParentName"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
IsDefault bool `json:"IsDefault"`
|
||||
@@ -33,7 +33,7 @@ type SProject struct {
|
||||
}
|
||||
|
||||
func (self *SProject) GetId() string {
|
||||
return self.ProjectID
|
||||
return self.ProjectId
|
||||
}
|
||||
|
||||
func (self *SProject) GetName() string {
|
||||
|
||||
+4
@@ -188,3 +188,7 @@ func (self *SUcloudProvider) GetObjectCannedAcls(regionId string) []string {
|
||||
func (self *SUcloudProvider) GetCapabilities() []string {
|
||||
return self.client.GetCapabilities()
|
||||
}
|
||||
|
||||
func (self *SUcloudProvider) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
return self.client.GetMetrics(opts)
|
||||
}
|
||||
|
||||
+5
-5
@@ -30,7 +30,7 @@ type SRegion struct {
|
||||
multicloud.SNoLbRegion
|
||||
client *SUcloudClient
|
||||
|
||||
RegionID string `json:"Region"`
|
||||
RegionId string `json:"Region"`
|
||||
LocalName string `json:"LocalName"`
|
||||
CountryCode string `json:"CountryCode"`
|
||||
Category string `json:"Category"`
|
||||
@@ -39,7 +39,7 @@ type SRegion struct {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetId() string {
|
||||
return self.RegionID
|
||||
return self.RegionId
|
||||
}
|
||||
|
||||
func (self *SRegion) GetName() string {
|
||||
@@ -154,7 +154,7 @@ func (self *SRegion) GetEip(eipId string) (*SEip, error) {
|
||||
}
|
||||
|
||||
for i := range eips {
|
||||
if eips[i].EIPID == eipId {
|
||||
if eips[i].EIPId == eipId {
|
||||
eips[i].region = self
|
||||
return &eips[i], nil
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func (self *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSn
|
||||
}
|
||||
|
||||
for i := range snapshots {
|
||||
if snapshots[i].SnapshotID == snapshotId {
|
||||
if snapshots[i].SnapshotId == snapshotId {
|
||||
snapshot := snapshots[i]
|
||||
snapshot.region = self
|
||||
return &snapshot, nil
|
||||
@@ -398,7 +398,7 @@ func (self *SRegion) GetInstance(instanceId string) (*SInstance, error) {
|
||||
}
|
||||
|
||||
for i := range instances {
|
||||
if instances[i].UHostID == instanceId {
|
||||
if instances[i].UHostId == instanceId {
|
||||
return &instances[i], nil
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ func (self *SecurityGroupRule) GetPriority() int {
|
||||
|
||||
func (self *SecurityGroupRule) Delete() error {
|
||||
params := NewUcloudParams()
|
||||
params.Set("FWId", self.secgroup.FWID)
|
||||
params.Set("FWId", self.secgroup.FWId)
|
||||
idx := 0
|
||||
for _, rule := range self.secgroup.Rule {
|
||||
if rule.GetGlobalId() == self.GetGlobalId() {
|
||||
|
||||
+5
-5
@@ -34,8 +34,8 @@ type SSecurityGroup struct {
|
||||
region *SRegion
|
||||
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
FWID string `json:"FWId"`
|
||||
GroupID string `json:"GroupId"`
|
||||
FWId string `json:"FWId"`
|
||||
GroupId string `json:"GroupId"`
|
||||
Name string `json:"Name"`
|
||||
Remark string `json:"Remark"`
|
||||
ResourceCount int `json:"ResourceCount"`
|
||||
@@ -49,7 +49,7 @@ func (self *SSecurityGroup) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetId() string {
|
||||
return self.FWID
|
||||
return self.FWId
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetName() string {
|
||||
@@ -133,7 +133,7 @@ func (self *SRegion) CreateSecurityGroup(name, description string) (string, erro
|
||||
|
||||
func (self *SSecurityGroup) CreateRule(opts *cloudprovider.SecurityGroupRuleCreateOptions) (cloudprovider.ISecurityGroupRule, error) {
|
||||
params := NewUcloudParams()
|
||||
params.Set("FWId", self.FWID)
|
||||
params.Set("FWId", self.FWId)
|
||||
idx := 0
|
||||
for _, rule := range self.Rule {
|
||||
params.Set(fmt.Sprintf("Rule.%d", idx), rule.String())
|
||||
@@ -210,5 +210,5 @@ func (self *SRegion) GetSecurityGroups(secGroupId string, resourceId string, nam
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) Delete() error {
|
||||
return self.region.DeleteSecurityGroup(self.FWID)
|
||||
return self.region.DeleteSecurityGroup(self.FWId)
|
||||
}
|
||||
|
||||
+7
-7
@@ -36,15 +36,15 @@ type SSnapshot struct {
|
||||
Name string `json:"Name"`
|
||||
UDiskName string `json:"UDiskName"`
|
||||
ExpiredTime int64 `json:"ExpiredTime"`
|
||||
UDiskID string `json:"UDiskId"`
|
||||
SnapshotID string `json:"SnapshotId"`
|
||||
UDiskId string `json:"UDiskId"`
|
||||
SnapshotId string `json:"SnapshotId"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
SizeGB int32 `json:"Size"`
|
||||
Status string `json:"Status"`
|
||||
IsUDiskAvailable bool `json:"IsUDiskAvailable"`
|
||||
Version string `json:"Version"`
|
||||
DiskType int `json:"DiskType"`
|
||||
UHostID string `json:"UHostId"`
|
||||
UHostId string `json:"UHostId"`
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
@@ -52,7 +52,7 @@ func (self *SSnapshot) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetId() string {
|
||||
return self.SnapshotID
|
||||
return self.SnapshotId
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetName() string {
|
||||
@@ -82,7 +82,7 @@ func (self *SSnapshot) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) Refresh() error {
|
||||
disk, err := self.region.GetDisk(self.UDiskID)
|
||||
disk, err := self.region.GetDisk(self.UDiskId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (self *SSnapshot) GetSizeMb() int32 {
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetDiskId() string {
|
||||
return self.UDiskID
|
||||
return self.UDiskId
|
||||
}
|
||||
|
||||
// 磁盘类型,0:数据盘,1:系统盘
|
||||
@@ -123,7 +123,7 @@ func (self *SSnapshot) GetDiskType() string {
|
||||
// https://docs.ucloud.cn/api/udisk-api/delete_udisk_snapshot
|
||||
func (self *SSnapshot) Delete() error {
|
||||
zoneId := ""
|
||||
idisk, err := self.region.GetDisk(self.UDiskID)
|
||||
idisk, err := self.region.GetDisk(self.UDiskId)
|
||||
if err == nil {
|
||||
zoneId = idisk.Zone
|
||||
} else if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
|
||||
+5
-7
@@ -69,7 +69,7 @@ func (self *SStoragecache) GetICloudImages() ([]cloudprovider.ICloudImage, error
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetICustomizedCloudImages() ([]cloudprovider.ICloudImage, error) {
|
||||
images, err := self.region.GetImages("", "Custom")
|
||||
images, err := self.region.GetImages("Custom", "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetImages")
|
||||
}
|
||||
@@ -83,8 +83,11 @@ func (self *SStoragecache) GetICustomizedCloudImages() ([]cloudprovider.ICloudIm
|
||||
|
||||
func (self *SStoragecache) GetIImageById(extId string) (cloudprovider.ICloudImage, error) {
|
||||
image, err := self.region.GetImage(extId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
image.storageCache = self
|
||||
return &image, err
|
||||
return &image, nil
|
||||
}
|
||||
|
||||
func (self *SStoragecache) GetPath() string {
|
||||
@@ -208,11 +211,6 @@ func (self *SStoragecache) uploadImage(ctx context.Context, image *cloudprovider
|
||||
return imgId, err
|
||||
}
|
||||
|
||||
// https://docs.ucloud.cn/api/uhost-api/create_custom_image
|
||||
func (self *SRegion) createIImage(snapshotId, imageName, imageDesc string) (string, error) {
|
||||
return "", cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
/*func (self *SRegion) GetBucketDomain(name string) (string, error) {
|
||||
params := NewUcloudParams()
|
||||
params.Set("BucketName", name)
|
||||
|
||||
+2
-2
@@ -271,10 +271,10 @@ func (self *SUcloudClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
|
||||
subAccounts := make([]cloudprovider.SSubAccount, 0)
|
||||
for _, project := range projects {
|
||||
subAccount := cloudprovider.SSubAccount{}
|
||||
subAccount.Id = project.ProjectID
|
||||
subAccount.Id = project.ProjectId
|
||||
subAccount.Name = fmt.Sprintf("%s-%s", self.cpcfg.Name, project.ProjectName)
|
||||
// ucloud账号ID中可能包含/。因此使用::作为分割符号
|
||||
subAccount.Account = fmt.Sprintf("%s::%s", self.accessKeyId, project.ProjectID)
|
||||
subAccount.Account = fmt.Sprintf("%s::%s", self.accessKeyId, project.ProjectId)
|
||||
subAccount.HealthStatus = api.CLOUD_PROVIDER_HEALTH_NORMAL
|
||||
|
||||
subAccounts = append(subAccounts, subAccount)
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ type SBucket struct {
|
||||
// projectId string
|
||||
|
||||
Domain Domain `json:"Domain"`
|
||||
BucketID string `json:"BucketId"`
|
||||
BucketId string `json:"BucketId"`
|
||||
Region string `json:"Region"`
|
||||
CreateTime int64 `json:"CreateTime"`
|
||||
Biz string `json:"Biz"`
|
||||
@@ -53,7 +53,7 @@ type SBucket struct {
|
||||
Type string `json:"Type"`
|
||||
Tag string `json:"Tag"`
|
||||
HasUserDomain int64 `json:"HasUserDomain"`
|
||||
CDNDomainID []string `json:"CdnDomainId"`
|
||||
CDNDomainId []string `json:"CdnDomainId"`
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
@@ -254,7 +254,7 @@ func (b *SBucket) GetProjectId() string {
|
||||
}
|
||||
|
||||
func (b *SBucket) GetGlobalId() string {
|
||||
return b.BucketID
|
||||
return b.BucketId
|
||||
}
|
||||
|
||||
func (b *SBucket) GetName() string {
|
||||
|
||||
Reference in New Issue
Block a user