mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #1142 from Zexi/hotfix/scheduler-misc
scheduler: misc bugfix
This commit is contained in:
@@ -33,6 +33,7 @@ type DiskCreateInput struct {
|
||||
Description string `json:"description"`
|
||||
Hypervisor string `json:"hypervisor"`
|
||||
Project string `json:"project"`
|
||||
Domain string `json:"domain_id"`
|
||||
}
|
||||
|
||||
// ToServerCreateInput used by disk schedule
|
||||
@@ -46,6 +47,7 @@ func (req *DiskCreateInput) ToServerCreateInput() *ServerCreateInput {
|
||||
Hypervisor: req.Hypervisor,
|
||||
Disks: []*DiskConfig{req.DiskConfig},
|
||||
Project: req.Project,
|
||||
Domain: req.Domain,
|
||||
},
|
||||
Name: req.Name,
|
||||
}
|
||||
|
||||
@@ -379,6 +379,7 @@ func (manager *SDiskManager) ValidateCreateData(ctx context.Context, userCred mc
|
||||
return nil, err
|
||||
}
|
||||
input.Project = ownerId.GetProjectId()
|
||||
input.Domain = ownerId.GetDomainId()
|
||||
|
||||
storageID := input.Storage
|
||||
if storageID != "" {
|
||||
|
||||
@@ -54,6 +54,18 @@ func RunBatchCreateTask(
|
||||
}
|
||||
}
|
||||
|
||||
func allowAssignHost(userCred mcclient.TokenCredential) bool {
|
||||
for _, scope := range []rbacutils.TRbacScope{
|
||||
rbacutils.ScopeSystem,
|
||||
rbacutils.ScopeDomain,
|
||||
} {
|
||||
if userCred.IsAllow(scope, consts.GetServiceType(), GuestManager.KeywordPlural(), policy.PolicyActionPerform, "assign-host") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput, hypervisor string) (*api.ServerCreateInput, error) {
|
||||
var err error
|
||||
|
||||
@@ -64,7 +76,7 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred
|
||||
// base validate_create_data
|
||||
if (input.PreferHost != "") && hypervisor != api.HYPERVISOR_CONTAINER {
|
||||
|
||||
if !userCred.IsAllow(rbacutils.ScopeSystem, consts.GetServiceType(), GuestManager.KeywordPlural(), policy.PolicyActionPerform, "assign-host") {
|
||||
if !allowAssignHost(userCred) {
|
||||
return nil, httperrors.NewNotSufficientPrivilegeError("Only system admin can specify preferred host")
|
||||
}
|
||||
bmName := input.PreferHost
|
||||
|
||||
@@ -50,7 +50,7 @@ func CreateServerExample() error {
|
||||
"vcpu_count": 1,
|
||||
"vmem_size": 2048,
|
||||
"disks": []map[string]string{
|
||||
map[string]string{
|
||||
{
|
||||
"image_id": "a4171f87-7e70-43bf-852e-4a3e1bf7deab",
|
||||
"disk_type": "sys",
|
||||
"backend": "local",
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/scheduler"
|
||||
)
|
||||
@@ -89,14 +91,15 @@ func (this *SchedulerManager) Test(s *mcclient.ClientSession, params *api.Schedu
|
||||
|
||||
func (this *SchedulerManager) DoForecast(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
projectId := s.GetProjectId()
|
||||
domainId := s.GetDomainId()
|
||||
domainId := s.GetProjectDomainId()
|
||||
cliProjectId, _ := params.GetString("project_id")
|
||||
if cliProjectId != "" {
|
||||
projectId = cliProjectId
|
||||
domainId = ""
|
||||
}
|
||||
if domainId == "" {
|
||||
ret, err := Projects.Get(s, projectId, nil)
|
||||
adminSession := auth.GetAdminSession(context.TODO(), "", "")
|
||||
ret, err := Projects.Get(adminSession, projectId, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -268,6 +268,14 @@ func (this *ClientSession) GetProjectName() string {
|
||||
return this.GetTenantName()
|
||||
}
|
||||
|
||||
func (this *ClientSession) GetProjectDomain() string {
|
||||
return this.token.GetProjectDomain()
|
||||
}
|
||||
|
||||
func (this *ClientSession) GetProjectDomainId() string {
|
||||
return this.token.GetProjectDomainId()
|
||||
}
|
||||
|
||||
func (this *ClientSession) GetDomainId() string {
|
||||
return this.token.GetDomainId()
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gopkg.in/gin-gonic/gin.v1"
|
||||
|
||||
@@ -63,6 +64,21 @@ func StartService() error {
|
||||
|
||||
db.InitAllManagers()
|
||||
|
||||
checkDBSyncRetries := 5
|
||||
count := 1
|
||||
for {
|
||||
if count == checkDBSyncRetries {
|
||||
log.Fatalf("database schema not in sync!!!")
|
||||
}
|
||||
if !db.CheckSync(false) {
|
||||
log.Errorf("database schema not in sync, wait region sync database")
|
||||
time.Sleep(2 * time.Second)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
count++
|
||||
}
|
||||
|
||||
if err := computemodels.InitDB(); err != nil {
|
||||
log.Fatalf("InitDB fail: %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user