clean network scripts on init

This commit is contained in:
wanyaoqi
2020-05-27 17:11:32 +08:00
parent c05e24371e
commit 73297de60c
7 changed files with 30 additions and 2 deletions
+1 -1
View File
@@ -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)
}
+1 -1
View File
@@ -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) {
+5
View File
@@ -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)
+4
View File
@@ -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
@@ -83,6 +83,7 @@ type IRootFsDriver interface {
IsResizeFsPartitionSupport() bool
PrepareFsForTemplate(IDiskPartition) error
CleanNetworkScripts(rootFs IDiskPartition) error
}
type IDebianRootFsDriver interface {
+4
View File
@@ -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++ {
@@ -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)
}