github.com/vmware/govmomi@v0.43.0/simulator/service_instance.go (about) 1 /* 2 Copyright (c) 2017 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 "time" 21 22 "github.com/google/uuid" 23 24 "github.com/vmware/govmomi/simulator/internal" 25 "github.com/vmware/govmomi/vim25" 26 "github.com/vmware/govmomi/vim25/methods" 27 "github.com/vmware/govmomi/vim25/mo" 28 "github.com/vmware/govmomi/vim25/soap" 29 "github.com/vmware/govmomi/vim25/types" 30 ) 31 32 type ServiceInstance struct { 33 mo.ServiceInstance 34 } 35 36 func NewServiceInstance(ctx *Context, content types.ServiceContent, folder mo.Folder) *ServiceInstance { 37 // TODO: This function ignores the passed in Map and operates on the 38 // global Map. 39 Map = NewRegistry() 40 ctx.Map = Map 41 42 s := &ServiceInstance{} 43 44 s.Self = vim25.ServiceInstance 45 s.Content = content 46 47 Map.Put(s) 48 49 f := &Folder{Folder: folder} 50 Map.Put(f) 51 52 if content.About.ApiType == "HostAgent" { 53 CreateDefaultESX(ctx, f) 54 } else { 55 content.About.InstanceUuid = uuid.New().String() 56 } 57 58 refs := mo.References(content) 59 60 for i := range refs { 61 if Map.Get(refs[i]) != nil { 62 continue 63 } 64 content := types.ObjectContent{Obj: refs[i]} 65 o, err := loadObject(content) 66 if err != nil { 67 panic(err) 68 } 69 Map.Put(o) 70 } 71 72 return s 73 } 74 75 func (s *ServiceInstance) RetrieveServiceContent(*types.RetrieveServiceContent) soap.HasFault { 76 return &methods.RetrieveServiceContentBody{ 77 Res: &types.RetrieveServiceContentResponse{ 78 Returnval: s.Content, 79 }, 80 } 81 } 82 83 func (*ServiceInstance) CurrentTime(*types.CurrentTime) soap.HasFault { 84 return &methods.CurrentTimeBody{ 85 Res: &types.CurrentTimeResponse{ 86 Returnval: time.Now(), 87 }, 88 } 89 } 90 91 func (s *ServiceInstance) RetrieveInternalContent(*internal.RetrieveInternalContent) soap.HasFault { 92 return &internal.RetrieveInternalContentBody{ 93 Res: &internal.RetrieveInternalContentResponse{ 94 Returnval: internal.InternalServiceInstanceContent{ 95 NfcService: types.ManagedObjectReference{Type: "NfcService", Value: "NfcService"}, 96 }, 97 }, 98 } 99 }