chassis.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. "context"
  17. "fmt"
  18. "yunion.io/x/pkg/util/printutils"
  19. "yunion.io/x/pkg/util/shellutils"
  20. "yunion.io/x/onecloud/pkg/util/redfish"
  21. )
  22. func init() {
  23. type IndicatorLEDOptions struct {
  24. }
  25. shellutils.R(&IndicatorLEDOptions{}, "led-get", "Get status of Indicator LED", func(cli redfish.IRedfishDriver, args *IndicatorLEDOptions) error {
  26. on, err := cli.GetIndicatorLED(context.Background())
  27. if err != nil {
  28. return err
  29. }
  30. fmt.Println("IndicatorLED", on)
  31. return nil
  32. })
  33. shellutils.R(&IndicatorLEDOptions{}, "led-on", "Set status of Indicator LED on", func(cli redfish.IRedfishDriver, args *IndicatorLEDOptions) error {
  34. err := cli.SetIndicatorLED(context.Background(), true)
  35. if err != nil {
  36. return err
  37. }
  38. fmt.Println("Success!")
  39. return nil
  40. })
  41. shellutils.R(&IndicatorLEDOptions{}, "led-off", "Set status of Indicator LED off", func(cli redfish.IRedfishDriver, args *IndicatorLEDOptions) error {
  42. err := cli.SetIndicatorLED(context.Background(), false)
  43. if err != nil {
  44. return err
  45. }
  46. fmt.Println("Success!")
  47. return nil
  48. })
  49. shellutils.R(&IndicatorLEDOptions{}, "power-get", "Get current power consumption", func(cli redfish.IRedfishDriver, args *IndicatorLEDOptions) error {
  50. powers, err := cli.GetPower(context.Background())
  51. if err != nil {
  52. return err
  53. }
  54. printutils.PrintInterfaceList(powers, 0, 0, 0, nil)
  55. return nil
  56. })
  57. shellutils.R(&IndicatorLEDOptions{}, "thermal-get", "Get current temperatures", func(cli redfish.IRedfishDriver, args *IndicatorLEDOptions) error {
  58. temps, err := cli.GetThermal(context.Background())
  59. if err != nil {
  60. return err
  61. }
  62. printutils.PrintInterfaceList(temps, 0, 0, 0, nil)
  63. return nil
  64. })
  65. }