diff --git a/pkg/baremetal/tasks/rebuild.go b/pkg/baremetal/tasks/rebuild.go index d8b658a49a..e8cb93f312 100644 --- a/pkg/baremetal/tasks/rebuild.go +++ b/pkg/baremetal/tasks/rebuild.go @@ -56,7 +56,7 @@ func (self *SBaremetalServerRebuildTask) DoDeploys(term *ssh.Client) (jsonutils. } data := jsonutils.NewDict() data.Add(jsonutils.NewArray(disks...), "disks") - deployInfo, err := self.Baremetal.GetServer().DoDeploy(term, self.data, false) + deployInfo, err := self.Baremetal.GetServer().DoDeploy(term, self.data, true) if err != nil { return nil, fmt.Errorf("DoDeploy: %v", err) } diff --git a/pkg/compute/tasks/guest_rebuild_root_task.go b/pkg/compute/tasks/guest_rebuild_root_task.go index 20ad417c7c..6f49c7ade8 100644 --- a/pkg/compute/tasks/guest_rebuild_root_task.go +++ b/pkg/compute/tasks/guest_rebuild_root_task.go @@ -228,7 +228,7 @@ func (self *KVMGuestRebuildRootTask) OnRebuildRootDiskComplete(ctx context.Conte guest.SetStatus(self.UserCred, api.VM_DEPLOYING, "") // params := jsonutils.NewDict() // params.Set("reset_password", jsonutils.JSONTrue) - guest.StartGuestDeployTask(ctx, self.UserCred, self.GetParams(), "deploy", self.GetTaskId()) + guest.StartGuestDeployTask(ctx, self.UserCred, self.GetParams(), "rebuild", self.GetTaskId()) } func (self *KVMGuestRebuildRootTask) OnRebuildRootDiskCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { diff --git a/pkg/hostman/guestfs/core.go b/pkg/hostman/guestfs/core.go index be5ce46444..9a7effb52e 100644 --- a/pkg/hostman/guestfs/core.go +++ b/pkg/hostman/guestfs/core.go @@ -96,6 +96,11 @@ func DoDeployGuestFs(rootfs fsdriver.IRootFsDriver, guestDesc *deployapi.GuestDe return ret, nil } + if deployInfo.IsInit { + if err = rootfs.CleanNetworkScripts(partition); err != nil { + return nil, errors.Wrap(err, "Clean network scripts") + } + } if len(deployInfo.Deploys) > 0 { if err = rootfs.DeployFiles(deployInfo.Deploys); err != nil { return nil, fmt.Errorf("DeployFiles: %v", err) diff --git a/pkg/hostman/guestfs/fsdriver/base.go b/pkg/hostman/guestfs/fsdriver/base.go index 5897a9404b..0a3808dac7 100644 --- a/pkg/hostman/guestfs/fsdriver/base.go +++ b/pkg/hostman/guestfs/fsdriver/base.go @@ -120,6 +120,10 @@ func (l *sGuestRootFsDriver) IsResizeFsPartitionSupport() bool { return true } +func (r *sGuestRootFsDriver) CleanNetworkScripts(rootFs IDiskPartition) error { + return nil +} + const ( modeAuthorizedKeysRWX = syscall.S_IRUSR | syscall.S_IWUSR | syscall.S_IXUSR modeAuthorizedKeysRW = syscall.S_IRUSR | syscall.S_IWUSR diff --git a/pkg/hostman/guestfs/fsdriver/interface.go b/pkg/hostman/guestfs/fsdriver/interface.go index 0c394291c4..31b4709fd4 100644 --- a/pkg/hostman/guestfs/fsdriver/interface.go +++ b/pkg/hostman/guestfs/fsdriver/interface.go @@ -83,6 +83,7 @@ type IRootFsDriver interface { IsResizeFsPartitionSupport() bool PrepareFsForTemplate(IDiskPartition) error + CleanNetworkScripts(rootFs IDiskPartition) error } type IDebianRootFsDriver interface { diff --git a/pkg/hostman/guestfs/fsdriver/linux.go b/pkg/hostman/guestfs/fsdriver/linux.go index 58c8aaf7af..6010499d45 100644 --- a/pkg/hostman/guestfs/fsdriver/linux.go +++ b/pkg/hostman/guestfs/fsdriver/linux.go @@ -836,6 +836,10 @@ func (r *sRedhatLikeRootFs) PrepareFsForTemplate(rootFs IDiskPartition) error { if err := r.sLinuxRootFs.PrepareFsForTemplate(rootFs); err != nil { return err } + return r.CleanNetworkScripts(rootFs) +} + +func (r *sRedhatLikeRootFs) CleanNetworkScripts(rootFs IDiskPartition) error { networkPath := "/etc/sysconfig/network-scripts" files := rootFs.ListDir(networkPath, false) for i := 0; i < len(files); i++ { diff --git a/pkg/hostman/guestman/guesthandlers/guesthandler.go b/pkg/hostman/guestman/guesthandlers/guesthandler.go index 540b4c6e77..44e80b1c0a 100644 --- a/pkg/hostman/guestman/guesthandlers/guesthandler.go +++ b/pkg/hostman/guestman/guesthandlers/guesthandler.go @@ -58,6 +58,7 @@ func AddGuestTaskHandler(prefix string, app *appsrv.Application) { for action, f := range map[string]actionFunc{ "create": guestCreate, "deploy": guestDeploy, + "rebuild": guestRebuild, "start": guestStart, "stop": guestStop, "monitor": guestMonitor, @@ -155,6 +156,19 @@ func guestDeploy(ctx context.Context, sid string, body jsonutils.JSONObject) (in return nil, nil } +func guestRebuild(ctx context.Context, sid string, body jsonutils.JSONObject) (interface{}, error) { + err := guestman.GetGuestManager().PrepareDeploy(sid) + if err != nil { + return nil, err + } + hostutils.DelayTaskWithWorker(ctx, + guestman.GetGuestManager().GuestDeploy, + &guestman.SGuestDeploy{sid, body, true}, + guestman.NbdWorker, + ) + return nil, nil +} + func guestStart(ctx context.Context, sid string, body jsonutils.JSONObject) (interface{}, error) { return guestman.GetGuestManager().GuestStart(ctx, sid, body) }