boot.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 shell
  15. import (
  16. "fmt"
  17. "yunion.io/x/pkg/util/printutils"
  18. "yunion.io/x/pkg/util/shellutils"
  19. "yunion.io/x/onecloud/pkg/baremetal/utils/ipmitool"
  20. )
  21. func init() {
  22. shellutils.R(&EmptyOptions{}, "get-boot-flags", "Get boot flags info", func(client ipmitool.IPMIExecutor, _ *EmptyOptions) error {
  23. info, err := ipmitool.GetBootFlags(client)
  24. if err != nil {
  25. return err
  26. }
  27. printutils.PrintInterfaceObject(info)
  28. return nil
  29. })
  30. shellutils.R(&EmptyOptions{}, "do-reboot", "Do reboot", func(client ipmitool.IPMIExecutor, _ *EmptyOptions) error {
  31. return ipmitool.DoReboot(client)
  32. })
  33. shellutils.R(&BootFlagOptions{}, "set-boot-flag", "Set bootflag, do reboot to make it work", func(cli ipmitool.IPMIExecutor, args *BootFlagOptions) error {
  34. switch args.FLAG {
  35. case "pxe":
  36. return ipmitool.SetRebootToPXE(cli)
  37. case "disk":
  38. return ipmitool.SetRebootToDisk(cli)
  39. case "bios":
  40. return ipmitool.SetRebootToBIOS(cli)
  41. default:
  42. return fmt.Errorf("Invalid boot flag: %s", args.FLAG)
  43. }
  44. })
  45. shellutils.R(&ShutdownOptions{}, "do-shutdown", "Do shutdown", func(client ipmitool.IPMIExecutor, args *ShutdownOptions) error {
  46. if args.Soft {
  47. return ipmitool.DoSoftShutdown(client)
  48. }
  49. return ipmitool.DoHardShutdown(client)
  50. })
  51. shellutils.R(&EmptyOptions{}, "do-power-on", "Do power on", func(client ipmitool.IPMIExecutor, _ *EmptyOptions) error {
  52. return ipmitool.DoPowerOn(client)
  53. })
  54. shellutils.R(&EmptyOptions{}, "do-power-reset", "Do power on", func(client ipmitool.IPMIExecutor, _ *EmptyOptions) error {
  55. return ipmitool.DoPowerReset(client)
  56. })
  57. }