1/* 2Copyright (c) 2015 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 HostVsanSystem struct { 29 Common 30} 31 32func NewHostVsanSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostVsanSystem { 33 return &HostVsanSystem{ 34 Common: NewCommon(c, ref), 35 } 36} 37 38func (s HostVsanSystem) Update(ctx context.Context, config types.VsanHostConfigInfo) (*Task, error) { 39 req := types.UpdateVsan_Task{ 40 This: s.Reference(), 41 Config: config, 42 } 43 44 res, err := methods.UpdateVsan_Task(ctx, s.Client(), &req) 45 if err != nil { 46 return nil, err 47 } 48 49 return NewTask(s.Client(), res.Returnval), nil 50} 51 52// updateVnic in support of the HostVirtualNicManager.{SelectVnic,DeselectVnic} methods 53func (s HostVsanSystem) updateVnic(ctx context.Context, device string, enable bool) error { 54 var vsan mo.HostVsanSystem 55 56 err := s.Properties(ctx, s.Reference(), []string{"config.networkInfo.port"}, &vsan) 57 if err != nil { 58 return err 59 } 60 61 info := vsan.Config 62 63 var port []types.VsanHostConfigInfoNetworkInfoPortConfig 64 65 for _, p := range info.NetworkInfo.Port { 66 if p.Device == device { 67 continue 68 } 69 70 port = append(port, p) 71 } 72 73 if enable { 74 port = append(port, types.VsanHostConfigInfoNetworkInfoPortConfig{ 75 Device: device, 76 }) 77 } 78 79 info.NetworkInfo.Port = port 80 81 task, err := s.Update(ctx, info) 82 if err != nil { 83 return err 84 } 85 86 _, err = task.WaitForResult(ctx, nil) 87 return err 88} 89