mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #11 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:hotfix/qj-zone-create-missing-region to release/2.0.0
* commit 'e07968a1eabcdc9ef68aa39f835fca36b820d0da': 修正:zone-create时候没有region时创建zone失败
This commit is contained in:
@@ -106,6 +106,7 @@ func init() {
|
||||
NameCN string `help:"Name in Chinese"`
|
||||
Desc string `metavar:"<DESCRIPTION>" help:"Description"`
|
||||
Location string `help:"Location"`
|
||||
Region string `help:"Cloudregion in which zone created"`
|
||||
}
|
||||
R(&ZoneCreateOptions{}, "zone-create", "Create a zone", func(s *mcclient.ClientSession, args *ZoneCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
@@ -119,6 +120,9 @@ func init() {
|
||||
if len(args.Location) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Location), "location")
|
||||
}
|
||||
if len(args.Region) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Region), "region")
|
||||
}
|
||||
zone, err := modules.Zones.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -2,14 +2,15 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/yunionio/jsonutils"
|
||||
"github.com/yunionio/log"
|
||||
"github.com/yunionio/onecloud/pkg/mcclient"
|
||||
"github.com/yunionio/onecloud/pkg/cloudcommon/db"
|
||||
"github.com/yunionio/onecloud/pkg/cloudprovider"
|
||||
"github.com/yunionio/onecloud/pkg/httperrors"
|
||||
"github.com/yunionio/onecloud/pkg/mcclient"
|
||||
"github.com/yunionio/pkg/tristate"
|
||||
"github.com/yunionio/pkg/util/compare"
|
||||
"github.com/yunionio/sqlchemy"
|
||||
@@ -288,6 +289,10 @@ return ret
|
||||
func zoneExtra(zone *SZone, extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
usage := zone.GeneralUsage()
|
||||
extra.Update(jsonutils.Marshal(usage))
|
||||
region := zone.GetRegion()
|
||||
if region != nil {
|
||||
extra.Add(jsonutils.NewString(region.Name), "cloudregion")
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
@@ -607,3 +612,23 @@ func (self *SZone) isUsable() bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SZoneManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
regionStr := jsonutils.GetAnyString(query, []string{"region", "region_id", "cloudregion", "cloudregion_id"})
|
||||
var regionId string
|
||||
if len(regionStr) > 0 {
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName("", regionStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("Region %s not found", regionStr)
|
||||
} else {
|
||||
return nil, httperrors.NewInternalServerError("Query region %s fail %s", regionStr, err)
|
||||
}
|
||||
}
|
||||
regionId = regionObj.GetId()
|
||||
} else {
|
||||
regionId = "default"
|
||||
}
|
||||
data.Add(jsonutils.NewString(regionId), "cloudregion_id")
|
||||
return manager.SStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user