mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #15395 from gouqi11/fix/modelartsSkuForMaster
fix(region): fix modelarts sku and cidr
This commit is contained in:
@@ -84,7 +84,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221121093718-ceb2d0e88331
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122060402-9ac1c621d6d7
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1176,8 +1176,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221121093718-ceb2d0e88331 h1:2Llg6nfloPMWhgB4CjxFdbH1QaThsWs8DayYhPK9N9E=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221121093718-ceb2d0e88331/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122060402-9ac1c621d6d7 h1:TEpAIggwNfnq63LWkXsBVQUXjHKXqhTPUQsGdqNppn4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122060402-9ac1c621d6d7/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -39,7 +39,8 @@ type ModelartsPoolCreateInput struct {
|
||||
CloudregionResourceInput
|
||||
CloudproviderResourceInput
|
||||
|
||||
NodeCount int
|
||||
NodeCount int `json:"node_count"`
|
||||
Cidr string `json:"cidr"`
|
||||
}
|
||||
|
||||
type ModelartsPoolUpdateInput struct {
|
||||
|
||||
@@ -36,5 +36,6 @@ type ModelartsPoolSkuListInput struct {
|
||||
apis.ExternalizedResourceBaseListInput
|
||||
|
||||
RegionalFilterListInput
|
||||
ManagedResourceListInput
|
||||
ProcessorType string
|
||||
CpuArch string
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -56,7 +55,6 @@ func init() {
|
||||
}
|
||||
|
||||
type SModelartsPoolSku struct {
|
||||
SManagedResourceBase
|
||||
db.SEnabledStatusStandaloneResourceBase
|
||||
db.SExternalizedResourceBase
|
||||
SCloudregionResourceBase
|
||||
@@ -76,6 +74,8 @@ type SModelartsPoolSku struct {
|
||||
NpuSize int `nullable:"true" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 内存
|
||||
Memory int `nullable:"true" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 处理器类型
|
||||
ProcessorType string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"admin_optional" update:"admin"`
|
||||
}
|
||||
|
||||
func (manager *SModelartsPoolSkuManager) GetContextManagers() [][]db.IModelManager {
|
||||
@@ -97,15 +97,16 @@ func (man *SModelartsPoolSkuManager) ListItemFilter(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SExternalizedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SManagedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.CpuArch) > 0 {
|
||||
q = q.Equals("cpu_arch", query.CpuArch)
|
||||
}
|
||||
if len(query.ProcessorType) > 0 {
|
||||
q = q.Equals("processor_type", query.ProcessorType)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -123,10 +124,6 @@ func (man *SModelartsPoolSkuManager) OrderByExtraFields(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SExternalizedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SManagedResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
|
||||
@@ -190,11 +187,8 @@ func (manager *SModelartsPoolSkuManager) ListItemExportKeys(ctx context.Context,
|
||||
|
||||
return q, nil
|
||||
}
|
||||
func (self *SCloudregion) GetModelartsPoolSkus(managerId string) ([]SModelartsPoolSku, error) {
|
||||
func (self *SCloudregion) GetModelartsPoolSkus() ([]SModelartsPoolSku, error) {
|
||||
q := ModelartsPoolSkuManager.Query().Equals("cloudregion_id", self.Id)
|
||||
if len(managerId) > 0 {
|
||||
q = q.Equals("manager_id", managerId)
|
||||
}
|
||||
ret := []SModelartsPoolSku{}
|
||||
err := db.FetchModelObjects(ModelartsPoolSkuManager, q, &ret)
|
||||
if err != nil {
|
||||
@@ -208,7 +202,7 @@ func (self *SCloudregion) SyncModelartsPoolSkus(ctx context.Context, userCred mc
|
||||
lockman.LockRawObject(ctx, self.Provider, "modelarts-pool-sku")
|
||||
defer lockman.ReleaseRawObject(ctx, self.Provider, "modelarts-pool-sku")
|
||||
result := compare.SyncResult{}
|
||||
dbPoolSku, err := self.GetModelartsPoolSkus(provider.Id)
|
||||
dbPoolSku, err := self.GetModelartsPoolSkus()
|
||||
if err != nil {
|
||||
result.Error(err)
|
||||
return result
|
||||
@@ -236,7 +230,6 @@ func (self *SCloudregion) SyncModelartsPoolSkus(ctx context.Context, userCred mc
|
||||
|
||||
// 和云上资源属性进行同步
|
||||
for i := 0; i < len(commondb); i++ {
|
||||
log.Errorln("this is commonext", commonext[i])
|
||||
err := commondb[i].syncWithCloudSku(ctx, userCred, commonext[i])
|
||||
if err != nil {
|
||||
result.UpdateError(err)
|
||||
@@ -271,6 +264,7 @@ func (self *SModelartsPoolSku) syncWithCloudSku(ctx context.Context, userCred mc
|
||||
self.NpuType = isku.GetNpuType()
|
||||
self.NpuSize = isku.GetNpuSize()
|
||||
self.ExternalId = isku.GetGlobalId()
|
||||
self.ProcessorType = isku.GetProcessorType()
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
@@ -283,6 +277,7 @@ func (self *SCloudregion) newFromCloudModelartsPoolSku(ctx context.Context, user
|
||||
sku.Name = isku.GetName()
|
||||
sku.CpuCount = isku.GetCpuCoreCount()
|
||||
sku.CpuArch = isku.GetCpuArch()
|
||||
sku.ProcessorType = isku.GetProcessorType()
|
||||
sku.Status = isku.GetStatus()
|
||||
sku.Type = isku.GetPoolType()
|
||||
sku.CreatedAt = isku.GetCreatedAt()
|
||||
@@ -292,6 +287,5 @@ func (self *SCloudregion) newFromCloudModelartsPoolSku(ctx context.Context, user
|
||||
sku.NpuType = isku.GetNpuType()
|
||||
sku.NpuSize = isku.GetNpuSize()
|
||||
sku.ExternalId = isku.GetGlobalId()
|
||||
sku.ManagerId = provider.Id
|
||||
return ModelartsPoolSkuManager.TableSpec().Insert(ctx, &sku)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
@@ -74,6 +75,7 @@ type SModelartsPool struct {
|
||||
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"`
|
||||
Cidr string `width:"32" charset:"ascii" nullable:"true" list:"user" create:"admin_optional"`
|
||||
}
|
||||
|
||||
func (manager *SModelartsPoolManager) GetContextManagers() [][]db.IModelManager {
|
||||
@@ -156,6 +158,13 @@ func (man *SModelartsPoolManager) ValidateCreateData(ctx context.Context, userCr
|
||||
if input.NodeCount > 200 {
|
||||
return input, errors.Wrap(errors.ErrNotSupported, "node count must between 1 and 200")
|
||||
}
|
||||
if len(input.Cidr) == 0 {
|
||||
input.Cidr = "192.168.128.0/17"
|
||||
}
|
||||
_, err = netutils.NewIPV4Prefix(input.Cidr)
|
||||
if err != nil {
|
||||
return input, httperrors.NewInputParameterError("invalid cidr: %s", input.Cidr)
|
||||
}
|
||||
_, err = validators.ValidateModel(userCred, CloudproviderManager, &input.CloudproviderId)
|
||||
if err != nil {
|
||||
return input, err
|
||||
|
||||
@@ -58,6 +58,7 @@ func (self *ModelartsPoolCreateTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
InstanceType: pool.InstanceType,
|
||||
WorkType: pool.WorkType,
|
||||
NodeCount: pool.NodeCount,
|
||||
Cidr: pool.Cidr,
|
||||
}
|
||||
|
||||
ipool, err := iRegion.CreateIModelartsPool(opts)
|
||||
@@ -72,7 +73,7 @@ func (self *ModelartsPoolCreateTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
}
|
||||
|
||||
// withDelay
|
||||
time.Sleep(30 * time.Second)
|
||||
time.Sleep(2 * time.Minute)
|
||||
err = cloudprovider.WaitMultiStatus(ipool, []string{api.MODELARTS_POOL_STATUS_RUNNING, api.MODELARTS_POOL_STATUS_CREATE_FAILED}, 15*time.Second, 2*time.Hour)
|
||||
if err != nil {
|
||||
pool.SetStatus(self.UserCred, api.MODELARTS_POOL_STATUS_TIMEOUT, err.Error())
|
||||
|
||||
@@ -47,6 +47,7 @@ type ModelartsPoolCreateOption struct {
|
||||
WorkType string `help:"Work Type"`
|
||||
CpuArch string `help:"Cpu Arch"`
|
||||
NodeCount int `help:"Node Count"`
|
||||
Cidr string `help:"Network Cidr"`
|
||||
|
||||
CloudregionId string `help:"Cloud Region ID"`
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1439,7 +1439,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221121093718-ceb2d0e88331
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122060402-9ac1c621d6d7
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+1
@@ -959,4 +959,5 @@ type ICloudModelartsPoolSku interface {
|
||||
GetGpuType() string
|
||||
GetNpuSize() int
|
||||
GetNpuType() string
|
||||
GetProcessorType() string
|
||||
}
|
||||
|
||||
+6
@@ -152,6 +152,12 @@ func (cli *SHuaweiClient) modelartsPoolNetworkDetail(networkName string) (jsonut
|
||||
return cli.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolNetworkDelete(networkName string) (jsonutils.JSONObject, error) {
|
||||
endpoint := cli.resetEndpoint(cli.endpoints.Modelarts, "modelarts")
|
||||
uri := fmt.Sprintf("https://%s/v1/%s/networks/%s", endpoint, cli.projectId, networkName)
|
||||
return cli.request(httputils.DELETE, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolNetworkCreate(params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
endpoint := self.resetEndpoint(self.endpoints.Modelarts, "modelarts")
|
||||
uri := fmt.Sprintf("https://%s/v1/%s/networks", endpoint, self.projectId)
|
||||
|
||||
+3
-3
@@ -156,10 +156,10 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.NetworkDetail")
|
||||
}
|
||||
netStatus, _ := netDetailObj.GetString("status", "phase")
|
||||
if netStatus == "Creating" {
|
||||
time.Sleep(10 * time.Second)
|
||||
} else {
|
||||
if netStatus == "Active" {
|
||||
break
|
||||
} else {
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -155,10 +155,10 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.NetworkDetail")
|
||||
}
|
||||
netStatus, _ := netDetailObj.GetString("status", "phase")
|
||||
if netStatus == "Creating" {
|
||||
time.Sleep(10 * time.Second)
|
||||
} else {
|
||||
if netStatus == "Active" {
|
||||
break
|
||||
} else {
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user