host_vsan_system.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2015 VMware, Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package object
  14. import (
  15. "context"
  16. "github.com/vmware/govmomi/vim25"
  17. "github.com/vmware/govmomi/vim25/methods"
  18. "github.com/vmware/govmomi/vim25/mo"
  19. "github.com/vmware/govmomi/vim25/types"
  20. )
  21. type HostVsanSystem struct {
  22. Common
  23. }
  24. func NewHostVsanSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostVsanSystem {
  25. return &HostVsanSystem{
  26. Common: NewCommon(c, ref),
  27. }
  28. }
  29. func (s HostVsanSystem) Update(ctx context.Context, config types.VsanHostConfigInfo) (*Task, error) {
  30. req := types.UpdateVsan_Task{
  31. This: s.Reference(),
  32. Config: config,
  33. }
  34. res, err := methods.UpdateVsan_Task(ctx, s.Client(), &req)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return NewTask(s.Client(), res.Returnval), nil
  39. }
  40. // updateVnic in support of the HostVirtualNicManager.{SelectVnic,DeselectVnic} methods
  41. func (s HostVsanSystem) updateVnic(ctx context.Context, device string, enable bool) error {
  42. var vsan mo.HostVsanSystem
  43. err := s.Properties(ctx, s.Reference(), []string{"config.networkInfo.port"}, &vsan)
  44. if err != nil {
  45. return err
  46. }
  47. info := vsan.Config
  48. var port []types.VsanHostConfigInfoNetworkInfoPortConfig
  49. for _, p := range info.NetworkInfo.Port {
  50. if p.Device == device {
  51. continue
  52. }
  53. port = append(port, p)
  54. }
  55. if enable {
  56. port = append(port, types.VsanHostConfigInfoNetworkInfoPortConfig{
  57. Device: device,
  58. })
  59. }
  60. info.NetworkInfo.Port = port
  61. task, err := s.Update(ctx, info)
  62. if err != nil {
  63. return err
  64. }
  65. _, err = task.WaitForResult(ctx, nil)
  66. return err
  67. }