1/* 2Copyright (c) 2016 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/methods" 24 "github.com/vmware/govmomi/vim25/mo" 25 "github.com/vmware/govmomi/vim25/types" 26) 27 28type HostServiceSystem struct { 29 Common 30} 31 32func NewHostServiceSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostServiceSystem { 33 return &HostServiceSystem{ 34 Common: NewCommon(c, ref), 35 } 36} 37 38func (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 49func (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 59func (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 69func (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 79func (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} 89