修正一些错误信息描述

This commit is contained in:
屈轩
2019-03-07 15:42:33 +08:00
parent 921038826d
commit 58ee33c3f0
21 changed files with 41 additions and 44 deletions
+1 -1
View File
@@ -207,7 +207,7 @@ func (model *SVirtualResourceBase) AllowPerformChangeOwner(ctx context.Context,
func (model *SVirtualResourceBase) PerformChangeOwner(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
tenant := jsonutils.GetAnyString(data, []string{"project", "tenant", "project_id", "tenant_id"})
if len(tenant) == 0 {
return nil, httperrors.NewInputParameterError("missing parameter tenant")
return nil, httperrors.NewMissingParameterError("tenant_id")
}
tobj, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, tenant)
if tobj == nil {
+1 -2
View File
@@ -13,7 +13,6 @@ import (
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
)
type SManagedVirtualizationHostDriver struct {
@@ -147,7 +146,7 @@ func (self *SManagedVirtualizationHostDriver) RequestSaveUploadImageOnHost(ctx c
}
iStoragecache := iStorage.GetIStoragecache()
if iStoragecache == nil {
return httperrors.NewResourceNotFoundError("fail to find iStoragecache for storage: %s", iStorage.GetName())
return fmt.Errorf("fail to find iStoragecache for storage: %s", iStorage.GetName())
}
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
snapshot, err := iDisk.CreateISnapshot(ctx, fmt.Sprintf("Snapshot-%s", imageId), "PrepareSaveImage")
+1 -1
View File
@@ -467,7 +467,7 @@ func (self *SCloudprovider) AllowPerformChangeProject(ctx context.Context, userC
func (self *SCloudprovider) PerformChangeProject(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
project, err := data.GetString("project")
if err != nil {
return nil, httperrors.NewInputParameterError("Missing project parameter")
return nil, httperrors.NewMissingParameterError("project")
}
tenant, err := db.TenantCacheManager.FetchTenantByIdOrName(ctx, project)
+1 -1
View File
@@ -299,7 +299,7 @@ func (self *SCloudregion) PerformDefaultVpc(ctx context.Context, userCred mcclie
}
vpcStr, _ := data.GetString("vpc")
if len(vpcStr) == 0 {
return nil, httperrors.NewInputParameterError("no vpc id")
return nil, httperrors.NewMissingParameterError("vpc")
}
findVpc := false
for _, vpc := range vpcs {
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"yunion.io/x/log"
"database/sql"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
@@ -66,7 +67,7 @@ func (self *SDynamicschedtag) AllowDeleteItem(ctx context.Context, userCred mccl
func validateDynamicSchedtagInputData(data *jsonutils.JSONDict, create bool) error {
condStr := jsonutils.GetAnyString(data, []string{"condition"})
if len(condStr) == 0 && create {
return httperrors.NewInputParameterError("empty condition")
return httperrors.NewMissingParameterError("condition")
}
if len(condStr) > 0 && !conditionparser.IsValid(condStr) {
return httperrors.NewInputParameterError("invalid condition")
@@ -74,7 +75,7 @@ func validateDynamicSchedtagInputData(data *jsonutils.JSONDict, create bool) err
schedStr := jsonutils.GetAnyString(data, []string{"schedtag", "schedtag_id"})
if len(schedStr) == 0 && create {
return httperrors.NewInputParameterError("missing schedtag")
return httperrors.NewMissingParameterError("schedtag_id")
}
if len(schedStr) > 0 {
schedObj, err := SchedtagManager.FetchByIdOrName(nil, schedStr)
+3 -3
View File
@@ -457,7 +457,7 @@ func (manager *SElasticipManager) getEipByExtEip(ctx context.Context, userCred m
func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
regionStr := jsonutils.GetAnyString(data, []string{"region", "region_id"})
if len(regionStr) == 0 {
return nil, httperrors.NewInputParameterError("Missing region/region_id")
return nil, httperrors.NewMissingParameterError("region_id")
}
region, err := CloudregionManager.FetchByIdOrName(nil, regionStr)
if err != nil {
@@ -471,7 +471,7 @@ func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCr
managerStr := jsonutils.GetAnyString(data, []string{"manager", "manager_id"})
if len(managerStr) == 0 {
return nil, httperrors.NewInputParameterError("Missing manager/manager_id")
return nil, httperrors.NewMissingParameterError("manager_id")
}
provider, err := CloudproviderManager.FetchByIdOrName(nil, managerStr)
@@ -577,7 +577,7 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient.
instanceId := jsonutils.GetAnyString(data, []string{"instance", "instance_id"})
if len(instanceId) == 0 {
return nil, httperrors.NewInputParameterError("Missing instance_id")
return nil, httperrors.NewMissingParameterError("instance_id")
}
instanceType := jsonutils.GetAnyString(data, []string{"instance_type"})
if len(instanceType) == 0 {
+12 -12
View File
@@ -249,7 +249,7 @@ func (self *SGuest) PerformLiveMigrate(ctx context.Context, userCred mcclient.To
return nil, err
}
if image.DiskFormat != "qcow2" {
return nil, httperrors.NewBadRequestError("Live migrate only support image fromat qocw2")
return nil, httperrors.NewBadRequestError("Live migrate only support image format qocw2")
}
if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_SUSPEND}) {
cdrom := self.getCdrom()
@@ -1369,7 +1369,7 @@ func (self *SGuest) PerformChangeIpaddr(ctx context.Context, userCred mcclient.T
netDesc, err := data.Get("net_desc")
if err != nil {
log.Errorf("net_desc not found")
return nil, httperrors.NewInputParameterError("missing net_desc")
return nil, httperrors.NewMissingParameterError("net_desc")
}
conf, err := parseNetworkInfo(userCred, netDesc)
if err != nil {
@@ -2008,7 +2008,7 @@ func (self *SGuest) AllowPerformSendkeys(ctx context.Context, userCred mcclient.
func (self *SGuest) PerformSendkeys(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if self.Hypervisor != HYPERVISOR_KVM {
return nil, httperrors.NewUnsupportOperationError("Not allow for hypervisor %s", self.Hypervisor)
return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.Hypervisor)
}
if self.Status != VM_RUNNING {
return nil, httperrors.NewInvalidStatusError("Cannot send keys in status %s", self.Status)
@@ -2096,7 +2096,7 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
}
eipStr := jsonutils.GetAnyString(data, []string{"eip", "eip_id"})
if len(eipStr) == 0 {
return nil, httperrors.NewInputParameterError("missing eip or eip_id")
return nil, httperrors.NewMissingParameterError("eip_id")
}
eipObj, err := ElasticipManager.FetchByIdOrName(userCred, eipStr)
if err != nil {
@@ -2178,7 +2178,7 @@ func (self *SGuest) AllowPerformCreateEip(ctx context.Context, userCred mcclient
func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
bw, err := data.Int("bandwidth")
if err != nil {
return nil, httperrors.NewInputParameterError("Missing bandwidth")
return nil, httperrors.NewMissingParameterError("bandwidth")
}
chargeType, _ := data.GetString("charge_type")
@@ -2238,7 +2238,7 @@ func (self *SGuest) AllowPerformUserData(ctx context.Context, userCred mcclient.
func (self *SGuest) PerformUserData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
userData, err := data.GetString("user_data")
if err != nil {
return nil, httperrors.NewInputParameterError("missing user_data %s", err)
return nil, httperrors.NewMissingParameterError("user_data")
}
err = self.setUserData(ctx, userCred, userData)
if err != nil {
@@ -2297,7 +2297,7 @@ func (manager *SGuestManager) AllowPerformDirtyServerStart(ctx context.Context,
func (manager *SGuestManager) PerformDirtyServerStart(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
guestId, err := data.GetString("guest_id")
if err != nil {
return nil, httperrors.NewBadRequestError("Missing guest_id")
return nil, httperrors.NewMissingParameterError("guest_id")
}
guest := manager.FetchGuestById(guestId)
if guest == nil {
@@ -2305,7 +2305,7 @@ func (manager *SGuestManager) PerformDirtyServerStart(ctx context.Context, userC
}
hostId, _ := data.GetString("host_id")
if len(hostId) == 0 {
return nil, httperrors.NewBadRequestError("Missing host_id or host id is nil?")
return nil, httperrors.NewMissingParameterError("host_id")
}
if guest.HostId == hostId {
@@ -2327,7 +2327,7 @@ func (manager *SGuestManager) AllowPerformDirtyServerVerify(ctx context.Context,
func (manager *SGuestManager) PerformDirtyServerVerify(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
guestId, err := data.GetString("guest_id")
if err != nil {
return nil, httperrors.NewBadRequestError("Missing guest_id")
return nil, httperrors.NewMissingParameterError("guest_id")
}
guest := manager.FetchGuestById(guestId)
if guest == nil {
@@ -2335,7 +2335,7 @@ func (manager *SGuestManager) PerformDirtyServerVerify(ctx context.Context, user
}
hostId, _ := data.GetString("host_id")
if len(hostId) == 0 {
return nil, httperrors.NewBadRequestError("Missing host_id or host id is nil?")
return nil, httperrors.NewMissingParameterError("host_id")
}
if guest.HostId != hostId && guest.BackupHostId != hostId {
@@ -2485,7 +2485,7 @@ func (self *SGuest) AllowPerformSetExtraOption(ctx context.Context, userCred mcc
func (self *SGuest) PerformSetExtraOption(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
key, err := data.GetString("key")
if err != nil {
return nil, httperrors.NewBadRequestError("Option key required")
return nil, httperrors.NewMissingParameterError("key")
}
value, _ := data.GetString("value")
extraOptions := self.GetExtraOptions(userCred)
@@ -2513,7 +2513,7 @@ func (self *SGuest) AllowPerformDelExtraOption(ctx context.Context, userCred mcc
func (self *SGuest) PerformDelExtraOption(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
key, err := data.GetString("key")
if err != nil {
return nil, httperrors.NewBadRequestError("Option key required")
return nil, httperrors.NewMissingParameterError("key")
}
extraOptions := self.GetExtraOptions(userCred)
extraOptions.Remove(key)
+2 -2
View File
@@ -777,7 +777,7 @@ func (self *SGuest) ValidateUpdateData(ctx context.Context, userCred mcclient.To
if data.Contains("name") {
if name, _ := data.GetString("name"); len(name) < 2 {
return nil, httperrors.NewInputParameterError("name is to short")
return nil, httperrors.NewInputParameterError("name is too short")
}
}
return self.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
@@ -885,7 +885,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
}
if vmemSize == 0 {
return nil, httperrors.NewInputParameterError("Missing memory size")
return nil, httperrors.NewMissingParameterError("vmem_size")
}
if vcpuCount == 0 {
vcpuCount = 1
+1 -1
View File
@@ -690,7 +690,7 @@ func (self *SHost) AllowPerformRenewPrepaidRecycle(ctx context.Context, userCred
func (self *SHost) PerformRenewPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
durationStr := jsonutils.GetAnyString(data, []string{"duration"})
if len(durationStr) == 0 {
return nil, httperrors.NewInputParameterError("missing duration")
return nil, httperrors.NewMissingParameterError("duration")
}
bc, err := billing.ParseBillingCycle(durationStr)
+2 -2
View File
@@ -306,10 +306,10 @@ func (man *SLoadbalancerListenerManager) checkTypeV(listenerType string) validat
func (man *SLoadbalancerListenerManager) validateAcl(aclStatusV *validators.ValidatorStringChoices, aclTypeV *validators.ValidatorStringChoices, aclV *validators.ValidatorModelIdOrName, data *jsonutils.JSONDict) error {
if aclStatusV.Value == consts.LB_BOOL_ON {
if aclV.Model == nil {
return httperrors.NewInputParameterError("missing acl")
return httperrors.NewMissingParameterError("acl")
}
if len(aclTypeV.Value) == 0 {
return httperrors.NewInputParameterError("missing acl_type")
return httperrors.NewMissingParameterError("acl_type")
}
} else {
data.Set("acl_id", jsonutils.NewString(""))
+2 -2
View File
@@ -1125,11 +1125,11 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred
wireId, _ := data.GetString("wire_id")
if len(wireId) == 0 {
return nil, httperrors.NewInputParameterError("missing wire_id")
return nil, httperrors.NewMissingParameterError("wire_id")
}
wire := WireManager.FetchWireById(wireId)
if wire == nil {
return nil, httperrors.NewInputParameterError("wire_id %s not valid", wireId)
return nil, httperrors.NewResourceNotFoundError("wire %s not found", wireId)
}
vpc := wire.getVpc()
if vpc == nil {
+1 -1
View File
@@ -50,7 +50,7 @@ func validateSchedpolicyInputData(data *jsonutils.JSONDict, create bool) error {
strategyStr := jsonutils.GetAnyString(data, []string{"strategy"})
if len(strategyStr) == 0 && create {
return httperrors.NewInputParameterError("missing strategy")
return httperrors.NewMissingParameterError("strategy")
}
if len(strategyStr) > 0 && !utils.IsInStringArray(strategyStr, STRATEGY_LIST) {
+1 -1
View File
@@ -134,7 +134,7 @@ func (self *SSecurityGroupRule) BeforeInsert() {
func (manager *SSecurityGroupRuleManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
defsecgroup, _ := data.GetString("secgroup")
if len(defsecgroup) == 0 {
return nil, httperrors.NewInputParameterError("Missing Security Group info")
return nil, httperrors.NewMissingParameterError("secgroup")
}
secgroup, _ := SecurityGroupManager.FetchByIdOrName(userCred, defsecgroup)
if secgroup == nil {
+1 -1
View File
@@ -214,7 +214,7 @@ func (self *SSecurityGroup) AllowPerformClone(ctx context.Context, userCred mccl
func (self *SSecurityGroup) PerformClone(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if name, _ := data.GetString("name"); len(name) == 0 {
return nil, httperrors.NewInputParameterError("Missing name params")
return nil, httperrors.NewMissingParameterError("name")
} else {
sql := SecurityGroupManager.Query()
sql = SecurityGroupManager.FilterByName(sql, name)
+1 -1
View File
@@ -376,7 +376,7 @@ func (self *SStoragecache) AllowPerformUncacheImage(ctx context.Context, userCre
func (self *SStoragecache) PerformUncacheImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
imageStr, _ := data.GetString("image")
if len(imageStr) == 0 {
return nil, httperrors.NewInputParameterError("missing image id or name")
return nil, httperrors.NewMissingParameterError("image")
}
isForce := jsonutils.QueryBoolean(data, "is_force", false)
+3 -6
View File
@@ -391,19 +391,16 @@ func (manager *SVpcManager) InitializeData() error {
func (manager *SVpcManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
regionId, err := data.GetString("cloudregion_id")
if err != nil {
return nil, httperrors.NewInputParameterError("No cloudregion_id")
return nil, httperrors.NewMissingParameterError("cloudregion_id")
}
region := CloudregionManager.FetchRegionById(regionId)
if region == nil {
return nil, httperrors.NewInputParameterError("Invalid cloudregion_id")
}
if region.isManaged() {
managerStr, _ := data.GetString("manager_id")
managerStr := jsonutils.GetAnyString(data, []string{"manager_id", "manager"})
if len(managerStr) == 0 {
managerStr, _ = data.GetString("manager")
if len(managerStr) == 0 {
return nil, httperrors.NewInputParameterError("cloud provider/manager must be provided")
}
return nil, httperrors.NewMissingParameterError("manager_id")
}
managerObj := CloudproviderManager.FetchCloudproviderByIdOrName(managerStr)
if err != nil {
+1 -1
View File
@@ -78,7 +78,7 @@ func (manager *SWireManager) ValidateCreateData(ctx context.Context, userCred mc
vpcStr := jsonutils.GetAnyString(data, []string{"vpc", "vpc_id"})
if len(vpcStr) == 0 {
return nil, httperrors.NewInternalServerError("missing vpc")
return nil, httperrors.NewMissingParameterError("vpc_id")
}
if len(vpcStr) > 0 {
+1 -1
View File
@@ -255,7 +255,7 @@ func guestDestPrepareMigrate(ctx context.Context, sid string, body jsonutils.JSO
} else {
targetStorageId, _ := disks[0].GetString("target_storage_id")
if len(targetStorageId) == 0 {
return nil, httperrors.NewInputParameterError("Disk desc missing target storage id")
return nil, httperrors.NewMissingParameterError("target_storage_id")
}
params.TargetStorageId = targetStorageId
}
+1
View File
@@ -3,6 +3,7 @@ package httperrors
import (
"bytes"
"fmt"
"yunion.io/x/onecloud/pkg/util/httputils"
)
+1 -1
View File
@@ -1091,7 +1091,7 @@ func (self *SImage) AllowPerformUpdateTorrentStatus(ctx context.Context, userCre
func (self *SImage) PerformUpdateTorrentStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
formatStr, _ := query.GetString("format")
if len(formatStr) == 0 {
return nil, httperrors.NewInputParameterError("missing parameter format")
return nil, httperrors.NewMissingParameterError("format")
}
subimg := ImageSubformatManager.FetchSubImage(self.Id, formatStr)
if subimg == nil {
+1 -2
View File
@@ -14,7 +14,6 @@ import (
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules"
@@ -336,7 +335,7 @@ func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imag
} else if imageList, err := bucket.ListObjects(oss.Prefix(fmt.Sprintf("%sexport", strings.Replace(extId, "-", "", -1)))); err != nil {
return nil, err
} else if len(imageList.Objects) != 1 {
return nil, httperrors.NewResourceNotFoundError("exported image not find")
return nil, fmt.Errorf("exported image not find")
} else if err := bucket.DownloadFile(imageList.Objects[0].Key, tmpImageFile.Name(), 12*1024*1024, oss.Routines(3), oss.Progress(&OssProgressListener{})); err != nil {
return nil, err
} else {