Skip to content

Commit

Permalink
fix: domain user no previleges to convert host
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu Jian committed May 27, 2020
1 parent d236823 commit c563f02
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4345,17 +4345,20 @@ func (self *SHost) PerformConvertHypervisor(ctx context.Context, userCred mcclie
if err != nil {
return nil, httperrors.NewNotAcceptableError("Convert error: %s", err.Error())
}
// admin delegate user to create system resource
input.ProjectDomain = userCred.GetProjectDomainId()
input.Project = userCred.GetProjectId()
params := input.JSON(input)
// ownerId := userCred.GetProjectId()
guest, err := db.DoCreate(GuestManager, ctx, userCred, nil, params, userCred)
adminCred := auth.AdminCredential()
guest, err := db.DoCreate(GuestManager, ctx, adminCred, nil, params, userCred)
if err != nil {
return nil, err
}
func() {
lockman.LockObject(ctx, guest)
defer lockman.ReleaseObject(ctx, guest)

guest.PostCreate(ctx, userCred, userCred, nil, params)
guest.PostCreate(ctx, adminCred, userCred, nil, params)
}()
log.Infof("Host convert to %s", guest.GetName())
db.OpsLog.LogEvent(self, db.ACT_CONVERT_START, "", userCred)
Expand All @@ -4366,7 +4369,7 @@ func (self *SHost) PerformConvertHypervisor(ctx context.Context, userCred mcclie
opts.Set("server_id", jsonutils.NewString(guest.GetId()))
opts.Set("convert_host_type", jsonutils.NewString(hostType))

task, err := taskman.TaskManager.NewTask(ctx, "BaremetalConvertHypervisorTask", self, userCred, opts, "", "", nil)
task, err := taskman.TaskManager.NewTask(ctx, "BaremetalConvertHypervisorTask", self, adminCred, opts, "", "", nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c563f02

Please sign in to comment.