packer-cn/vendor/github.com/vmware/govmomi/object/host_config_manager.go

172 lines
4.8 KiB
Go
Raw Normal View History

2017-07-09 14:56:39 -04:00
/*
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package object
import (
"context"
2020-06-10 08:38:17 -04:00
"fmt"
2017-07-09 14:56:39 -04:00
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)
type HostConfigManager struct {
Common
}
func NewHostConfigManager(c *vim25.Client, ref types.ManagedObjectReference) *HostConfigManager {
return &HostConfigManager{
Common: NewCommon(c, ref),
}
}
2020-06-10 08:38:17 -04:00
// reference returns the ManagedObjectReference for the given HostConfigManager property name.
// An error is returned if the field is nil, of type ErrNotSupported if versioned is true.
func (m HostConfigManager) reference(ctx context.Context, name string, versioned ...bool) (types.ManagedObjectReference, error) {
prop := "configManager." + name
var content []types.ObjectContent
2017-07-09 14:56:39 -04:00
2020-06-10 08:38:17 -04:00
err := m.Properties(ctx, m.Reference(), []string{prop}, &content)
2017-07-09 14:56:39 -04:00
if err != nil {
2020-06-10 08:38:17 -04:00
return types.ManagedObjectReference{}, err
2017-07-09 14:56:39 -04:00
}
2020-06-10 08:38:17 -04:00
for _, c := range content {
for _, p := range c.PropSet {
if p.Name != prop {
continue
}
if ref, ok := p.Val.(types.ManagedObjectReference); ok {
return ref, nil
}
}
}
2017-07-09 14:56:39 -04:00
2020-06-10 08:38:17 -04:00
err = fmt.Errorf("%s %s is nil", m.Reference(), prop)
if len(versioned) == 1 && versioned[0] {
err = ErrNotSupported
}
return types.ManagedObjectReference{}, err
}
2017-07-09 14:56:39 -04:00
2020-06-10 08:38:17 -04:00
func (m HostConfigManager) DatastoreSystem(ctx context.Context) (*HostDatastoreSystem, error) {
ref, err := m.reference(ctx, "datastoreSystem")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostDatastoreSystem(m.c, ref), nil
}
2017-07-09 14:56:39 -04:00
2020-06-10 08:38:17 -04:00
func (m HostConfigManager) NetworkSystem(ctx context.Context) (*HostNetworkSystem, error) {
ref, err := m.reference(ctx, "networkSystem")
if err != nil {
return nil, err
}
return NewHostNetworkSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) FirewallSystem(ctx context.Context) (*HostFirewallSystem, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "firewallSystem")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostFirewallSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) StorageSystem(ctx context.Context) (*HostStorageSystem, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "storageSystem")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostStorageSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) VirtualNicManager(ctx context.Context) (*HostVirtualNicManager, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "virtualNicManager")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostVirtualNicManager(m.c, ref, m.Reference()), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) VsanSystem(ctx context.Context) (*HostVsanSystem, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "vsanSystem", true) // Added in 5.5
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostVsanSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) VsanInternalSystem(ctx context.Context) (*HostVsanInternalSystem, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "vsanInternalSystem", true) // Added in 5.5
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostVsanInternalSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) AccountManager(ctx context.Context) (*HostAccountManager, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "accountManager", true) // Added in 5.5
2017-07-09 14:56:39 -04:00
if err != nil {
2020-06-10 08:38:17 -04:00
if err == ErrNotSupported {
// Versions < 5.5 can use the ServiceContent ref,
// but only when connected directly to ESX.
if m.c.ServiceContent.AccountManager == nil {
return nil, err
}
ref = *m.c.ServiceContent.AccountManager
} else {
return nil, err
2017-07-09 14:56:39 -04:00
}
}
2020-06-10 08:38:17 -04:00
return NewHostAccountManager(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) OptionManager(ctx context.Context) (*OptionManager, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "advancedOption")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewOptionManager(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) ServiceSystem(ctx context.Context) (*HostServiceSystem, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "serviceSystem")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostServiceSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) CertificateManager(ctx context.Context) (*HostCertificateManager, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "certificateManager", true) // Added in 6.0
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostCertificateManager(m.c, ref, m.Reference()), nil
2017-07-09 14:56:39 -04:00
}
func (m HostConfigManager) DateTimeSystem(ctx context.Context) (*HostDateTimeSystem, error) {
2020-06-10 08:38:17 -04:00
ref, err := m.reference(ctx, "dateTimeSystem")
2017-07-09 14:56:39 -04:00
if err != nil {
return nil, err
}
2020-06-10 08:38:17 -04:00
return NewHostDateTimeSystem(m.c, ref), nil
2017-07-09 14:56:39 -04:00
}