baremetal_base_task.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package baremetal
  15. import (
  16. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  17. "yunion.io/x/onecloud/pkg/compute/models"
  18. "yunion.io/x/onecloud/pkg/util/logclient"
  19. )
  20. type SBaremetalBaseTask struct {
  21. taskman.STask
  22. }
  23. func (self *SBaremetalBaseTask) Action() string {
  24. actionMap := map[string]string{
  25. "start": logclient.ACT_VM_START,
  26. "stop": logclient.ACT_VM_STOP,
  27. "maintenance": logclient.ACT_BM_MAINTENANCE,
  28. "unmaintenance": logclient.ACT_BM_UNMAINTENANCE,
  29. }
  30. if self.Params.Contains("action") {
  31. action, _ := self.Params.GetString("action")
  32. self.Params.Remove("action")
  33. if val, ok := actionMap[action]; len(action) > 0 && ok {
  34. return val
  35. }
  36. }
  37. return ""
  38. }
  39. func (self *SBaremetalBaseTask) GetBaremetal() *models.SHost {
  40. obj := self.GetObject()
  41. return obj.(*models.SHost)
  42. }