github.com/vmware/govmomi@v0.51.0/simulator/service_instance.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package simulator 6 7 import ( 8 "time" 9 10 "github.com/google/uuid" 11 12 "github.com/vmware/govmomi/simulator/internal" 13 "github.com/vmware/govmomi/vim25" 14 "github.com/vmware/govmomi/vim25/methods" 15 "github.com/vmware/govmomi/vim25/mo" 16 "github.com/vmware/govmomi/vim25/soap" 17 "github.com/vmware/govmomi/vim25/types" 18 ) 19 20 type ServiceInstance struct { 21 mo.ServiceInstance 22 } 23 24 func NewServiceInstance(ctx *Context, content types.ServiceContent, folder mo.Folder) (*Context, *ServiceInstance) { 25 s := &ServiceInstance{} 26 27 s.Self = vim25.ServiceInstance 28 s.Content = content 29 30 ctx.Map.Put(s) 31 32 f := &Folder{Folder: folder} 33 ctx.Map.Put(f) 34 35 if content.About.ApiType == "HostAgent" { 36 CreateDefaultESX(ctx, f) 37 } else { 38 content.About.InstanceUuid = uuid.New().String() 39 } 40 41 refs := mo.References(content) 42 43 for i := range refs { 44 if ctx.Map.Get(refs[i]) != nil { 45 continue 46 } 47 content := types.ObjectContent{Obj: refs[i]} 48 o, err := loadObject(ctx, content) 49 if err != nil { 50 panic(err) 51 } 52 ctx.Map.Put(o) 53 } 54 55 return ctx, s 56 } 57 58 func (s *ServiceInstance) ServiceContent() types.ServiceContent { 59 return s.Content 60 } 61 62 func (s *ServiceInstance) RetrieveServiceContent(*types.RetrieveServiceContent) soap.HasFault { 63 return &methods.RetrieveServiceContentBody{ 64 Res: &types.RetrieveServiceContentResponse{ 65 Returnval: s.Content, 66 }, 67 } 68 } 69 70 func (*ServiceInstance) CurrentTime(*types.CurrentTime) soap.HasFault { 71 return &methods.CurrentTimeBody{ 72 Res: &types.CurrentTimeResponse{ 73 Returnval: time.Now(), 74 }, 75 } 76 } 77 78 func (s *ServiceInstance) RetrieveInternalContent(*internal.RetrieveInternalContent) soap.HasFault { 79 return &internal.RetrieveInternalContentBody{ 80 Res: &internal.RetrieveInternalContentResponse{ 81 Returnval: internal.InternalServiceInstanceContent{ 82 NfcService: types.ManagedObjectReference{Type: "NfcService", Value: "NfcService"}, 83 }, 84 }, 85 } 86 }