baremetalevents.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 logger
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/onecloud/pkg/mcclient"
  18. "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/logger"
  20. )
  21. func init() {
  22. type BaremetalEventListOptions struct {
  23. HostId string `help:"filter by hostId"`
  24. HostName string `help:"filter by hostname"`
  25. IpmiIp string `help:"filter by ipmi_ip"`
  26. Type string `help:"filter by type" choices:"system|manager"`
  27. PagingMarker string `help:"marker for pagination"`
  28. Limit int `help:"page limit, default 20" default:"20"`
  29. Severity string `help:"filter by severity"`
  30. Since string `help:"Show logs since specific date" metavar:"DATETIME"`
  31. Until string `help:"Show logs until specific date" metavar:"DATETIME"`
  32. }
  33. R(&BaremetalEventListOptions{}, "baremetal-event-list", "List baremetal events", func(s *mcclient.ClientSession, args *BaremetalEventListOptions) error {
  34. params := jsonutils.Marshal(args)
  35. result, err := modules.BaremetalEvents.List(s, params)
  36. if err != nil {
  37. return err
  38. }
  39. printList(result, modules.BaremetalEvents.GetColumns(s))
  40. return nil
  41. })
  42. type BaremetalEventCreateOptions struct {
  43. HOST string `json:"-" help:"Host Id"`
  44. Type string `json:"type" help:"event type" choices:"system|manager"`
  45. EventId string `json:"event_id" help:"original event Id"`
  46. MESSAGE string `json:"message" help:"content of event"`
  47. Severity string `json:"severity" help:"Severity of event"`
  48. CREATED string `json:"created" help:"when event was created"`
  49. }
  50. R(&BaremetalEventCreateOptions{}, "baremetal-event-create", "Create baremetal event", func(s *mcclient.ClientSession, args *BaremetalEventCreateOptions) error {
  51. host, err := compute.Hosts.Get(s, args.HOST, nil)
  52. if err != nil {
  53. return err
  54. }
  55. hostId, _ := host.Get("id")
  56. hostName, _ := host.Get("name")
  57. ipmiIp, _ := host.Get("ipmi_ip")
  58. params := jsonutils.Marshal(args).(*jsonutils.JSONDict)
  59. params.Add(hostId, "host_id")
  60. params.Add(hostName, "host_name")
  61. params.Add(ipmiIp, "ipmi_ip")
  62. result, err := modules.BaremetalEvents.Create(s, params)
  63. if err != nil {
  64. return err
  65. }
  66. printObject(result)
  67. return nil
  68. })
  69. }