github.com/vmware/govmomi@v0.51.0/lookup/simulator/registration_info.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 "github.com/google/uuid" 9 10 "github.com/vmware/govmomi/lookup" 11 "github.com/vmware/govmomi/lookup/types" 12 "github.com/vmware/govmomi/simulator" 13 "github.com/vmware/govmomi/vim25" 14 ) 15 16 var ( 17 siteID = "vcsim" 18 ) 19 20 // registrationInfo returns a ServiceRegistration populated with vcsim's OptionManager settings. 21 // The complete list can be captured using: govc sso.service.ls -dump 22 func registrationInfo(ctx *simulator.Context) []types.LookupServiceRegistrationInfo { 23 vctx := ctx.For(vim25.Path) 24 vc := vctx.Map.Get(vim25.ServiceInstance).(*simulator.ServiceInstance) 25 setting := vctx.Map.OptionManager().Setting 26 sm := vctx.Map.SessionManager() 27 opts := make(map[string]string, len(setting)) 28 29 for _, o := range setting { 30 opt := o.GetOptionValue() 31 if val, ok := opt.Value.(string); ok { 32 opts[opt.Key] = val 33 } 34 } 35 36 trust := []string{sm.TLSCert()} 37 sdk := opts["vcsim.server.url"] + vim25.Path 38 admin := opts["config.vpxd.sso.default.admin"] 39 owner := opts["config.vpxd.sso.solutionUser.name"] 40 instance := opts["VirtualCenter.InstanceName"] 41 42 // Real PSC has 30+ services by default, we just provide a few that are useful for vmomi interaction.. 43 info := []types.LookupServiceRegistrationInfo{ 44 { 45 LookupServiceRegistrationCommonServiceInfo: types.LookupServiceRegistrationCommonServiceInfo{ 46 LookupServiceRegistrationMutableServiceInfo: types.LookupServiceRegistrationMutableServiceInfo{ 47 ServiceVersion: lookup.Version, 48 ServiceEndpoints: []types.LookupServiceRegistrationEndpoint{ 49 { 50 Url: opts["config.vpxd.sso.sts.uri"], 51 EndpointType: types.LookupServiceRegistrationEndpointType{ 52 Protocol: "wsTrust", 53 Type: "com.vmware.cis.cs.identity.sso", 54 }, 55 SslTrust: trust, 56 }, 57 }, 58 }, 59 OwnerId: admin, 60 ServiceType: types.LookupServiceRegistrationServiceType{ 61 Product: "com.vmware.cis", 62 Type: "cs.identity", 63 }, 64 }, 65 ServiceId: siteID + ":" + uuid.New().String(), 66 SiteId: siteID, 67 }, 68 { 69 LookupServiceRegistrationCommonServiceInfo: types.LookupServiceRegistrationCommonServiceInfo{ 70 LookupServiceRegistrationMutableServiceInfo: types.LookupServiceRegistrationMutableServiceInfo{ 71 ServiceVersion: lookup.Version, 72 ServiceEndpoints: []types.LookupServiceRegistrationEndpoint{ 73 { 74 Url: opts["config.vpxd.sso.admin.uri"], 75 EndpointType: types.LookupServiceRegistrationEndpointType{ 76 Protocol: "vmomi", 77 Type: "com.vmware.cis.cs.identity.admin", 78 }, 79 SslTrust: trust, 80 }, 81 }, 82 }, 83 OwnerId: admin, 84 ServiceType: types.LookupServiceRegistrationServiceType{ 85 Product: "com.vmware.cis", 86 Type: "cs.identity", 87 }, 88 }, 89 ServiceId: siteID + ":" + uuid.New().String(), 90 SiteId: siteID, 91 }, 92 { 93 LookupServiceRegistrationCommonServiceInfo: types.LookupServiceRegistrationCommonServiceInfo{ 94 LookupServiceRegistrationMutableServiceInfo: types.LookupServiceRegistrationMutableServiceInfo{ 95 ServiceVersion: vim25.Version, 96 ServiceEndpoints: []types.LookupServiceRegistrationEndpoint{ 97 { 98 Url: sdk, 99 EndpointType: types.LookupServiceRegistrationEndpointType{ 100 Protocol: "vmomi", 101 Type: "com.vmware.vim", 102 }, 103 SslTrust: trust, 104 EndpointAttributes: []types.LookupServiceRegistrationAttribute{ 105 { 106 Key: "cis.common.ep.localurl", 107 Value: sdk, 108 }, 109 }, 110 }, 111 }, 112 ServiceAttributes: []types.LookupServiceRegistrationAttribute{ 113 { 114 Key: "com.vmware.cis.cm.GroupInternalId", 115 Value: "com.vmware.vim.vcenter", 116 }, 117 { 118 Key: "com.vmware.vim.vcenter.instanceName", 119 Value: instance, 120 }, 121 { 122 Key: "com.vmware.cis.cm.ControlScript", 123 Value: "service-control-default-vmon", 124 }, 125 { 126 Key: "com.vmware.cis.cm.HostId", 127 Value: uuid.New().String(), 128 }, 129 }, 130 ServiceNameResourceKey: "AboutInfo.vpx.name", 131 ServiceDescriptionResourceKey: "AboutInfo.vpx.name", 132 }, 133 OwnerId: owner, 134 ServiceType: types.LookupServiceRegistrationServiceType{ 135 Product: "com.vmware.cis", 136 Type: "vcenterserver", 137 }, 138 NodeId: uuid.New().String(), 139 }, 140 ServiceId: vc.Content.About.InstanceUuid, 141 SiteId: siteID, 142 }, 143 } 144 145 sts := info[0] 146 sts.ServiceType.Type = "sso:sts" // obsolete service type, but still used by PowerCLI 147 148 return append(info, sts) 149 }