diff --git a/pkg/hostman/client.go b/pkg/hostman/client.go new file mode 100644 index 0000000000..579d0d675a --- /dev/null +++ b/pkg/hostman/client.go @@ -0,0 +1,33 @@ +package hostman + +import ( + "context" + "fmt" + + "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/appctx" + "yunion.io/x/onecloud/pkg/hostman/options" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/auth" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +var session *mcclient.ClientSession + +func GetComputeSession() *mcclient.ClientSession { + return session +} + +func init() { + session = auth.GetAdminSession(options.HostOptions.Region, "v2") +} + +func TaskFailed(ctx context.Context, reason string) error { + if taskId := ctx.Value(appctx.APP_CONTEXT_KEY_TASK_ID); taskId != nil { + modules.ComputeTasks.TaskFailed(ctx, taskId.(string), reason) + return nil + } else { + log.Errorln("Reqeuest task failed missing task id, with reason(%s)", reason) + return fmt.Errorf("Reqeuest task failed missing task id") + } +} diff --git a/pkg/hostman/guestman/guestman.go b/pkg/hostman/guestman/guestman.go index e5e4af2648..ddae2bc4b2 100644 --- a/pkg/hostman/guestman/guestman.go +++ b/pkg/hostman/guestman/guestman.go @@ -19,8 +19,6 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/workmanager" "yunion.io/x/onecloud/pkg/hostman/guestfs" "yunion.io/x/onecloud/pkg/httperrors" - "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/auth" "yunion.io/x/pkg/util/regutils" "yunion.io/x/pkg/util/seclib" ) @@ -350,15 +348,6 @@ func Init(serversPath string) { var guestManger *SGuestManager var wm *workmanager.SWorkManager -var session *mcclient.ClientSession - -func SetClientSession() *mcclient.ClientSession { - session = auth.GetAdminSession(o.Options.Region, "v2") -} - -func GetClinetSession() *mcclient.ClientSession { - return session -} func GetGuestManager() *SGuestManager { return guestManger diff --git a/pkg/hostman/guestman/guesttasks.go b/pkg/hostman/guestman/guesttasks.go index fc5bca3708..2b3dbae6f3 100644 --- a/pkg/hostman/guestman/guesttasks.go +++ b/pkg/hostman/guestman/guesttasks.go @@ -41,8 +41,7 @@ func (s *SGuestStopTask) onPowerdownGuest(results string) { func (s *SGuestStopTask) checkGuestRunning() { if !s.IsRunning() || time.Now().Sub(*s.startPowerdown) > (s.timeout*time.Duration) { - // force stop - s.Stop() + s.Stop() // force stop httpclients.TaskComplete(s.ctx, nil) } else { s.CheckGuestRunningLater() diff --git a/pkg/mcclient/modules/mod_tasks.go b/pkg/mcclient/modules/mod_tasks.go index e9a21ff7d0..8dbfc433ae 100644 --- a/pkg/mcclient/modules/mod_tasks.go +++ b/pkg/mcclient/modules/mod_tasks.go @@ -20,10 +20,8 @@ type ComputeTasksManager struct { } func init() { - Tasks = NewITSMManager("task", "taskman", - []string{"id", "status", "create_by", "update_by", "delete_by", "gmt_create", "gmt_modified", "gmt_delete", "is_deleted", "project_id", "remark", "instance_id", "business_id", "task_id", "task_type", "task_name", "task_status", "current_approver", "approver_name", "receive_time", "finish_time", "result", "content", "common_start_string"}, - []string{"id", "status", "create_by", "update_by", "delete_by", "gmt_create", "gmt_modified", "gmt_delete", "is_deleted", "project_id", "remark", "instance_id", "business_id", "task_id", "task_type", "task_name", "task_status", "current_approver", "approver_name", "receive_time", "finish_time", "result", "content", "common_start_string"}, - ) + cols := []string{"id", "status", "create_by", "update_by", "delete_by", "gmt_create", "gmt_modified", "gmt_delete", "is_deleted", "project_id", "remark", "instance_id", "business_id", "task_id", "task_type", "task_name", "task_status", "current_approver", "approver_name", "receive_time", "finish_time", "result", "content", "common_start_string"} + Tasks = NewITSMManager("task", "taskman", cols, cols) register(&Tasks) ComputeTasks = ComputeTasksManager{