github.com/vmware/govmomi@v0.43.0/vsan/simulator/simulator.go (about) 1 /* 2 Copyright (c) 2021-2024 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 simulator 18 19 import ( 20 "github.com/google/uuid" 21 22 "github.com/vmware/govmomi/simulator" 23 "github.com/vmware/govmomi/vim25/soap" 24 vim "github.com/vmware/govmomi/vim25/types" 25 "github.com/vmware/govmomi/vsan" 26 "github.com/vmware/govmomi/vsan/methods" 27 "github.com/vmware/govmomi/vsan/types" 28 ) 29 30 func init() { 31 simulator.RegisterEndpoint(func(s *simulator.Service, r *simulator.Registry) { 32 if r.IsVPX() { 33 s.RegisterSDK(New()) 34 } 35 }) 36 } 37 38 func New() *simulator.Registry { 39 r := simulator.NewRegistry() 40 r.Namespace = vsan.Namespace 41 r.Path = vsan.Path 42 43 r.Put(&StretchedClusterSystem{ 44 ManagedObjectReference: vsan.VsanVcStretchedClusterSystem, 45 }) 46 47 r.Put(&ClusterConfigSystem{ 48 ManagedObjectReference: vsan.VsanVcClusterConfigSystemInstance, 49 }) 50 51 return r 52 } 53 54 type StretchedClusterSystem struct { 55 vim.ManagedObjectReference 56 } 57 58 func (s *StretchedClusterSystem) VSANVcConvertToStretchedCluster(ctx *simulator.Context, req *types.VSANVcConvertToStretchedCluster) soap.HasFault { 59 task := simulator.CreateTask(s, "convertToStretchedCluster", func(*simulator.Task) (vim.AnyType, vim.BaseMethodFault) { 60 // TODO: validate req fields 61 return nil, nil 62 }) 63 64 return &methods.VSANVcConvertToStretchedClusterBody{ 65 Res: &types.VSANVcConvertToStretchedClusterResponse{ 66 Returnval: task.Run(ctx), 67 }, 68 } 69 } 70 71 type ClusterConfigSystem struct { 72 vim.ManagedObjectReference 73 74 Config map[vim.ManagedObjectReference]*types.VsanConfigInfoEx 75 } 76 77 func (s *ClusterConfigSystem) info(ref vim.ManagedObjectReference) *types.VsanConfigInfoEx { 78 if s.Config == nil { 79 s.Config = make(map[vim.ManagedObjectReference]*types.VsanConfigInfoEx) 80 } 81 82 info := s.Config[ref] 83 if info == nil { 84 info = &types.VsanConfigInfoEx{} 85 info.DefaultConfig = &vim.VsanClusterConfigInfoHostDefaultInfo{ 86 Uuid: uuid.New().String(), 87 } 88 s.Config[ref] = info 89 } 90 91 return info 92 } 93 94 func (s *ClusterConfigSystem) VsanClusterGetConfig(ctx *simulator.Context, req *types.VsanClusterGetConfig) soap.HasFault { 95 return &methods.VsanClusterGetConfigBody{ 96 Res: &types.VsanClusterGetConfigResponse{ 97 Returnval: *s.info(req.Cluster), 98 }, 99 } 100 } 101 102 func (s *ClusterConfigSystem) VsanClusterReconfig(ctx *simulator.Context, req *types.VsanClusterReconfig) soap.HasFault { 103 task := simulator.CreateTask(s, "vsanClusterReconfig", func(*simulator.Task) (vim.AnyType, vim.BaseMethodFault) { 104 // TODO: validate req fields 105 info := s.info(req.Cluster) 106 if req.VsanReconfigSpec.UnmapConfig != nil { 107 info.UnmapConfig = req.VsanReconfigSpec.UnmapConfig 108 } 109 if req.VsanReconfigSpec.FileServiceConfig != nil { 110 info.FileServiceConfig = req.VsanReconfigSpec.FileServiceConfig 111 } 112 return nil, nil 113 }) 114 115 return &methods.VsanClusterReconfigBody{ 116 Res: &types.VsanClusterReconfigResponse{ 117 Returnval: task.Run(ctx), 118 }, 119 } 120 }