idrac.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 idrac9
  15. import (
  16. "context"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. "yunion.io/x/onecloud/pkg/util/redfish"
  20. "yunion.io/x/onecloud/pkg/util/redfish/bmconsole"
  21. "yunion.io/x/onecloud/pkg/util/redfish/generic"
  22. "yunion.io/x/onecloud/pkg/util/redfish/idrac"
  23. )
  24. type SIDrac9RedfishApiFactory struct {
  25. }
  26. func (f *SIDrac9RedfishApiFactory) Name() string {
  27. return "iDRAC9"
  28. }
  29. func (f *SIDrac9RedfishApiFactory) NewApi(endpoint, username, password string, debug bool) redfish.IRedfishDriver {
  30. return NewIDrac9RedfishApi(endpoint, username, password, debug)
  31. }
  32. func init() {
  33. redfish.RegisterApiFactory(&SIDrac9RedfishApiFactory{})
  34. }
  35. type SIDrac9RefishApi struct {
  36. idrac.SIDracRefishApi
  37. }
  38. func NewIDrac9RedfishApi(endpoint, username, password string, debug bool) redfish.IRedfishDriver {
  39. api := &SIDrac9RefishApi{
  40. SIDracRefishApi: idrac.SIDracRefishApi{
  41. SGenericRefishApi: generic.SGenericRefishApi{
  42. SBaseRedfishClient: redfish.NewBaseRedfishClient(endpoint, username, password, debug),
  43. },
  44. },
  45. }
  46. api.SetVirtualObject(api)
  47. return api
  48. }
  49. func (r *SIDrac9RefishApi) ParseRoot(root jsonutils.JSONObject) error {
  50. // log.Debugf("ParseRoot %s", root.PrettyString())
  51. oem, _ := root.Get("Oem", "Dell")
  52. if oem != nil {
  53. return nil
  54. }
  55. return errors.Error("not iDrac")
  56. }
  57. func (r *SIDrac9RefishApi) GetNTPConf(ctx context.Context) (redfish.SNTPConf, error) {
  58. return r.SGenericRefishApi.GetNTPConf(ctx)
  59. }
  60. func (r *SIDrac9RefishApi) SetNTPConf(ctx context.Context, conf redfish.SNTPConf) error {
  61. return r.SGenericRefishApi.SetNTPConf(ctx, conf)
  62. }
  63. func (r *SIDrac9RefishApi) GetConsoleJNLP(ctx context.Context) (string, error) {
  64. bmc := bmconsole.NewBMCConsole(r.GetHost(), r.GetUsername(), r.GetPassword(), r.IsDebug)
  65. return bmc.GetIdrac9ConsoleJNLP(ctx)
  66. }
  67. func (r *SIDrac9RefishApi) GetSystemLogsPath() string {
  68. return "/redfish/v1/Managers/iDRAC.Embedded.1/LogServices/Sel/Entries"
  69. }
  70. func (r *SIDrac9RefishApi) GetManagerLogsPath() string {
  71. return "/redfish/v1/Managers/iDRAC.Embedded.1/LogServices/Lclog/Entries"
  72. }
  73. func (r *SIDrac9RefishApi) GetClearSystemLogsPath() string {
  74. return "/redfish/v1/Managers/iDRAC.Embedded.1/LogServices/Sel/Actions/LogService.ClearLog"
  75. }
  76. func (r *SIDrac9RefishApi) GetClearManagerLogsPath() string {
  77. return "/redfish/v1/Managers/iDRAC.Embedded.1/LogServices/Lclog/Actions/LogService.ClearLog"
  78. }
  79. func (r *SIDrac9RefishApi) GetPowerPath() string {
  80. return "/redfish/v1/Chassis/System.Embedded.1/Power"
  81. }
  82. func (r *SIDrac9RefishApi) GetThermalPath() string {
  83. return "/redfish/v1/Chassis/System.Embedded.1/Thermal"
  84. }