Merge pull request #15094 from gouqi11/addNodeCount

add modelarts nodecount
This commit is contained in:
Zexi Li
2022-09-28 15:51:34 +08:00
committed by GitHub
8 changed files with 31 additions and 2 deletions
+2
View File
@@ -33,6 +33,8 @@ type ModelartsPoolCreateInput struct {
CloudregionResourceInput
CloudproviderResourceInput
NodeCount int
}
type ModelartsPoolUpdateInput struct {
+1
View File
@@ -939,6 +939,7 @@ type ICloudModelartsPool interface {
GetProjectId() string
GetInstanceType() string
GetWorkType() string
GetNodeCount() int
}
type ICloudModelartsPoolSku interface {
+1
View File
@@ -21,6 +21,7 @@ type ModelartsPoolCreateOption struct {
PeriodNum uint
AutoRenew uint
InstanceType string
NodeCount int
NetworkId string
WorkType string
+9
View File
@@ -70,6 +70,7 @@ type SModelartsPool struct {
SDeletePreventableResourceBase
InstanceType string `width:"72" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
NodeCount int `nullable:"false" list:"user" create:"required"`
WorkType string `width:"72" charset:"ascii" nullable:"true" list:"user" update:"user" create:"optional"`
// CPU 架构 x86|xarm
CpuArch string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"`
@@ -149,6 +150,12 @@ func (man *SModelartsPoolManager) QueryDistinctExtraField(q *sqlchemy.SQuery, fi
func (man *SModelartsPoolManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.ModelartsPoolCreateInput) (api.ModelartsPoolCreateInput, error) {
var err error
if input.NodeCount <= 0 {
input.NodeCount = 1
}
if input.NodeCount > 200 {
return input, errors.Wrap(errors.ErrNotSupported, "node count must between 1 and 200")
}
_, err = validators.ValidateModel(userCred, CloudproviderManager, &input.CloudproviderId)
if err != nil {
return input, err
@@ -400,6 +407,7 @@ func (self *SModelartsPool) SyncWithCloudModelartsPool(ctx context.Context, user
self.InstanceType = instanceName
self.WorkType = ext.GetWorkType()
self.CpuArch = sku.CpuArch
self.NodeCount = ext.GetNodeCount()
return nil
})
if err != nil {
@@ -428,6 +436,7 @@ func (self *SCloudregion) newFromCloudModelartsPool(ctx context.Context, userCre
pool.Status = ext.GetStatus()
pool.WorkType = ext.GetWorkType()
pool.InstanceType = ext.GetInstanceType()
pool.NodeCount = ext.GetNodeCount()
if createdAt := ext.GetCreatedAt(); !createdAt.IsZero() {
pool.CreatedAt = createdAt
}
@@ -56,6 +56,7 @@ func (self *ModelartsPoolCreateTask) OnInit(ctx context.Context, obj db.IStandal
Name: pool.Name,
InstanceType: pool.InstanceType,
WorkType: pool.WorkType,
NodeCount: pool.NodeCount,
}
ipool, err := iRegion.CreateIModelartsPool(opts)
@@ -46,6 +46,7 @@ type ModelartsPoolCreateOption struct {
InstanceType string `help:"Instance Type"`
WorkType string `help:"Work Type"`
CpuArch string `help:"Cpu Arch"`
NodeCount int `help:"Node Count"`
CloudregionId string `help:"Cloud Region ID"`
}
+8 -1
View File
@@ -145,7 +145,7 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
"resources": []map[string]interface{}{
{
"flavor": args.InstanceType,
"count": 1,
"count": args.NodeCount,
},
},
},
@@ -349,3 +349,10 @@ func (self *SModelartsPool) GetInstanceType() string {
func (self *SModelartsPool) GetWorkType() string {
return strings.Join(self.Spec.Scope, ",")
}
func (self *SModelartsPool) GetNodeCount() int {
if len(self.Spec.Resource) < 1 {
return 0
}
return self.Spec.Resource[0].Count
}
+8 -1
View File
@@ -144,7 +144,7 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
"resources": []map[string]interface{}{
{
"flavor": args.InstanceType,
"count": 1,
"count": args.NodeCount,
},
},
},
@@ -348,3 +348,10 @@ func (self *SModelartsPool) GetInstanceType() string {
func (self *SModelartsPool) GetWorkType() string {
return strings.Join(self.Spec.Scope, ",")
}
func (self *SModelartsPool) GetNodeCount() int {
if len(self.Spec.Resource) < 1 {
return 0
}
return self.Spec.Resource[0].Count
}