host_config_manager.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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/mo"
  18. "github.com/vmware/govmomi/vim25/types"
  19. )
  20. type HostConfigManager struct {
  21. Common
  22. }
  23. func NewHostConfigManager(c *vim25.Client, ref types.ManagedObjectReference) *HostConfigManager {
  24. return &HostConfigManager{
  25. Common: NewCommon(c, ref),
  26. }
  27. }
  28. func (m HostConfigManager) DatastoreSystem(ctx context.Context) (*HostDatastoreSystem, error) {
  29. var h mo.HostSystem
  30. err := m.Properties(ctx, m.Reference(), []string{"configManager.datastoreSystem"}, &h)
  31. if err != nil {
  32. return nil, err
  33. }
  34. return NewHostDatastoreSystem(m.c, *h.ConfigManager.DatastoreSystem), nil
  35. }
  36. func (m HostConfigManager) NetworkSystem(ctx context.Context) (*HostNetworkSystem, error) {
  37. var h mo.HostSystem
  38. err := m.Properties(ctx, m.Reference(), []string{"configManager.networkSystem"}, &h)
  39. if err != nil {
  40. return nil, err
  41. }
  42. return NewHostNetworkSystem(m.c, *h.ConfigManager.NetworkSystem), nil
  43. }
  44. func (m HostConfigManager) FirewallSystem(ctx context.Context) (*HostFirewallSystem, error) {
  45. var h mo.HostSystem
  46. err := m.Properties(ctx, m.Reference(), []string{"configManager.firewallSystem"}, &h)
  47. if err != nil {
  48. return nil, err
  49. }
  50. return NewHostFirewallSystem(m.c, *h.ConfigManager.FirewallSystem), nil
  51. }
  52. func (m HostConfigManager) StorageSystem(ctx context.Context) (*HostStorageSystem, error) {
  53. var h mo.HostSystem
  54. err := m.Properties(ctx, m.Reference(), []string{"configManager.storageSystem"}, &h)
  55. if err != nil {
  56. return nil, err
  57. }
  58. return NewHostStorageSystem(m.c, *h.ConfigManager.StorageSystem), nil
  59. }
  60. func (m HostConfigManager) VirtualNicManager(ctx context.Context) (*HostVirtualNicManager, error) {
  61. var h mo.HostSystem
  62. err := m.Properties(ctx, m.Reference(), []string{"configManager.virtualNicManager"}, &h)
  63. if err != nil {
  64. return nil, err
  65. }
  66. return NewHostVirtualNicManager(m.c, *h.ConfigManager.VirtualNicManager, m.Reference()), nil
  67. }
  68. func (m HostConfigManager) VsanSystem(ctx context.Context) (*HostVsanSystem, error) {
  69. var h mo.HostSystem
  70. err := m.Properties(ctx, m.Reference(), []string{"configManager.vsanSystem"}, &h)
  71. if err != nil {
  72. return nil, err
  73. }
  74. // Added in 5.5
  75. if h.ConfigManager.VsanSystem == nil {
  76. return nil, ErrNotSupported
  77. }
  78. return NewHostVsanSystem(m.c, *h.ConfigManager.VsanSystem), nil
  79. }
  80. func (m HostConfigManager) VsanInternalSystem(ctx context.Context) (*HostVsanInternalSystem, error) {
  81. var h mo.HostSystem
  82. err := m.Properties(ctx, m.Reference(), []string{"configManager.vsanInternalSystem"}, &h)
  83. if err != nil {
  84. return nil, err
  85. }
  86. // Added in 5.5
  87. if h.ConfigManager.VsanInternalSystem == nil {
  88. return nil, ErrNotSupported
  89. }
  90. return NewHostVsanInternalSystem(m.c, *h.ConfigManager.VsanInternalSystem), nil
  91. }
  92. func (m HostConfigManager) AccountManager(ctx context.Context) (*HostAccountManager, error) {
  93. var h mo.HostSystem
  94. err := m.Properties(ctx, m.Reference(), []string{"configManager.accountManager"}, &h)
  95. if err != nil {
  96. return nil, err
  97. }
  98. ref := h.ConfigManager.AccountManager // Added in 6.0
  99. if ref == nil {
  100. // Versions < 5.5 can use the ServiceContent ref,
  101. // but we can only use it when connected directly to ESX.
  102. c := m.Client()
  103. if !c.IsVC() {
  104. ref = c.ServiceContent.AccountManager
  105. }
  106. if ref == nil {
  107. return nil, ErrNotSupported
  108. }
  109. }
  110. return NewHostAccountManager(m.c, *ref), nil
  111. }
  112. func (m HostConfigManager) OptionManager(ctx context.Context) (*OptionManager, error) {
  113. var h mo.HostSystem
  114. err := m.Properties(ctx, m.Reference(), []string{"configManager.advancedOption"}, &h)
  115. if err != nil {
  116. return nil, err
  117. }
  118. return NewOptionManager(m.c, *h.ConfigManager.AdvancedOption), nil
  119. }
  120. func (m HostConfigManager) ServiceSystem(ctx context.Context) (*HostServiceSystem, error) {
  121. var h mo.HostSystem
  122. err := m.Properties(ctx, m.Reference(), []string{"configManager.serviceSystem"}, &h)
  123. if err != nil {
  124. return nil, err
  125. }
  126. return NewHostServiceSystem(m.c, *h.ConfigManager.ServiceSystem), nil
  127. }
  128. func (m HostConfigManager) CertificateManager(ctx context.Context) (*HostCertificateManager, error) {
  129. var h mo.HostSystem
  130. err := m.Properties(ctx, m.Reference(), []string{"configManager.certificateManager"}, &h)
  131. if err != nil {
  132. return nil, err
  133. }
  134. // Added in 6.0
  135. if h.ConfigManager.CertificateManager == nil {
  136. return nil, ErrNotSupported
  137. }
  138. return NewHostCertificateManager(m.c, *h.ConfigManager.CertificateManager, m.Reference()), nil
  139. }
  140. func (m HostConfigManager) DateTimeSystem(ctx context.Context) (*HostDateTimeSystem, error) {
  141. var h mo.HostSystem
  142. err := m.Properties(ctx, m.Reference(), []string{"configManager.dateTimeSystem"}, &h)
  143. if err != nil {
  144. return nil, err
  145. }
  146. return NewHostDateTimeSystem(m.c, *h.ConfigManager.DateTimeSystem), nil
  147. }