github.com/vmware/govmomi@v0.37.1/simulator/extension_manager.go (about) 1 /* 2 Copyright (c) 2024-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 "time" 21 22 "github.com/vmware/govmomi/vim25/methods" 23 "github.com/vmware/govmomi/vim25/mo" 24 "github.com/vmware/govmomi/vim25/soap" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 var ExtensionList = []types.Extension{ 29 { 30 Description: &types.Description{ 31 Label: "vcsim", 32 Summary: "Go vCenter simulator", 33 }, 34 Key: "com.vmware.govmomi.simulator", 35 Company: "VMware, Inc.", 36 Type: "", 37 Version: "0.37.0", 38 SubjectName: "", 39 Server: nil, 40 Client: nil, 41 TaskList: []types.ExtensionTaskTypeInfo{ 42 { 43 TaskID: "com.vmware.govmomi.simulator.test", 44 }, 45 }, 46 EventList: nil, 47 FaultList: nil, 48 PrivilegeList: nil, 49 ResourceList: nil, 50 LastHeartbeatTime: time.Now(), 51 HealthInfo: (*types.ExtensionHealthInfo)(nil), 52 OvfConsumerInfo: (*types.ExtensionOvfConsumerInfo)(nil), 53 ExtendedProductInfo: (*types.ExtExtendedProductInfo)(nil), 54 ManagedEntityInfo: nil, 55 ShownInSolutionManager: types.NewBool(false), 56 SolutionManagerInfo: (*types.ExtSolutionManagerInfo)(nil), 57 }, 58 } 59 60 type ExtensionManager struct { 61 mo.ExtensionManager 62 } 63 64 func (m *ExtensionManager) init(r *Registry) { 65 if r.IsVPX() && len(m.ExtensionList) == 0 { 66 m.ExtensionList = ExtensionList 67 } 68 } 69 70 func (m *ExtensionManager) FindExtension(ctx *Context, req *types.FindExtension) soap.HasFault { 71 body := &methods.FindExtensionBody{ 72 Res: new(types.FindExtensionResponse), 73 } 74 75 for _, x := range m.ExtensionList { 76 if x.Key == req.ExtensionKey { 77 body.Res.Returnval = &x 78 break 79 } 80 } 81 82 return body 83 } 84 85 func (m *ExtensionManager) RegisterExtension(ctx *Context, req *types.RegisterExtension) soap.HasFault { 86 body := &methods.RegisterExtensionBody{} 87 88 for _, x := range m.ExtensionList { 89 if x.Key == req.Extension.Key { 90 body.Fault_ = Fault("", &types.InvalidArgument{ 91 InvalidProperty: "extension.key", 92 }) 93 return body 94 } 95 } 96 97 body.Res = new(types.RegisterExtensionResponse) 98 m.ExtensionList = append(m.ExtensionList, req.Extension) 99 100 return body 101 } 102 103 func (m *ExtensionManager) UnregisterExtension(ctx *Context, req *types.UnregisterExtension) soap.HasFault { 104 body := &methods.UnregisterExtensionBody{} 105 106 for i, x := range m.ExtensionList { 107 if x.Key == req.ExtensionKey { 108 m.ExtensionList = append(m.ExtensionList[:i], m.ExtensionList[i+1:]...) 109 110 body.Res = new(types.UnregisterExtensionResponse) 111 return body 112 } 113 } 114 115 body.Fault_ = Fault("", new(types.NotFound)) 116 117 return body 118 } 119 120 func (m *ExtensionManager) UpdateExtension(ctx *Context, req *types.UpdateExtension) soap.HasFault { 121 body := &methods.UpdateExtensionBody{} 122 123 for i, x := range m.ExtensionList { 124 if x.Key == req.Extension.Key { 125 m.ExtensionList[i] = req.Extension 126 127 body.Res = new(types.UpdateExtensionResponse) 128 return body 129 } 130 } 131 132 body.Fault_ = Fault("", new(types.NotFound)) 133 134 return body 135 } 136 137 func (m *ExtensionManager) SetExtensionCertificate(ctx *Context, req *types.SetExtensionCertificate) soap.HasFault { 138 body := &methods.SetExtensionCertificateBody{} 139 140 for _, x := range m.ExtensionList { 141 if x.Key == req.ExtensionKey { 142 // TODO: save req.CertificatePem for use with SessionManager.LoginExtensionByCertificate() 143 144 body.Res = new(types.SetExtensionCertificateResponse) 145 return body 146 } 147 } 148 149 body.Fault_ = Fault("", new(types.NotFound)) 150 151 return body 152 }