mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #252 in YUNIONIO/onecloud from ~WANYAOQI/onecloud:feature/wyq/baremetal-control to release/2.3.0
* commit '6d21c7e0d2501a385438c01522ad98a6709b19b7': baremetal ops some bugfix make dep
This commit is contained in:
@@ -443,6 +443,14 @@ func listItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
retConut := len(retList)
|
||||
retList, err = manager.CustomizeFilterList(ctx, userCred, queryDict, retList)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if len(retList) != retConut {
|
||||
totalCnt = int64(len(retList))
|
||||
}
|
||||
retResult := modules.ListResult{Data: retList, Total: int(totalCnt), Limit: int(limit), Offset: int(offset)}
|
||||
return &retResult, nil
|
||||
}
|
||||
@@ -864,7 +872,7 @@ func (dispatcher *DBModelDispatcher) PerformClassAction(ctx context.Context, act
|
||||
|
||||
func (dispatcher *DBModelDispatcher) PerformAction(ctx context.Context, idStr string, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
userCred := fetchUserCredential(ctx)
|
||||
model, err := fetchItem(dispatcher.modelManager, ctx, userCred, idStr, query)
|
||||
model, err := fetchItem(dispatcher.modelManager, ctx, userCred, idStr, nil)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError(fmt.Sprintf("%s %s not found",
|
||||
dispatcher.modelManager.Keyword(), idStr))
|
||||
@@ -1022,7 +1030,7 @@ func updateItem(manager IModelManager, item IModel, ctx context.Context, userCre
|
||||
|
||||
func (dispatcher *DBModelDispatcher) Update(ctx context.Context, idStr string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
userCred := fetchUserCredential(ctx)
|
||||
model, err := fetchItem(dispatcher.modelManager, ctx, userCred, idStr, query)
|
||||
model, err := fetchItem(dispatcher.modelManager, ctx, userCred, idStr, nil)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError(fmt.Sprintf("%s %s not found",
|
||||
dispatcher.modelManager.Keyword(), idStr))
|
||||
@@ -1100,7 +1108,7 @@ func deleteItem(manager IModelManager, model IModel, ctx context.Context, userCr
|
||||
|
||||
func (dispatcher *DBModelDispatcher) Delete(ctx context.Context, idstr string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
userCred := fetchUserCredential(ctx)
|
||||
model, err := fetchItem(dispatcher.modelManager, ctx, userCred, idstr, query)
|
||||
model, err := fetchItem(dispatcher.modelManager, ctx, userCred, idstr, nil)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError(fmt.Sprintf("%s %s not found",
|
||||
dispatcher.modelManager.Keyword(), idstr))
|
||||
|
||||
@@ -29,6 +29,7 @@ type IModelManager interface {
|
||||
AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool
|
||||
ValidateListConditions(ctx context.Context, userCred mcclient.TokenCredential, query *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
|
||||
ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error)
|
||||
CustomizeFilterList(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, retList []jsonutils.JSONObject) ([]jsonutils.JSONObject, error)
|
||||
ExtraSearchConditions(ctx context.Context, q *sqlchemy.SQuery, like string) []sqlchemy.ICondition
|
||||
|
||||
// fetch hook
|
||||
@@ -55,6 +56,8 @@ type IModelManager interface {
|
||||
AllowPerformAction(ctx context.Context, userCred mcclient.TokenCredential, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) bool
|
||||
PerformAction(ctx context.Context, userCred mcclient.TokenCredential, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
|
||||
|
||||
DoCreate(ctx context.Context, userCred mcclient.TokenCredential, kwargs jsonutils.JSONObject, data jsonutils.JSONObject, realManager IModelManager) (IModel, error)
|
||||
|
||||
InitializeData() error
|
||||
}
|
||||
|
||||
|
||||
@@ -108,16 +108,20 @@ func (manager *SJointResourceBaseManager) AllowAttach(ctx context.Context, userC
|
||||
|
||||
func JointModelExtra(jointModel IJointModel, extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
master := jointModel.Master()
|
||||
extra.Add(jsonutils.NewString(master.GetName()), master.GetModelManager().Keyword())
|
||||
alias := master.GetModelManager().Alias()
|
||||
if len(alias) > 0 {
|
||||
extra.Add(jsonutils.NewString(master.GetName()), alias)
|
||||
if master != nil {
|
||||
extra.Add(jsonutils.NewString(master.GetName()), master.GetModelManager().Keyword())
|
||||
alias := master.GetModelManager().Alias()
|
||||
if len(alias) > 0 {
|
||||
extra.Add(jsonutils.NewString(master.GetName()), alias)
|
||||
}
|
||||
}
|
||||
slave := jointModel.Slave()
|
||||
extra.Add(jsonutils.NewString(slave.GetName()), slave.GetModelManager().Keyword())
|
||||
alias = slave.GetModelManager().Alias()
|
||||
if len(alias) > 0 {
|
||||
extra.Add(jsonutils.NewString(slave.GetName()), alias)
|
||||
if slave != nil {
|
||||
extra.Add(jsonutils.NewString(slave.GetName()), slave.GetModelManager().Keyword())
|
||||
alias := slave.GetModelManager().Alias()
|
||||
if len(alias) > 0 {
|
||||
extra.Add(jsonutils.NewString(slave.GetName()), alias)
|
||||
}
|
||||
}
|
||||
return extra
|
||||
}
|
||||
@@ -180,13 +184,23 @@ func (joint *SJointResourceBase) Slave() IStandaloneModel {
|
||||
}
|
||||
|
||||
func (self *SJointResourceBase) AllowGetJointDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, item IJointModel) bool {
|
||||
masterVirtual := item.Master().(IVirtualModel)
|
||||
return masterVirtual.IsOwner(userCred)
|
||||
master := item.Master()
|
||||
switch master.(type) {
|
||||
case IVirtualModel:
|
||||
return master.(IVirtualModel).IsOwner(userCred)
|
||||
default: // case item implemented customized AllowGetDetails, eg hostjoints
|
||||
return item.AllowGetDetails(ctx, userCred, query)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SJointResourceBase) AllowUpdateJointItem(ctx context.Context, userCred mcclient.TokenCredential, item IJointModel) bool {
|
||||
masterVirtual := item.Master().(IVirtualModel)
|
||||
return masterVirtual.IsOwner(userCred)
|
||||
master := item.Master()
|
||||
switch master.(type) {
|
||||
case IVirtualModel:
|
||||
return master.(IVirtualModel).IsOwner(userCred)
|
||||
default: // case item implemented customized AllowGetDetails, eg hostjoints
|
||||
return item.AllowUpdateItem(ctx, userCred)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,6 +3,7 @@ package db
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -74,6 +75,10 @@ func (manager *SModelBaseManager) ListItemFilter(ctx context.Context, q *sqlchem
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SModelBaseManager) CustomizeFilterList(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, retList []jsonutils.JSONObject) ([]jsonutils.JSONObject, error) {
|
||||
return retList, nil
|
||||
}
|
||||
|
||||
func (manager *SModelBaseManager) ExtraSearchConditions(ctx context.Context, q *sqlchemy.SQuery, like string) []sqlchemy.ICondition {
|
||||
return nil
|
||||
}
|
||||
@@ -149,6 +154,10 @@ func (manager *SModelBaseManager) InitializeData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SModelBaseManager) DoCreate(ctx context.Context, userCred mcclient.TokenCredential, kwargs jsonutils.JSONObject, data jsonutils.JSONObject, realManager IModelManager) (IModel, error) {
|
||||
return nil, fmt.Errorf("Do create not implement?")
|
||||
}
|
||||
|
||||
func (model *SModelBase) GetId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/pkg/util/timeutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -35,6 +36,14 @@ func (manager *SResourceBaseManager) RawQuery(fields ...string) *sqlchemy.SQuery
|
||||
return manager.SModelBaseManager.Query(fields...)
|
||||
}
|
||||
|
||||
func (manager *SResourceBaseManager) DoCreate(ctx context.Context, userCred mcclient.TokenCredential, kwargs jsonutils.JSONObject, data jsonutils.JSONObject, realManager IModelManager) (IModel, error) {
|
||||
ownerProjId, err := fetchOwnerProjectId(ctx, userCred, kwargs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return doCreateItem(realManager, ctx, userCred, ownerProjId, nil, data)
|
||||
}
|
||||
|
||||
func CanDelete(model IModel, ctx context.Context) bool {
|
||||
err := model.ValidateDeleteCondition(ctx)
|
||||
if err == nil {
|
||||
|
||||
@@ -37,6 +37,8 @@ const (
|
||||
MULTI_OBJECTS_ID = "[--MULTI_OBJECTS--]"
|
||||
|
||||
TASK_INIT_STAGE = "on_init"
|
||||
|
||||
CONVERT_TASK = "convert_task"
|
||||
)
|
||||
|
||||
type STaskManager struct {
|
||||
|
||||
Reference in New Issue
Block a user