mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #26 in YUNIONIO/onecloud from ~ZHOUYOUSONG/onecloud:bugfix/yousong-minors to release/2.0.0
* commit 'f76609e91da3f668700b9ed7535e502bbf712401': dep: remove constraint on github.com/coreos/etcd cloudcommon: db: rename argument name cloudcommon: db: make master, slave id explict in joint resource base treewide: make explicit calls to JSONDict.Remove() and JSONDict.RemoveIgnoreCase scheduler: fix test compilation
This commit is contained in:
Generated
+3
-2
@@ -567,9 +567,10 @@
|
||||
revision = "bbd99532a768d2fe369079ceda730e30726ae1a6"
|
||||
|
||||
[[projects]]
|
||||
branch = "release/2.0.0"
|
||||
name = "github.com/yunionio/jsonutils"
|
||||
packages = ["."]
|
||||
revision = "6dd39f8579af6c6b61b971eb3a1ccf55e724b0ca"
|
||||
revision = "0f3f30adfdac3dec6ffbbfb72116f6f908134f63"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -904,6 +905,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "1fdd79d4d8791f7e87a3740b3807ea84f6306ecac3095d32a1ccf39b48be1f18"
|
||||
inputs-digest = "aa5af605c21bc592cbc237ad3539bc2cd9bbe5b8495c6c2d22e4a3bd8b148633"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
||||
+1
-5
@@ -30,7 +30,7 @@
|
||||
version = "0.2.2"
|
||||
|
||||
[[constraint]]
|
||||
revision = "6dd39f8579af6c6b61b971eb3a1ccf55e724b0ca"
|
||||
branch = "release/2.0.0"
|
||||
name = "github.com/yunionio/jsonutils"
|
||||
|
||||
[[constraint]]
|
||||
@@ -69,10 +69,6 @@
|
||||
name = "github.com/ugorji/go"
|
||||
revision = "f3cacc17c85ecb7f1b6a9e373ee85d1480919868"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/coreos/etcd"
|
||||
version = "3.3.5"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/coredns/coredns"
|
||||
version = "v1.2.0"
|
||||
|
||||
@@ -665,7 +665,7 @@ func doCreateItem(manager IModelManager, ctx context.Context, userCred mcclient.
|
||||
|
||||
generateName, _ := dataDict.GetString("generate_name")
|
||||
if len(generateName) > 0 {
|
||||
dataDict.Remove("generate_name", true)
|
||||
dataDict.Remove("generate_name")
|
||||
dataDict.Add(jsonutils.NewString(GenerateName(manager, ownerProjId, generateName)), "name")
|
||||
} else {
|
||||
name, _ := data.GetString("name")
|
||||
@@ -756,7 +756,7 @@ func expandMultiCreateParams(data jsonutils.JSONObject, count int) ([]jsonutils.
|
||||
return nil, httperrors.NewInputParameterError("Missing name or generate_name")
|
||||
}
|
||||
jsonDict.Add(jsonutils.NewString(name), "generate_name")
|
||||
jsonDict.Remove("name", false)
|
||||
jsonDict.RemoveIgnoreCase("name")
|
||||
}
|
||||
ret := make([]jsonutils.JSONObject, count)
|
||||
for i := 0; i < count; i += 1 {
|
||||
|
||||
@@ -116,7 +116,7 @@ type IJointModelManager interface {
|
||||
GetMasterManager() IStandaloneModelManager
|
||||
GetSlaveManager() IStandaloneModelManager
|
||||
|
||||
FetchByIds(id1 string, id2 string) (IJointModel, error)
|
||||
FetchByIds(masterId string, slaveId string) (IJointModel, error)
|
||||
|
||||
AllowListDescendent(ctx context.Context, userCred mcclient.TokenCredential, model IStandaloneModel, query jsonutils.JSONObject) bool
|
||||
AllowAttach(ctx context.Context, userCred mcclient.TokenCredential, master IStandaloneModel, slave IStandaloneModel) bool
|
||||
|
||||
@@ -65,7 +65,7 @@ func (manager *SJointResourceBaseManager) SlaveField(q *sqlchemy.SQuery) sqlchem
|
||||
return queryField(q, manager.GetSlaveManager())
|
||||
}
|
||||
|
||||
func (manager *SJointResourceBaseManager) FetchByIds(id1 string, id2 string) (IJointModel, error) {
|
||||
func (manager *SJointResourceBaseManager) FetchByIds(masterId string, slaveId string) (IJointModel, error) {
|
||||
obj, err := NewModelObject(manager)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -83,9 +83,8 @@ func (manager *SJointResourceBaseManager) FetchByIds(id1 string, id2 string) (IJ
|
||||
if slaveField == nil {
|
||||
return nil, fmt.Errorf("cannot find slave id")
|
||||
}
|
||||
cond1 := sqlchemy.AND(sqlchemy.Equals(masterField, id1), sqlchemy.Equals(slaveField, id2))
|
||||
cond2 := sqlchemy.AND(sqlchemy.Equals(slaveField, id1), sqlchemy.Equals(masterField, id2))
|
||||
q = q.Filter(sqlchemy.OR(cond1, cond2))
|
||||
cond := sqlchemy.AND(sqlchemy.Equals(masterField, masterId), sqlchemy.Equals(slaveField, slaveId))
|
||||
q = q.Filter(cond)
|
||||
count := q.Count()
|
||||
if count > 1 {
|
||||
return nil, sqlchemy.ErrDuplicateEntry
|
||||
@@ -127,14 +126,14 @@ func (joint *SJointResourceBase) GetJointModelManager() IJointModelManager {
|
||||
return joint.SResourceBase.GetModelManager().(IJointModelManager)
|
||||
}
|
||||
|
||||
func getFieldValue(joint IJointModel, name1 string, name2 string) string {
|
||||
func getFieldValue(joint IJointModel, keyword string, alias string) string {
|
||||
jointValue := reflect.Indirect(reflect.ValueOf(joint))
|
||||
idStr, find := reflectutils.FindStructFieldInterface(jointValue, fmt.Sprintf("%s_id", name1))
|
||||
if find {
|
||||
idStr, ok := reflectutils.FindStructFieldInterface(jointValue, fmt.Sprintf("%s_id", keyword))
|
||||
if ok {
|
||||
return idStr.(string)
|
||||
}
|
||||
idStr, find = reflectutils.FindStructFieldInterface(jointValue, fmt.Sprintf("%s_id", name2))
|
||||
if find {
|
||||
idStr, ok = reflectutils.FindStructFieldInterface(jointValue, fmt.Sprintf("%s_id", alias))
|
||||
if ok {
|
||||
return idStr.(string)
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -270,17 +270,17 @@ func (manager *SOpsLogManager) ListItemFilter(ctx context.Context, q *sqlchemy.S
|
||||
}
|
||||
objTypes := jsonutils.GetQueryStringArray(queryDict, "obj_type")
|
||||
if objTypes != nil && len(objTypes) > 0 {
|
||||
queryDict.Remove("obj_type", false)
|
||||
queryDict.RemoveIgnoreCase("obj_type")
|
||||
q = q.Filter(sqlchemy.In(q.Field("obj_type"), objTypes))
|
||||
}
|
||||
objIds := jsonutils.GetQueryStringArray(queryDict, "obj_id")
|
||||
if objIds != nil && len(objIds) > 0 {
|
||||
queryDict.Remove("obj_id", false)
|
||||
queryDict.RemoveIgnoreCase("obj_id")
|
||||
q = q.Filter(sqlchemy.OR(sqlchemy.In(q.Field("obj_id"), objIds), sqlchemy.In(q.Field("obj_name"), objIds)))
|
||||
}
|
||||
action := jsonutils.GetQueryStringArray(queryDict, "action")
|
||||
if action != nil && len(action) > 0 {
|
||||
queryDict.Remove("action", false)
|
||||
queryDict.RemoveIgnoreCase("action")
|
||||
q = q.Filter(sqlchemy.In(q.Field("action"), action))
|
||||
}
|
||||
if !userCred.IsSystemAdmin() {
|
||||
|
||||
@@ -196,7 +196,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
isBMstr, _ := queryDict.GetString("baremetal")
|
||||
if len(isBMstr) > 0 && utils.ToBool(isBMstr) {
|
||||
queryDict.Add(jsonutils.NewString(HYPERVISOR_BAREMETAL), "hypervisor")
|
||||
queryDict.Remove("baremetal", true)
|
||||
queryDict.Remove("baremetal")
|
||||
}
|
||||
hypervisor, _ := queryDict.GetString("hypervisor")
|
||||
if len(hypervisor) > 0 {
|
||||
|
||||
@@ -18,8 +18,15 @@ var HostwireManager *SHostwireManager
|
||||
|
||||
func init() {
|
||||
db.InitManager(func() {
|
||||
HostwireManager = &SHostwireManager{SHostJointsManager: NewHostJointsManager(SHostwire{},
|
||||
"hostwires_tbl", "hostwire", "hostwires", WireManager)}
|
||||
HostwireManager = &SHostwireManager{
|
||||
SHostJointsManager: NewHostJointsManager(
|
||||
SHostwire{},
|
||||
"hostwires_tbl",
|
||||
"hostwire",
|
||||
"hostwires",
|
||||
WireManager,
|
||||
),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,16 @@ var StoragecachedimageManager *SStoragecachedimageManager
|
||||
|
||||
func init() {
|
||||
db.InitManager(func() {
|
||||
StoragecachedimageManager = &SStoragecachedimageManager{SJointResourceBaseManager: db.NewJointResourceBaseManager(SStoragecachedimage{}, "storagecachedimages_tbl", "storagecachedimage", "storagecachedimages", StoragecacheManager, CachedimageManager)}
|
||||
StoragecachedimageManager = &SStoragecachedimageManager{
|
||||
SJointResourceBaseManager: db.NewJointResourceBaseManager(
|
||||
SStoragecachedimage{},
|
||||
"storagecachedimages_tbl",
|
||||
"storagecachedimage",
|
||||
"storagecachedimages",
|
||||
StoragecacheManager,
|
||||
CachedimageManager,
|
||||
),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ func (this *ImageManager) List(session *mcclient.ClientSession, params jsonutils
|
||||
path = fmt.Sprintf("%s/detail", path)
|
||||
}
|
||||
dictparams, _ := params.(*jsonutils.JSONDict)
|
||||
dictparams.Remove("details", false)
|
||||
dictparams.RemoveIgnoreCase("details")
|
||||
qs := params.QueryString()
|
||||
if len(qs) > 0 {
|
||||
path = fmt.Sprintf("%s?%s", path, qs)
|
||||
|
||||
@@ -20,8 +20,8 @@ func (this *UsageManager) GetGeneralUsage(session *mcclient.ClientSession, param
|
||||
url = fmt.Sprintf("%s/%s/%s", url, range_type, range_id)
|
||||
}
|
||||
dict := params.(*jsonutils.JSONDict)
|
||||
dict.Remove("range_type", true)
|
||||
dict.Remove("range_id", true)
|
||||
dict.Remove("range_type")
|
||||
dict.Remove("range_id")
|
||||
qs := dict.QueryString()
|
||||
if len(qs) > 0 {
|
||||
url = fmt.Sprintf("%s?%s", url, qs)
|
||||
|
||||
@@ -155,7 +155,8 @@ func TestGuestDisk(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
size, err := gst.(*Guest).DiskSize()
|
||||
onlyLocal := false
|
||||
size, err := gst.(*Guest).DiskSize(onlyLocal)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
+26
-1
@@ -42,11 +42,36 @@ func NewFloat(val float64) *JSONFloat {
|
||||
return &JSONFloat{data: val}
|
||||
}
|
||||
|
||||
func NewBool(val bool) *JSONBool {
|
||||
if val {
|
||||
return JSONTrue
|
||||
}
|
||||
return JSONFalse
|
||||
}
|
||||
|
||||
func (this *JSONDict) Set(key string, value JSONObject) {
|
||||
this.data[key] = value
|
||||
}
|
||||
|
||||
func (this *JSONDict) Remove(key string, caseSensitive bool) bool {
|
||||
func (this *JSONDict) Remove(key string) bool {
|
||||
return this.remove(key, true)
|
||||
}
|
||||
|
||||
func (this *JSONDict) RemoveIgnoreCase(key string) bool {
|
||||
someRemoved := false
|
||||
for {
|
||||
removed := this.remove(key, false)
|
||||
if !removed {
|
||||
break
|
||||
}
|
||||
if !someRemoved {
|
||||
someRemoved = true
|
||||
}
|
||||
}
|
||||
return someRemoved
|
||||
}
|
||||
|
||||
func (this *JSONDict) remove(key string, caseSensitive bool) bool {
|
||||
_, rk, ok := dictGet(this.data, key, caseSensitive)
|
||||
if ok {
|
||||
delete(this.data, rk)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package jsonutils
|
||||
|
||||
func (this *JSONString) Length() int {
|
||||
return len(this.data)
|
||||
}
|
||||
|
||||
func (this *JSONDict) Length() int {
|
||||
return len(this.data)
|
||||
}
|
||||
|
||||
func (this *JSONArray) Length() int {
|
||||
return len(this.data)
|
||||
}
|
||||
Reference in New Issue
Block a user