mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix: host files not initialized when host reboot (#22550)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -94,6 +94,9 @@ func init() {
|
||||
fmt.Println("error", err)
|
||||
}
|
||||
}, &options.BaseIdOptions{})
|
||||
cmd.GetWithCustomShow("host-files", func(data jsonutils.JSONObject) {
|
||||
printObject(data)
|
||||
}, &options.BaseIdOptions{})
|
||||
|
||||
R(&compute.HostShowOptions{}, "host-show", "Show details of a host", func(s *mcclient.ClientSession, args *compute.HostShowOptions) error {
|
||||
params, err := args.Params()
|
||||
|
||||
@@ -210,3 +210,18 @@ func fetchHostFilesHosts(hostFileIds []string) (map[string][]string, error) {
|
||||
|
||||
return hostFiles, nil
|
||||
}
|
||||
|
||||
func (host *SHost) GetDetailsHostFiles(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
hostFiles, err := host.getHostFiles()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetHostFiles")
|
||||
}
|
||||
|
||||
hostFilesObj := jsonutils.NewDict()
|
||||
hostFilesObj.Add(jsonutils.Marshal(hostFiles), "host_files")
|
||||
return hostFilesObj, nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/hostman/system_service"
|
||||
computemodules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
"yunion.io/x/onecloud/pkg/util/apparmorutils"
|
||||
"yunion.io/x/onecloud/pkg/util/fileutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
@@ -63,6 +64,10 @@ func (h *SHostInfo) saveHostFiles(hostfiles []api.SHostFile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *SHostInfo) clearHostFiles() error {
|
||||
return os.Remove(options.HostOptions.HostFilesPath)
|
||||
}
|
||||
|
||||
type hostFilePaire struct {
|
||||
old *api.SHostFile
|
||||
new *api.SHostFile
|
||||
@@ -116,6 +121,22 @@ func (h *SHostInfo) OnHostFilesChanged(hostfiles []api.SHostFile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *SHostInfo) initHostFiles() error {
|
||||
hostFilesObj, err := computemodules.Hosts.GetSpecific(h.GetSession(), h.GetId(), "host-files", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "computemodules.Hosts.GetSpecific")
|
||||
}
|
||||
hostFiles := []api.SHostFile{}
|
||||
err = hostFilesObj.Unmarshal(&hostFiles, "host_files")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Unmarshal")
|
||||
}
|
||||
if err := h.clearHostFiles(); err != nil {
|
||||
return errors.Wrap(err, "clearHostFiles")
|
||||
}
|
||||
return h.OnHostFilesChanged(hostFiles)
|
||||
}
|
||||
|
||||
func handleHostFileChanged(pair *hostFilePaire) error {
|
||||
switch pair.new.Type {
|
||||
case string(api.ApparmorProfile):
|
||||
|
||||
@@ -1216,6 +1216,11 @@ func (h *SHostInfo) register() {
|
||||
h.onFail(errors.Wrap(err, "finalizeNetworkSetup"))
|
||||
return
|
||||
}
|
||||
if err := h.initHostFiles(); err != nil {
|
||||
log.Errorf("initHostFiles failed: %s", err)
|
||||
} else {
|
||||
log.Infof("initHostFiles success")
|
||||
}
|
||||
h.deployAdminAuthorizedKeys()
|
||||
h.onSucc()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user