github.com/vmware/govmomi@v0.37.1/eam/object/esx_agent_manager.go (about)

     1  /*
     2  Copyright (c) 2021 VMware, Inc. All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package object
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/vmware/govmomi/eam"
    23  	"github.com/vmware/govmomi/eam/methods"
    24  	"github.com/vmware/govmomi/eam/types"
    25  	vim "github.com/vmware/govmomi/vim25/types"
    26  )
    27  
    28  type EsxAgentManager struct {
    29  	EamObject
    30  }
    31  
    32  // NewEsxAgentManager returns a wrapper for an EsxAgentManager managed object.
    33  func NewEsxAgentManager(c *eam.Client, ref vim.ManagedObjectReference) EsxAgentManager {
    34  	return EsxAgentManager{
    35  		EamObject: EamObject{
    36  			c: c,
    37  			r: ref,
    38  		},
    39  	}
    40  }
    41  
    42  func (m EsxAgentManager) CreateAgency(
    43  	ctx context.Context,
    44  	config types.BaseAgencyConfigInfo,
    45  	initialGoalState string) (Agency, error) {
    46  
    47  	var agency Agency
    48  	resp, err := methods.CreateAgency(ctx, m.c, &types.CreateAgency{
    49  		This:             m.r,
    50  		AgencyConfigInfo: config,
    51  		InitialGoalState: initialGoalState,
    52  	})
    53  	if err != nil {
    54  		return agency, err
    55  	}
    56  	agency.c = m.c
    57  	agency.r = resp.Returnval
    58  	return agency, nil
    59  }
    60  
    61  func (m EsxAgentManager) Agencies(ctx context.Context) ([]Agency, error) {
    62  	resp, err := methods.QueryAgency(ctx, m.c, &types.QueryAgency{
    63  		This: m.r,
    64  	})
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  	objs := make([]Agency, len(resp.Returnval))
    69  	for i := range resp.Returnval {
    70  		objs[i].c = m.c
    71  		objs[i].r = resp.Returnval[i]
    72  	}
    73  	return objs, nil
    74  }
    75  
    76  func (m EsxAgentManager) ScanForUnknownAgentVm(ctx context.Context) error {
    77  	_, err := methods.ScanForUnknownAgentVm(ctx, m.c, &types.ScanForUnknownAgentVm{
    78  		This: m.r,
    79  	})
    80  	if err != nil {
    81  		return err
    82  	}
    83  	return nil
    84  }