diff --git a/pkg/compute/guestdrivers/aws.go b/pkg/compute/guestdrivers/aws.go index eaf78dea75..77f89b65c3 100644 --- a/pkg/compute/guestdrivers/aws.go +++ b/pkg/compute/guestdrivers/aws.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - "yunion.io/x/pkg/utils" "yunion.io/x/jsonutils" diff --git a/pkg/compute/hostdrivers/esxi.go b/pkg/compute/hostdrivers/esxi.go index 53cfe156a6..8f56cd07b0 100644 --- a/pkg/compute/hostdrivers/esxi.go +++ b/pkg/compute/hostdrivers/esxi.go @@ -7,10 +7,10 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "github.com/golang-plus/errors" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/httputils" - "github.com/golang-plus/errors" ) type SESXiHostDriver struct { diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 3e0a12c1c6..8e6012922a 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -531,7 +531,6 @@ func (manager *SCloudaccountManager) FetchCloudaccountByIdOrName(accountId strin return providerObj.(*SCloudaccount) } - func (self *SCloudaccount) getProviderCount() int { q := CloudproviderManager.Query().Equals("cloudaccount_id", self.Id) return q.Count() diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index 44ff7dd376..d43a165d3e 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -372,7 +372,7 @@ func (manager *SDiskManager) ValidateCreateData(ctx context.Context, userCred mc } pendingUsage := SQuota{Storage: diskConfig.SizeMb} if err := QuotaManager.CheckSetPendingQuota(ctx, userCred, userCred.GetProjectId(), &pendingUsage); err != nil { - return nil, err + return nil, httperrors.NewOutOfQuotaError("%s", err) } return data, nil } @@ -719,10 +719,13 @@ func (self *SDisk) PrepareSaveImage(ctx context.Context, userCred mcclient.Token } else if imageList.Total > 0 { return "", httperrors.NewConflictError("Duplicate image name %s", name) } - quota := SQuota{Image: 1} - if _, err := QuotaManager.CheckQuota(ctx, userCred, userCred.GetProjectId(), "a); err != nil { - return "", err - } + /* + no need to check quota anymore + session := auth.GetSession(userCred, options.Options.Region, "v2") + quota := image_models.SQuota{Image: 1} + if _, err := modules.ImageQuotas.DoQuotaCheck(session, jsonutils.Marshal("a)); err != nil { + return "", err + }*/ data.Add(jsonutils.NewInt(int64(self.DiskSize)), "virtual_size") if result, err := modules.Images.Create(s, data); err != nil { return "", err @@ -1354,9 +1357,12 @@ func (self *SDisk) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict return extra } -func (self *SDisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query) - return self.getMoreDetails(extra) +func (self *SDisk) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { + extra, err := self.SSharableVirtualResourceBase.GetExtraDetails(ctx, userCred, query) + if err != nil { + return nil, err + } + return self.getMoreDetails(extra), nil } func (self *SDisk) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { @@ -1478,11 +1484,7 @@ func (self *SDisk) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { billingInfo.PriceKey = priceKey } -<<<<<<< HEAD - billingInfo.ChargeType = self.GetChargeType() -======= billingInfo.SBillingBaseInfo = self.getBillingBaseInfo() ->>>>>>> 8f11b765... 1. desc.Update(jsonutils.Marshal(billingInfo)) diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index f29e851e71..d57034c79f 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -23,10 +23,8 @@ import ( "yunion.io/x/onecloud/pkg/util/logclient" "yunion.io/x/onecloud/pkg/util/seclib2" - "time" - "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/onecloud/pkg/util/billing" diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 5755e970c0..24c53203ee 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -127,12 +127,13 @@ const ( HYPERVISOR_BAREMETAL = "baremetal" HYPERVISOR_ESXI = "esxi" HYPERVISOR_HYPERV = "hyperv" - HYPERVISOR_ALIYUN = "aliyun" - HYPERVISOR_QCLOUD = "qcloud" - HYPERVISOR_AZURE = "azure" - HYPERVISOR_AWS = "aws" - HYPERVISOR_HUAWEI = "huawei" + HYPERVISOR_XEN = "xen" + HYPERVISOR_ALIYUN = "aliyun" + HYPERVISOR_QCLOUD = "qcloud" + HYPERVISOR_AZURE = "azure" + HYPERVISOR_AWS = "aws" + HYPERVISOR_HUAWEI = "huawei" // HYPERVISOR_DEFAULT = HYPERVISOR_KVM HYPERVISOR_DEFAULT = HYPERVISOR_KVM @@ -141,10 +142,24 @@ const ( var VM_RUNNING_STATUS = []string{VM_START_START, VM_STARTING, VM_RUNNING, VM_BLOCK_STREAM} var VM_CREATING_STATUS = []string{VM_CREATE_NETWORK, VM_CREATE_DISK, VM_START_DEPLOY, VM_DEPLOYING} -var HYPERVISORS = []string{HYPERVISOR_KVM, HYPERVISOR_BAREMETAL, HYPERVISOR_ESXI, HYPERVISOR_CONTAINER, - HYPERVISOR_ALIYUN, HYPERVISOR_AZURE, HYPERVISOR_AWS, HYPERVISOR_QCLOUD, HYPERVISOR_HUAWEI} +var HYPERVISORS = []string{HYPERVISOR_KVM, + HYPERVISOR_BAREMETAL, + HYPERVISOR_ESXI, + HYPERVISOR_CONTAINER, + HYPERVISOR_ALIYUN, + HYPERVISOR_AZURE, + HYPERVISOR_AWS, + HYPERVISOR_QCLOUD, + HYPERVISOR_HUAWEI, +} -var PUBLIC_CLOUD_HYPERVISORS = []string{HYPERVISOR_ALIYUN, HYPERVISOR_AWS, HYPERVISOR_AZURE, HYPERVISOR_QCLOUD, HYPERVISOR_HUAWEI} +var PUBLIC_CLOUD_HYPERVISORS = []string{ + HYPERVISOR_ALIYUN, + HYPERVISOR_AWS, + HYPERVISOR_AZURE, + HYPERVISOR_QCLOUD, + HYPERVISOR_HUAWEI, +} // var HYPERVISORS = []string{HYPERVISOR_ALIYUN} @@ -219,7 +234,7 @@ type SGuest struct { SecgrpId string `width:"36" charset:"ascii" nullable:"true" get:"user" create:"optional"` // Column(VARCHAR(36, charset='ascii'), nullable=True) AdminSecgrpId string `width:"36" charset:"ascii" nullable:"true" get:"admin"` // Column(VARCHAR(36, charset='ascii'), nullable=True) - Hypervisor string `width:"16" charset:"ascii" nullable:"false" default:"kvm" list:"user" create:"required"` // Column(VARCHAR(16, charset='ascii'), nullable=False, default=HYPERVISOR_DEFAULT) + Hypervisor string `width:"16" charset:"ascii" nullable:"false" default:"kvm" list:"user"` // Column(VARCHAR(16, charset='ascii'), nullable=False, default=HYPERVISOR_DEFAULT) InstanceType string `width:"64" charset:"ascii" nullable:"true" list:"user" create:"optional"` } @@ -1198,8 +1213,12 @@ func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict) *jsonutils.JSONDict return extra } -func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict { - extra := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) +func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) { + extra, err := self.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query) + if err != nil { + return nil, err + } + extra.Add(jsonutils.NewString(self.getNetworksDetails()), "networks") extra.Add(jsonutils.NewString(self.getDisksDetails()), "disks") extra.Add(self.getDisksInfoDetails(), "disks_info") @@ -1251,7 +1270,7 @@ func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.Token extra.Add(jsonutils.JSONFalse, "is_prepaid_recycle") } - return self.moreExtraInfo(extra) + return self.moreExtraInfo(extra), nil } func (manager *SGuestManager) ListItemExportKeys(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) { @@ -3198,7 +3217,6 @@ func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { desc.Add(jsonutils.NewString(self.OsType), "os_type") } - if len(self.ExternalId) > 0 { desc.Add(jsonutils.NewString(self.ExternalId), "externalId") } @@ -3229,11 +3247,7 @@ func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { billingInfo.PriceKey = priceKey } -<<<<<<< HEAD - billingInfo.ChargeType = self.GetChargeType() -======= billingInfo.SBillingBaseInfo = self.getBillingBaseInfo() ->>>>>>> 8f11b765... 1. desc.Update(jsonutils.Marshal(billingInfo)) diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index 8ff9fc74b3..c43b5b5255 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -617,8 +617,8 @@ func (manager *SNetworkManager) allNetworksQ(providers []string, rangeObj db.ISt q = q.Join(hosts, sqlchemy.Equals(hosts.Field("id"), hostwires.Field("host_id"))) q = q.Filter(sqlchemy.IsTrue(hosts.Field("enabled"))) q = q.Filter(sqlchemy.OR( - sqlchemy.Equals(hosts.Field("host_type"), HOST_TYPE_BAREMETAL), - sqlchemy.Equals(hosts.Field("host_status"), HOST_ONLINE))) + sqlchemy.Equals(hosts.Field("host_type"), HOST_TYPE_BAREMETAL), + sqlchemy.Equals(hosts.Field("host_status"), HOST_ONLINE))) return AttachUsageQuery(q, hosts, nil, nil, providers, rangeObj) } diff --git a/pkg/compute/options/options.go b/pkg/compute/options/options.go index 78726deb34..f792d42279 100644 --- a/pkg/compute/options/options.go +++ b/pkg/compute/options/options.go @@ -26,8 +26,8 @@ type ComputeOptions struct { PendingDeleteExpireSeconds int `default:"259200" help:"How long a pending delete VM/disks cleaned automatically, default 3 days"` PendingDeleteMaxCleanBatchSize int `default:"50" help:"How many pending delete servers can be clean in a batch"` - PrepaidExpireCheckSeconds int `default:"600" help:"How long to wait to scan expired prepaid VM or disks, default is 10 minutes"` - ExpiredPrepaidMaxCleanBatchSize int `default:"50" help:"How many expired prepaid servers can be deleted in a batch"` + PrepaidExpireCheckSeconds int `default:"600" help:"How long to wait to scan expired prepaid VM or disks, default is 10 minutes"` + ExpiredPrepaidMaxCleanBatchSize int `default:"50" help:"How many expired prepaid servers can be deleted in a batch"` LoadbalancerPendingDeleteCheckInterval int `default:"3600" help:"Interval between checks of pending deleted loadbalancer objects, defaults to 1h"` diff --git a/pkg/compute/tasks/disk_delete_task.go b/pkg/compute/tasks/disk_delete_task.go index 17eaccaae6..65cba3e7e9 100644 --- a/pkg/compute/tasks/disk_delete_task.go +++ b/pkg/compute/tasks/disk_delete_task.go @@ -5,6 +5,7 @@ import ( "yunion.io/x/jsonutils" + "fmt" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -52,34 +53,33 @@ func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SD self.OnGuestDiskDeleteComplete(ctx, disk, nil) } else { if len(disk.BackupStorageId) > 0 { - self.SetStage("OnMasterStorageDeleteDiskSucc", nil) + self.SetStage("OnMasterStorageDeleteDiskComplete", nil) } else { - self.SetStage("OnGuestDiskDeleteSucc", nil) + self.SetStage("OnGuestDiskDeleteComplete", nil) } - if host == nil { - self.OnGuestDiskDeleteFailed(ctx, disk, httperrors.NewNotFoundError("fail to find master host")) - } else if err := host.GetHostDriver().RequestDeallocateDiskOnHost(ctx, host, storage, disk, self); err != nil { - self.OnGuestDiskDeleteFailed(ctx, disk, err) - self.SetStage("OnGuestDiskDeleteComplete", nil) if host == nil { self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString("fail to find master host")) - } else if err := host.GetHostDriver().RequestDeallocateDiskOnHost(host, storage, disk, self); err != nil { + } else if err := host.GetHostDriver().RequestDeallocateDiskOnHost(ctx, host, storage, disk, self); err != nil { self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString(err.Error())) } } } -func (self *DiskDeleteTask) OnMasterStorageDeleteDiskSucc(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { - self.SetStage("OnGuestDiskDeleteSucc", nil) +func (self *DiskDeleteTask) OnMasterStorageDeleteDiskComplete(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { + self.SetStage("OnGuestDiskDeleteComplete", nil) storage := models.StorageManager.FetchStorageById(disk.BackupStorageId) host := storage.GetMasterHost() if host == nil { - self.OnGuestDiskDeleteFailed(ctx, disk, httperrors.NewNotFoundError("backup storage %s fail to find master host", disk.BackupStorageId)) + self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString(fmt.Sprintf("backup storage %s fail to find master host", disk.BackupStorageId))) } else if err := host.GetHostDriver().RequestDeallocateDiskOnHost(ctx, host, storage, disk, self); err != nil { - self.OnGuestDiskDeleteFailed(ctx, disk, err) + self.OnGuestDiskDeleteCompleteFailed(ctx, disk, jsonutils.NewString(err.Error())) } } +func (self *DiskDeleteTask) OnMasterStorageDeleteDiskCompleteFailed(ctx context.Context, disk *models.SDisk, resion jsonutils.JSONObject) { + self.OnGuestDiskDeleteCompleteFailed(ctx, disk, resion) +} + func (self *DiskDeleteTask) startPendingDeleteDisk(ctx context.Context, disk *models.SDisk) { disk.DoPendingDelete(ctx, self.UserCred) self.SetStageComplete(ctx, nil) diff --git a/pkg/compute/tasks/disk_resize_task.go b/pkg/compute/tasks/disk_resize_task.go index a8d4dec43e..32f6d102b2 100644 --- a/pkg/compute/tasks/disk_resize_task.go +++ b/pkg/compute/tasks/disk_resize_task.go @@ -107,7 +107,6 @@ func (self *DiskResizeTask) OnDiskResizeComplete(ctx context.Context, disk *mode self.finalReleasePendingUsage(ctx) } - func (self *DiskResizeTask) OnDiskResizeCompleteFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { disk.SetDiskReady(ctx, self.GetUserCred(), data.String()) db.OpsLog.LogEvent(disk, db.ACT_RESIZE_FAIL, disk.GetShortDesc(ctx), self.UserCred) diff --git a/pkg/compute/usages/handler.go b/pkg/compute/usages/handler.go index 846eb2afb7..435f6a53d4 100644 --- a/pkg/compute/usages/handler.go +++ b/pkg/compute/usages/handler.go @@ -579,4 +579,4 @@ func SnapshotUsage(projectId string, rangeObj db.IStandaloneModel, providers []s count := make(map[string]interface{}) count[getKey(projectId, "snapshot")] = cnt return count -} \ No newline at end of file +} diff --git a/pkg/mcclient/options/servers.go b/pkg/mcclient/options/servers.go index b638d0f0d9..dacbdfe44c 100644 --- a/pkg/mcclient/options/servers.go +++ b/pkg/mcclient/options/servers.go @@ -267,7 +267,6 @@ type ServerSecGroupsOptions struct { Secgrp []string `help:"Ids of Security Groups" metavar:"Security Groups" positional:"true"` } - type ServerSendKeyOptions struct { ID string `help:"ID or Name of server" metavar:"Guest" json:"-"` KEYS string `help:"Special keys to send, eg. ctrl, alt, f12, shift, etc, separated by \"-\""` diff --git a/pkg/util/aliyun/aliyun.go b/pkg/util/aliyun/aliyun.go index 6d381591ba..cf25abae28 100644 --- a/pkg/util/aliyun/aliyun.go +++ b/pkg/util/aliyun/aliyun.go @@ -12,9 +12,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + "time" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/models" - "time" ) const ( diff --git a/pkg/util/aliyun/region.go b/pkg/util/aliyun/region.go index 80c0e864e6..e8956fc397 100644 --- a/pkg/util/aliyun/region.go +++ b/pkg/util/aliyun/region.go @@ -84,6 +84,8 @@ func (self *SRegion) ecsRequest(apiName string, params map[string]string) (jsonu if err != nil { return nil, err } + return jsonRequest(client, "ecs.aliyuncs.com", ALIYUN_API_VERSION, apiName, params) +} func (self *SRegion) lbRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) { client, err := self.getSdkClient() diff --git a/pkg/util/aliyun/storagecache.go b/pkg/util/aliyun/storagecache.go index 77f5d43004..e540750267 100644 --- a/pkg/util/aliyun/storagecache.go +++ b/pkg/util/aliyun/storagecache.go @@ -105,7 +105,6 @@ func (self *SStoragecache) GetPath() string { return "" } - func (self *SStoragecache) UploadImage(ctx context.Context, userCred mcclient.TokenCredential, imageId string, osArch, osType, osDist, osVersion string, extId string, isForce bool) (string, error) { if len(extId) > 0 { log.Debugf("UploadImage: Image external ID exists %s", extId) diff --git a/pkg/util/aws/storagecache.go b/pkg/util/aws/storagecache.go index 666280febf..6625287b81 100644 --- a/pkg/util/aws/storagecache.go +++ b/pkg/util/aws/storagecache.go @@ -15,7 +15,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" - "yunion.io/x/jsonutils" "yunion.io/x/log"