Merge pull request #13641 from rainzm/secret/network

optimization for class metadata and instance backup
This commit is contained in:
Zexi Li
2022-03-10 01:12:38 +08:00
committed by GitHub
4 changed files with 23 additions and 4 deletions
+1
View File
@@ -249,6 +249,7 @@ func (self *SGuestdisk) ToDiskConfig() *api.DiskConfig {
}
conf := disk.ToDiskConfig()
conf.Index = int(self.Index)
conf.Mountpoint = self.Mountpoint
return conf
}
-2
View File
@@ -248,8 +248,6 @@ func (manager *SInstanceBackupManager) fillInstanceBackup(ctx context.Context, u
instanceBackup.CloudregionId = zone.CloudregionId
guestSchedInput.HostId = ""
guestSchedInput.Project = ""
guestSchedInput.Domain = ""
for i := 0; i < len(guestSchedInput.Networks); i++ {
guestSchedInput.Networks[i].Mac = ""
guestSchedInput.Networks[i].Address = ""
@@ -16,9 +16,11 @@ package tasks
import (
"context"
"database/sql"
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
@@ -59,12 +61,23 @@ func (self *InstanceBackupRecoveryTask) OnInit(ctx context.Context, obj db.IStan
if serverName == "" {
serverName, _ = ib.ServerConfig.GetString("name")
}
project, _ := ib.ServerConfig.GetString("project")
sourceInput := &compute.ServerCreateInput{}
sourceInput.ServerConfigs = &compute.ServerConfigs{}
sourceInput.GenerateName = serverName
sourceInput.Description = fmt.Sprintf("recovery from instance backup %s", ib.GetName())
sourceInput.InstanceBackupId = ib.GetId()
sourceInput.Hypervisor = compute.HYPERVISOR_KVM
if project != "" {
tenant, err := db.TenantCacheManager.FetchTenantByIdOrName(ctx, project)
if err != nil && errors.Cause(err) != sql.ErrNoRows {
self.taskFailed(ctx, ib, jsonutils.NewString(err.Error()))
return
}
if tenant != nil {
sourceInput.Project = project
}
}
taskHeader := self.GetTaskRequestHeader()
session := auth.GetSession(ctx, self.UserCred, "", "")
session.Header.Set(mcclient.TASK_NOTIFY_URL, taskHeader.Get(mcclient.TASK_NOTIFY_URL))
@@ -18,11 +18,13 @@ import (
"context"
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/scheduler/core"
"yunion.io/x/onecloud/pkg/util/rbacutils"
)
type ClassMetadataPredicate struct {
@@ -97,8 +99,13 @@ func (p *ClassMetadataPredicate) PreExecute(u *core.Unit, cs []core.Candidater)
if err != nil {
return false, errors.Wrapf(err, "unable to fetch cachedimage %s", disks[0].ImageId)
}
stand = &obj.SStandaloneAnonResourceBase
guestSource.keyword = "image"
// no check if image if system public image
public := jsonutils.QueryBoolean(obj.Info, "is_public", false)
publicScope, _ := obj.Info.GetString("public_scope")
if !public || publicScope != string(rbacutils.ScopeSystem) {
stand = &obj.SStandaloneAnonResourceBase
guestSource.keyword = "image"
}
case disks[0].SnapshotId != "":
obj, err := models.SnapshotManager.FetchById(disks[0].SnapshotId)
if err != nil {