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

     1  /*
     2  Copyright (c) 2016 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/vim25"
    23  	"github.com/vmware/govmomi/vim25/methods"
    24  	"github.com/vmware/govmomi/vim25/mo"
    25  	"github.com/vmware/govmomi/vim25/types"
    26  )
    27  
    28  type HostServiceSystem struct {
    29  	Common
    30  }
    31  
    32  func NewHostServiceSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostServiceSystem {
    33  	return &HostServiceSystem{
    34  		Common: NewCommon(c, ref),
    35  	}
    36  }
    37  
    38  func (s HostServiceSystem) Service(ctx context.Context) ([]types.HostService, error) {
    39  	var ss mo.HostServiceSystem
    40  
    41  	err := s.Properties(ctx, s.Reference(), []string{"serviceInfo.service"}, &ss)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	return ss.ServiceInfo.Service, nil
    47  }
    48  
    49  func (s HostServiceSystem) Start(ctx context.Context, id string) error {
    50  	req := types.StartService{
    51  		This: s.Reference(),
    52  		Id:   id,
    53  	}
    54  
    55  	_, err := methods.StartService(ctx, s.Client(), &req)
    56  	return err
    57  }
    58  
    59  func (s HostServiceSystem) Stop(ctx context.Context, id string) error {
    60  	req := types.StopService{
    61  		This: s.Reference(),
    62  		Id:   id,
    63  	}
    64  
    65  	_, err := methods.StopService(ctx, s.Client(), &req)
    66  	return err
    67  }
    68  
    69  func (s HostServiceSystem) Restart(ctx context.Context, id string) error {
    70  	req := types.RestartService{
    71  		This: s.Reference(),
    72  		Id:   id,
    73  	}
    74  
    75  	_, err := methods.RestartService(ctx, s.Client(), &req)
    76  	return err
    77  }
    78  
    79  func (s HostServiceSystem) UpdatePolicy(ctx context.Context, id string, policy string) error {
    80  	req := types.UpdateServicePolicy{
    81  		This:   s.Reference(),
    82  		Id:     id,
    83  		Policy: policy,
    84  	}
    85  
    86  	_, err := methods.UpdateServicePolicy(ctx, s.Client(), &req)
    87  	return err
    88  }