Skip to content

Commit 9ec310a

Browse files
committed
vcsim: add UpdateAssignedLicense method
- govc object.save includes licenseAssignmentManager property Signed-off-by: Doug MacEachern <[email protected]>
1 parent 1481d91 commit 9ec310a

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

govc/object/save.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2019-2024 VMware, Inc. All Rights Reserved.
2+
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -290,10 +290,15 @@ func (cmd *save) Run(ctx context.Context, f *flag.FlagSet) error {
290290

291291
for _, p := range content[0].PropSet {
292292
if c, ok := p.Val.(types.ServiceContent); ok {
293+
var path []string
293294
for _, ref := range mo.References(c) {
294295
all := types.NewBool(true)
295296
switch ref.Type {
296-
case "LicenseManager", "ServiceManager":
297+
case "LicenseManager":
298+
// avoid saving "licenses" property as it includes the keys
299+
path = []string{"licenseAssignmentManager"}
300+
all = nil
301+
case "ServiceManager":
297302
all = nil
298303
}
299304
req.SpecSet = append(req.SpecSet, types.PropertyFilterSpec{
@@ -303,7 +308,7 @@ func (cmd *save) Run(ctx context.Context, f *flag.FlagSet) error {
303308
PropSet: []types.PropertySpec{{
304309
Type: ref.Type,
305310
All: all,
306-
PathSet: nil,
311+
PathSet: path,
307312
}},
308313
})
309314
}

govc/test/license.bats

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ get_nlabel() {
3838
assert_equal "License is not valid for this product" "$(get_key 00000-00000-00000-00000-00002 <<<${output} | get_property diagnostic)"
3939
}
4040

41+
@test "license.assign" {
42+
vcsim_env
43+
44+
run govc license.assign -cluster DC0_C0 00000-00000-00000-00000-00000
45+
assert_success
46+
47+
run govc license.assigned.ls
48+
assert_success
49+
}
50+
4151
@test "license.remove" {
42-
esx_env
52+
vcsim_env
4353

4454
verify_evaluation
4555

simulator/license_manager.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
/*
2-
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
2+
Copyright (c) 2017-2024 VMware, Inc. All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
// Copyright 2017 VMware, Inc. All Rights Reserved.
17-
//
18-
// Licensed under the Apache License, Version 2.0 (the "License");
19-
// you may not use this file except in compliance with the License.
20-
// You may obtain a copy of the License at
21-
//
22-
// http://www.apache.org/licenses/LICENSE-2.0
23-
//
24-
// Unless required by applicable law or agreed to in writing, software
25-
// distributed under the License is distributed on an "AS IS" BASIS,
26-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27-
// See the License for the specific language governing permissions and
28-
// limitations under the License.
2916

3017
package simulator
3118

@@ -67,12 +54,19 @@ func (m *LicenseManager) init(r *Registry) {
6754
m.Licenses = []types.LicenseManagerLicenseInfo{EvalLicense}
6855

6956
if r.IsVPX() {
70-
am := Map.Put(&LicenseAssignmentManager{}).Reference()
71-
m.LicenseAssignmentManager = &am
57+
if m.LicenseAssignmentManager == nil {
58+
m.LicenseAssignmentManager = &types.ManagedObjectReference{
59+
Type: "LicenseAssignmentManager",
60+
Value: "LicenseAssignmentManager",
61+
}
62+
}
63+
r.Put(&LicenseAssignmentManager{
64+
mo.LicenseAssignmentManager{Self: *m.LicenseAssignmentManager},
65+
})
7266
}
7367
}
7468

75-
func (m *LicenseManager) AddLicense(req *types.AddLicense) soap.HasFault {
69+
func (m *LicenseManager) AddLicense(ctx *Context, req *types.AddLicense) soap.HasFault {
7670
body := &methods.AddLicenseBody{
7771
Res: &types.AddLicenseResponse{},
7872
}
@@ -94,7 +88,7 @@ func (m *LicenseManager) AddLicense(req *types.AddLicense) soap.HasFault {
9488
return body
9589
}
9690

97-
func (m *LicenseManager) RemoveLicense(req *types.RemoveLicense) soap.HasFault {
91+
func (m *LicenseManager) RemoveLicense(ctx *Context, req *types.RemoveLicense) soap.HasFault {
9892
body := &methods.RemoveLicenseBody{
9993
Res: &types.RemoveLicenseResponse{},
10094
}
@@ -108,7 +102,7 @@ func (m *LicenseManager) RemoveLicense(req *types.RemoveLicense) soap.HasFault {
108102
return body
109103
}
110104

111-
func (m *LicenseManager) UpdateLicenseLabel(req *types.UpdateLicenseLabel) soap.HasFault {
105+
func (m *LicenseManager) UpdateLicenseLabel(ctx *Context, req *types.UpdateLicenseLabel) soap.HasFault {
112106
body := &methods.UpdateLicenseLabelBody{}
113107

114108
for i := range m.Licenses {
@@ -149,20 +143,20 @@ type LicenseAssignmentManager struct {
149143
mo.LicenseAssignmentManager
150144
}
151145

152-
func (m *LicenseAssignmentManager) QueryAssignedLicenses(req *types.QueryAssignedLicenses) soap.HasFault {
146+
func (m *LicenseAssignmentManager) QueryAssignedLicenses(ctx *Context, req *types.QueryAssignedLicenses) soap.HasFault {
153147
body := &methods.QueryAssignedLicensesBody{
154148
Res: &types.QueryAssignedLicensesResponse{},
155149
}
156150

157151
// EntityId can be a HostSystem or the vCenter InstanceUuid
158152
if req.EntityId != "" {
159-
if req.EntityId != Map.content().About.InstanceUuid {
153+
if req.EntityId != ctx.Map.content().About.InstanceUuid {
160154
id := types.ManagedObjectReference{
161155
Type: "HostSystem",
162156
Value: req.EntityId,
163157
}
164158

165-
if Map.Get(id) == nil {
159+
if ctx.Map.Get(id) == nil {
166160
return body
167161
}
168162
}
@@ -178,6 +172,16 @@ func (m *LicenseAssignmentManager) QueryAssignedLicenses(req *types.QueryAssigne
178172
return body
179173
}
180174

175+
func (m *LicenseAssignmentManager) UpdateAssignedLicense(ctx *Context, req *types.UpdateAssignedLicense) soap.HasFault {
176+
body := &methods.UpdateAssignedLicenseBody{
177+
Res: &types.UpdateAssignedLicenseResponse{
178+
Returnval: licenseInfo(req.LicenseKey, nil),
179+
},
180+
}
181+
182+
return body
183+
}
184+
181185
func licenseInfo(key string, labels []types.KeyValue) types.LicenseManagerLicenseInfo {
182186
info := EvalLicense
183187

0 commit comments

Comments
 (0)