diagnostic_manager.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Copyright (c) 2015 VMware, Inc. All Rights Reserved.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package object
  14. import (
  15. "context"
  16. "github.com/vmware/govmomi/vim25"
  17. "github.com/vmware/govmomi/vim25/methods"
  18. "github.com/vmware/govmomi/vim25/types"
  19. )
  20. type DiagnosticManager struct {
  21. Common
  22. }
  23. func NewDiagnosticManager(c *vim25.Client) *DiagnosticManager {
  24. m := DiagnosticManager{
  25. Common: NewCommon(c, *c.ServiceContent.DiagnosticManager),
  26. }
  27. return &m
  28. }
  29. func (m DiagnosticManager) Log(ctx context.Context, host *HostSystem, key string) *DiagnosticLog {
  30. return &DiagnosticLog{
  31. m: m,
  32. Key: key,
  33. Host: host,
  34. }
  35. }
  36. func (m DiagnosticManager) BrowseLog(ctx context.Context, host *HostSystem, key string, start, lines int32) (*types.DiagnosticManagerLogHeader, error) {
  37. req := types.BrowseDiagnosticLog{
  38. This: m.Reference(),
  39. Key: key,
  40. Start: start,
  41. Lines: lines,
  42. }
  43. if host != nil {
  44. ref := host.Reference()
  45. req.Host = &ref
  46. }
  47. res, err := methods.BrowseDiagnosticLog(ctx, m.Client(), &req)
  48. if err != nil {
  49. return nil, err
  50. }
  51. return &res.Returnval, nil
  52. }
  53. func (m DiagnosticManager) GenerateLogBundles(ctx context.Context, includeDefault bool, host []*HostSystem) (*Task, error) {
  54. req := types.GenerateLogBundles_Task{
  55. This: m.Reference(),
  56. IncludeDefault: includeDefault,
  57. }
  58. if host != nil {
  59. for _, h := range host {
  60. req.Host = append(req.Host, h.Reference())
  61. }
  62. }
  63. res, err := methods.GenerateLogBundles_Task(ctx, m.c, &req)
  64. if err != nil {
  65. return nil, err
  66. }
  67. return NewTask(m.c, res.Returnval), nil
  68. }
  69. func (m DiagnosticManager) QueryDescriptions(ctx context.Context, host *HostSystem) ([]types.DiagnosticManagerLogDescriptor, error) {
  70. req := types.QueryDescriptions{
  71. This: m.Reference(),
  72. }
  73. if host != nil {
  74. ref := host.Reference()
  75. req.Host = &ref
  76. }
  77. res, err := methods.QueryDescriptions(ctx, m.Client(), &req)
  78. if err != nil {
  79. return nil, err
  80. }
  81. return res.Returnval, nil
  82. }