fix: host-update ipmi and host-sync-config support

This commit is contained in:
Qiu Jian
2019-12-30 16:05:05 +08:00
parent 53972dc1ec
commit f41de9139d
3 changed files with 107 additions and 0 deletions
+24
View File
@@ -4681,3 +4681,27 @@ func (self *SHost) StartEjectIsoTask(ctx context.Context, userCred mcclient.Toke
return nil
}
}
func (self *SHost) AllowPerformSyncConfig(ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
data jsonutils.JSONObject) bool {
return db.IsAdminAllowPerform(userCred, self, "sync-config")
}
func (self *SHost) PerformSyncConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if self.HostType != api.HOST_TYPE_BAREMETAL {
return nil, httperrors.NewBadRequestError("Cannot sync config a non-baremetal host")
}
self.SetStatus(userCred, api.BAREMETAL_SYNCING_STATUS, "")
return nil, self.StartSyncConfig(ctx, userCred, "")
}
func (self *SHost) StartSyncConfig(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
task, err := taskman.TaskManager.NewTask(ctx, "BaremetalSyncConfigTask", self, userCred, nil, parentTaskId, "", nil)
if err != nil {
return err
}
task.ScheduleRun(nil)
return nil
}
@@ -0,0 +1,64 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tasks
import (
"context"
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type BaremetalSyncConfigTask struct {
SBaremetalBaseTask
}
func init() {
taskman.RegisterTask(BaremetalSyncConfigTask{})
}
func (self *BaremetalSyncConfigTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
baremetal := obj.(*models.SHost)
if baremetal.IsBaremetal {
self.DoSyncConfig(ctx, baremetal)
} else {
self.SetStageComplete(ctx, nil)
}
}
func (self *BaremetalSyncConfigTask) DoSyncConfig(ctx context.Context, baremetal *models.SHost) {
self.SetStage("OnSyncConfigComplete", nil)
url := fmt.Sprintf("/baremetals/%s/sync-config", baremetal.Id)
headers := self.GetTaskRequestHeader()
_, err := baremetal.BaremetalSyncRequest(ctx, "POST", url, headers, nil)
if err != nil {
self.SetStageFailed(ctx, err.Error())
}
}
func (self *BaremetalSyncConfigTask) OnSyncConfigComplete(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) {
self.SetStage("OnSyncstatusComplete", nil)
baremetal.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
logclient.AddActionLogWithStartable(self, baremetal, logclient.ACT_SYNC_CONF, "", self.UserCred, true)
}
func (self *BaremetalSyncConfigTask) OnSyncstatusComplete(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) {
self.SetStageComplete(ctx, nil)
}