github.com/vmware/govmomi@v0.51.0/object/host_service_system.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package object
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/vmware/govmomi/vim25"
    11  	"github.com/vmware/govmomi/vim25/methods"
    12  	"github.com/vmware/govmomi/vim25/mo"
    13  	"github.com/vmware/govmomi/vim25/types"
    14  )
    15  
    16  type HostServiceSystem struct {
    17  	Common
    18  }
    19  
    20  func NewHostServiceSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostServiceSystem {
    21  	return &HostServiceSystem{
    22  		Common: NewCommon(c, ref),
    23  	}
    24  }
    25  
    26  func (s HostServiceSystem) Service(ctx context.Context) ([]types.HostService, error) {
    27  	var ss mo.HostServiceSystem
    28  
    29  	err := s.Properties(ctx, s.Reference(), []string{"serviceInfo.service"}, &ss)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	return ss.ServiceInfo.Service, nil
    35  }
    36  
    37  func (s HostServiceSystem) Start(ctx context.Context, id string) error {
    38  	req := types.StartService{
    39  		This: s.Reference(),
    40  		Id:   id,
    41  	}
    42  
    43  	_, err := methods.StartService(ctx, s.Client(), &req)
    44  	return err
    45  }
    46  
    47  func (s HostServiceSystem) Stop(ctx context.Context, id string) error {
    48  	req := types.StopService{
    49  		This: s.Reference(),
    50  		Id:   id,
    51  	}
    52  
    53  	_, err := methods.StopService(ctx, s.Client(), &req)
    54  	return err
    55  }
    56  
    57  func (s HostServiceSystem) Restart(ctx context.Context, id string) error {
    58  	req := types.RestartService{
    59  		This: s.Reference(),
    60  		Id:   id,
    61  	}
    62  
    63  	_, err := methods.RestartService(ctx, s.Client(), &req)
    64  	return err
    65  }
    66  
    67  func (s HostServiceSystem) UpdatePolicy(ctx context.Context, id string, policy string) error {
    68  	req := types.UpdateServicePolicy{
    69  		This:   s.Reference(),
    70  		Id:     id,
    71  		Policy: policy,
    72  	}
    73  
    74  	_, err := methods.UpdateServicePolicy(ctx, s.Client(), &req)
    75  	return err
    76  }