1/* 2Copyright (c) 2015 VMware, Inc. All Rights Reserved. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package object 18 19import ( 20 "context" 21 22 "github.com/vmware/govmomi/vim25" 23 "github.com/vmware/govmomi/vim25/mo" 24 "github.com/vmware/govmomi/vim25/types" 25) 26 27type HostConfigManager struct { 28 Common 29} 30 31func NewHostConfigManager(c *vim25.Client, ref types.ManagedObjectReference) *HostConfigManager { 32 return &HostConfigManager{ 33 Common: NewCommon(c, ref), 34 } 35} 36 37func (m HostConfigManager) DatastoreSystem(ctx context.Context) (*HostDatastoreSystem, error) { 38 var h mo.HostSystem 39 40 err := m.Properties(ctx, m.Reference(), []string{"configManager.datastoreSystem"}, &h) 41 if err != nil { 42 return nil, err 43 } 44 45 return NewHostDatastoreSystem(m.c, *h.ConfigManager.DatastoreSystem), nil 46} 47 48func (m HostConfigManager) NetworkSystem(ctx context.Context) (*HostNetworkSystem, error) { 49 var h mo.HostSystem 50 51 err := m.Properties(ctx, m.Reference(), []string{"configManager.networkSystem"}, &h) 52 if err != nil { 53 return nil, err 54 } 55 56 return NewHostNetworkSystem(m.c, *h.ConfigManager.NetworkSystem), nil 57} 58 59func (m HostConfigManager) FirewallSystem(ctx context.Context) (*HostFirewallSystem, error) { 60 var h mo.HostSystem 61 62 err := m.Properties(ctx, m.Reference(), []string{"configManager.firewallSystem"}, &h) 63 if err != nil { 64 return nil, err 65 } 66 67 return NewHostFirewallSystem(m.c, *h.ConfigManager.FirewallSystem), nil 68} 69 70func (m HostConfigManager) StorageSystem(ctx context.Context) (*HostStorageSystem, error) { 71 var h mo.HostSystem 72 73 err := m.Properties(ctx, m.Reference(), []string{"configManager.storageSystem"}, &h) 74 if err != nil { 75 return nil, err 76 } 77 78 return NewHostStorageSystem(m.c, *h.ConfigManager.StorageSystem), nil 79} 80 81func (m HostConfigManager) VirtualNicManager(ctx context.Context) (*HostVirtualNicManager, error) { 82 var h mo.HostSystem 83 84 err := m.Properties(ctx, m.Reference(), []string{"configManager.virtualNicManager"}, &h) 85 if err != nil { 86 return nil, err 87 } 88 89 return NewHostVirtualNicManager(m.c, *h.ConfigManager.VirtualNicManager, m.Reference()), nil 90} 91 92func (m HostConfigManager) VsanSystem(ctx context.Context) (*HostVsanSystem, error) { 93 var h mo.HostSystem 94 95 err := m.Properties(ctx, m.Reference(), []string{"configManager.vsanSystem"}, &h) 96 if err != nil { 97 return nil, err 98 } 99 100 // Added in 5.5 101 if h.ConfigManager.VsanSystem == nil { 102 return nil, ErrNotSupported 103 } 104 105 return NewHostVsanSystem(m.c, *h.ConfigManager.VsanSystem), nil 106} 107 108func (m HostConfigManager) VsanInternalSystem(ctx context.Context) (*HostVsanInternalSystem, error) { 109 var h mo.HostSystem 110 111 err := m.Properties(ctx, m.Reference(), []string{"configManager.vsanInternalSystem"}, &h) 112 if err != nil { 113 return nil, err 114 } 115 116 // Added in 5.5 117 if h.ConfigManager.VsanInternalSystem == nil { 118 return nil, ErrNotSupported 119 } 120 121 return NewHostVsanInternalSystem(m.c, *h.ConfigManager.VsanInternalSystem), nil 122} 123 124func (m HostConfigManager) AccountManager(ctx context.Context) (*HostAccountManager, error) { 125 var h mo.HostSystem 126 127 err := m.Properties(ctx, m.Reference(), []string{"configManager.accountManager"}, &h) 128 if err != nil { 129 return nil, err 130 } 131 132 ref := h.ConfigManager.AccountManager // Added in 6.0 133 if ref == nil { 134 // Versions < 5.5 can use the ServiceContent ref, 135 // but we can only use it when connected directly to ESX. 136 c := m.Client() 137 if !c.IsVC() { 138 ref = c.ServiceContent.AccountManager 139 } 140 141 if ref == nil { 142 return nil, ErrNotSupported 143 } 144 } 145 146 return NewHostAccountManager(m.c, *ref), nil 147} 148 149func (m HostConfigManager) OptionManager(ctx context.Context) (*OptionManager, error) { 150 var h mo.HostSystem 151 152 err := m.Properties(ctx, m.Reference(), []string{"configManager.advancedOption"}, &h) 153 if err != nil { 154 return nil, err 155 } 156 157 return NewOptionManager(m.c, *h.ConfigManager.AdvancedOption), nil 158} 159 160func (m HostConfigManager) ServiceSystem(ctx context.Context) (*HostServiceSystem, error) { 161 var h mo.HostSystem 162 163 err := m.Properties(ctx, m.Reference(), []string{"configManager.serviceSystem"}, &h) 164 if err != nil { 165 return nil, err 166 } 167 168 return NewHostServiceSystem(m.c, *h.ConfigManager.ServiceSystem), nil 169} 170 171func (m HostConfigManager) CertificateManager(ctx context.Context) (*HostCertificateManager, error) { 172 var h mo.HostSystem 173 174 err := m.Properties(ctx, m.Reference(), []string{"configManager.certificateManager"}, &h) 175 if err != nil { 176 return nil, err 177 } 178 179 // Added in 6.0 180 if h.ConfigManager.CertificateManager == nil { 181 return nil, ErrNotSupported 182 } 183 184 return NewHostCertificateManager(m.c, *h.ConfigManager.CertificateManager, m.Reference()), nil 185} 186 187func (m HostConfigManager) DateTimeSystem(ctx context.Context) (*HostDateTimeSystem, error) { 188 var h mo.HostSystem 189 190 err := m.Properties(ctx, m.Reference(), []string{"configManager.dateTimeSystem"}, &h) 191 if err != nil { 192 return nil, err 193 } 194 195 return NewHostDateTimeSystem(m.c, *h.ConfigManager.DateTimeSystem), nil 196} 197