Skip to content

Commit 81828ed

Browse files
committedJan 16, 2025·
govc: enhance VAPI for vSphere Supervisor Services
- Update GET for both /supervisor-services and /supervisor-services/{id}/versions - Add GET for specific service and specific version: /supervisor-services/{id} and /supervisor-services/{id}/versions/{version} - Add DELETE for /supervisor-services/{id} and /supervisor-services/{id}/versions/{version}: DELETE for /supervisor-services/{id} and /supervisor-services/{id}/versions/{version} - Add activate/deactivate for a service version too (you can't delete a version of a service if it's not deactivated first): PATCH for superrvisor-services/{id} and /supervisor-services/{id}/versions/{version} - Update namespace.bats tests to test list and get - Update VAPI simulator to use `ServeHTTP` to make sure the path vlaues are set properly - Also update copyrights Fixes #3624 Testing Done: Ran `make install check doc` and `./govc/test/namespace.bats` Also ran against a real VC where I added 1 dummy service with 2 versions: `export GOVC_URL=...` ``` $ cat sample-pkg.test.carvel.dev-1.0.0.yaml apiVersion: data.packaging.carvel.dev/v1alpha1 kind: PackageMetadata metadata: name: sample-pkg-testgovc.test.carvel.dev spec: displayName: "sample-service for testing" shortDescription: "Sample core service description" --- apiVersion: data.packaging.carvel.dev/v1alpha1 kind: Package metadata: name: sample-pkg-testgovc.test.carvel.dev.1.0.0 spec: refName: sample-pkg-testgovc.test.carvel.dev version: 1.0.0 releasedAt: 2021-05-05T18:57:06Z template: spec: fetch: - imgpkgBundle: image: wcp-docker-ci.artifactory.eng.vmware.com/carvel/simple-app-bundle:v0.0.0 template: - ytt: paths: - config-step-2-template - config-step-2a-overlays deploy: - kapp: { } $ govc namespace.service.create sample-pkg.test.carvel.dev-1.0.0.yaml $ govc namespace.service.create sample-pkg.test.carvel.dev-1.0.0.yaml govc: 400 Bad Request: {"messages":[{"args":["sample-pkg-testgovc.test.carvel.dev","Supervisor Service"],"default_message":"Failed to create Supervisor Service sample-pkg-testgovc.test.carvel.dev because an instance of Supervisor Service with the same identifier already exists.","localized":"Failed to create Supervisor Service sample-pkg-testgovc.test.carvel.dev because an instance of Supervisor Service with the same identifier already exists.","id":"vcenter.wcp.appplatform.supervisorservice.write.unique_violation"}]} $ govc namespace.service.version.create sample-pkg-testgovc.test.carvel.dev sample-pkg.test.carvel.dev-2.0.0.yaml $ govc namespace.service.version.deactivate sample-pkg-testgovc.test.carvel.dev 2.0.0 $ govc namespace.service.version.activate sample-pkg-testgovc.test.carvel.dev 2.0.0 $ govc namespace.service.version.rm sample-pkg-testgovc.test.carvel.dev 2.0.0 govc: 400 Bad Request: {"messages":[{"args":["sample-pkg-testgovc.test.carvel.dev","2.0.0"],"default_message":"Cannot delete the Supervisor Service (sample-pkg-testgovc.test.carvel.dev) version (2.0.0) because it is active.","localized":"Cannot delete the Supervisor Service (sample-pkg-testgovc.test.carvel.dev) version (2.0.0) because it is active.","id":"vcenter.wcp.appplatform.supervisorserviceversion.delete.activated"}]} $ govc namespace.service.version.deactivate sample-pkg-testgovc.test.carvel.dev 2.0.0 $ govc namespace.service.version.rm sample-pkg-testgovc.test.carvel.dev 2.0.0 $ govc namespace.service.ls sample-pkg-testgovc.test.carvel.dev 2.0.0 $ govc namespace.service.ls -json [...] { "supervisor_service": "sample-pkg-testgovc.test.carvel.dev", "display_name": "sample-service for testing version", "state": "ACTIVATED" }, ] $ govc namespace.service.info -json sample-pkg-testgovc.test.carvel.dev { "display_name": "sample-service for testing version", "state": "ACTIVATED", "description": "Sample core service description", "must_be_installed": false, "has_default_versions_registered": false } { "must_be_installed": false, "has_default_versions_registered": false, "description": "Sample core service description", "state": "ACTIVATED", "display_name": "sample-service for testing version" } ``` Signed-off-by: Fanny Strudel <fanny.strudel@broadcom.com>
1 parent 8eb362f commit 81828ed

20 files changed

+941
-216
lines changed
 

‎cli/namespace/service/activate.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package service
186

@@ -39,7 +27,7 @@ func (cmd *activate) Register(ctx context.Context, f *flag.FlagSet) {
3927
}
4028

4129
func (cmd *activate) Description() string {
42-
return `Activates a vSphere Namespace Supervisor Service.
30+
return `Activates a vSphere Supervisor Service (and all its versions).
4331
4432
Examples:
4533
govc namespace.service.activate my-supervisor-service other-supervisor-service`

‎cli/namespace/service/create.go

+32-36
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package service
186

@@ -30,10 +18,7 @@ import (
3018

3119
type create struct {
3220
*flags.ClientFlag
33-
34-
specType string
35-
trustedProvider bool
36-
acceptEULA bool
21+
*ServiceVersionFlag
3722
}
3823

3924
func init() {
@@ -44,13 +29,14 @@ func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
4429
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
4530
cmd.ClientFlag.Register(ctx, f)
4631

47-
f.StringVar(&cmd.specType, "spec-type", "vsphere", "Type of Spec: only vsphere is supported right now")
48-
f.BoolVar(&cmd.trustedProvider, "trusted", false, "Define if this is a trusted provider")
49-
f.BoolVar(&cmd.acceptEULA, "accept-eula", false, "Auto accept EULA")
32+
cmd.ServiceVersionFlag = &ServiceVersionFlag{}
33+
cmd.ServiceVersionFlag.Register(ctx, f)
5034
}
5135

5236
func (cmd *create) Description() string {
53-
return `Creates a vSphere Namespace Supervisor Service.
37+
return `Registers a vSphere Supervisor Service version on vCenter for a new service.
38+
A service version can be registered once on vCenter and then be installed on multiple vSphere Supervisors managed by this vCenter.
39+
A vSphere Supervisor Service contains a list of service versions; this call will create a service and its first version.
5440
5541
Examples:
5642
govc namespace.service.create manifest.yaml`
@@ -60,30 +46,41 @@ func (cmd *create) Usage() string {
6046
return "MANIFEST"
6147
}
6248

49+
func (cmd *create) Process(ctx context.Context) error {
50+
if err := cmd.ServiceVersionFlag.Process(ctx); err != nil {
51+
return err
52+
}
53+
return cmd.ClientFlag.Process(ctx)
54+
}
55+
6356
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
64-
manifest := f.Args()
65-
if len(manifest) != 1 {
57+
if f.NArg() != 1 {
6658
return flag.ErrHelp
6759
}
6860

69-
if cmd.specType != "vsphere" {
70-
return fmt.Errorf("only vsphere specs are accepted right now")
71-
}
61+
manifestFile := f.Arg(0)
7262

73-
manifestFile, err := os.ReadFile(manifest[0])
63+
manifest, err := os.ReadFile(manifestFile)
7464
if err != nil {
7565
return fmt.Errorf("failed to read manifest file: %s", err)
7666
}
67+
content := base64.StdEncoding.EncodeToString(manifest)
7768

78-
content := base64.StdEncoding.EncodeToString(manifestFile)
79-
service := namespace.SupervisorService{
80-
VsphereService: namespace.SupervisorServicesVSphereSpec{
69+
service := namespace.SupervisorService{}
70+
if cmd.ServiceVersionFlag.SpecType == "carvel" {
71+
service.CarvelService = &namespace.SupervisorServicesCarvelSpec{
72+
VersionSpec: namespace.CarvelVersionCreateSpec{
73+
Content: content,
74+
},
75+
}
76+
} else {
77+
service.VsphereService = &namespace.SupervisorServicesVSphereSpec{
8178
VersionSpec: namespace.SupervisorServicesVSphereVersionCreateSpec{
8279
Content: content,
83-
AcceptEula: cmd.acceptEULA,
84-
TrustedProvider: cmd.trustedProvider,
80+
AcceptEula: cmd.ServiceVersionFlag.AcceptEULA,
81+
TrustedProvider: cmd.ServiceVersionFlag.TrustedProvider,
8582
},
86-
},
83+
}
8784
}
8885

8986
c, err := cmd.RestClient()
@@ -93,5 +90,4 @@ func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
9390

9491
m := namespace.NewManager(c)
9592
return m.CreateSupervisorService(ctx, &service)
96-
9793
}

‎cli/namespace/service/deactivate.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package service
186

@@ -39,7 +27,7 @@ func (cmd *deactivate) Register(ctx context.Context, f *flag.FlagSet) {
3927
}
4028

4129
func (cmd *deactivate) Description() string {
42-
return `Deactivates a vSphere Namespace Supervisor Service.
30+
return `Deactivates a vSphere Supervisor Service (and all its versions).
4331
4432
Examples:
4533
govc namespace.service.deactivate my-supervisor-service other-supervisor-service`

‎cli/namespace/service/flag.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 service
6+
7+
import (
8+
"context"
9+
"encoding/base64"
10+
"flag"
11+
"fmt"
12+
"os"
13+
14+
"github.com/vmware/govmomi/vapi/namespace"
15+
)
16+
17+
// Common processing of flags for service and service versions creation/update commands.
18+
type ServiceVersionFlag struct {
19+
SpecType string
20+
TrustedProvider bool
21+
AcceptEULA bool
22+
content string
23+
}
24+
25+
func (svf *ServiceVersionFlag) Register(ctx context.Context, f *flag.FlagSet) {
26+
f.StringVar(&svf.SpecType, "spec-type", "carvel", "Type of Spec: vsphere (deprecated) or carvel")
27+
f.BoolVar(&svf.TrustedProvider, "trusted", false, "Define if this is a trusted provider (only applicable for vSphere spec type)")
28+
f.BoolVar(&svf.AcceptEULA, "accept-eula", false, "Auto accept EULA (only required for vSphere spec type)")
29+
}
30+
31+
func (svf *ServiceVersionFlag) Process(ctx context.Context) error {
32+
if svf.SpecType != "vsphere" && svf.SpecType != "carvel" {
33+
return fmt.Errorf("Invalid type: '%v', only 'vsphere' and 'carvel' specs are supported", svf.SpecType)
34+
}
35+
return nil
36+
}
37+
38+
// SupervisorServiceVersionSpec returns a spec for a supervisor service version definition
39+
func (svf *ServiceVersionFlag) SupervisorServiceVersionSpec(manifestFile string) (namespace.SupervisorService, error) {
40+
service := namespace.SupervisorService{}
41+
manifest, err := os.ReadFile(manifestFile)
42+
if err != nil {
43+
return service, fmt.Errorf("failed to read manifest file: %s", err)
44+
}
45+
46+
content := base64.StdEncoding.EncodeToString(manifest)
47+
if svf.SpecType == "carvel" {
48+
service.CarvelService = &namespace.SupervisorServicesCarvelSpec{
49+
VersionSpec: namespace.CarvelVersionCreateSpec{
50+
Content: content,
51+
},
52+
}
53+
} else {
54+
service.VsphereService = &namespace.SupervisorServicesVSphereSpec{
55+
VersionSpec: namespace.SupervisorServicesVSphereVersionCreateSpec{
56+
Content: content,
57+
AcceptEula: svf.AcceptEULA,
58+
TrustedProvider: svf.TrustedProvider,
59+
},
60+
}
61+
}
62+
return service, nil
63+
}

‎cli/namespace/service/info.go

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021-2023 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package service
186

@@ -55,7 +43,7 @@ func (cmd *info) Process(ctx context.Context) error {
5543
}
5644

5745
func (cmd *info) Description() string {
58-
return `Gets information of a specific supervisor service.
46+
return `Gets information of a specific vSphere Supervisor Service.
5947
6048
Examples:
6149
govc namespace.service.info my-supervisor-service
@@ -73,7 +61,6 @@ func (r *infoWriter) Write(w io.Writer) error {
7361
fmt.Fprintf(tw, "%s", r.Service.Name)
7462
fmt.Fprintf(tw, "\t%s", r.Service.State)
7563
fmt.Fprintf(tw, "\t%s", r.Service.Description)
76-
7764
fmt.Fprintf(tw, "\n")
7865

7966
return tw.Flush()

‎cli/namespace/service/ls.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021-2023 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package service
186

@@ -58,7 +46,7 @@ func (cmd *ls) Process(ctx context.Context) error {
5846
}
5947

6048
func (cmd *ls) Description() string {
61-
return `List namepace registered supervisor services.
49+
return `List all registered vSphere Supervisor Services.
6250
6351
Examples:
6452
govc namespace.service.ls

‎cli/namespace/service/rm.go

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package service
186

@@ -40,7 +28,8 @@ func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
4028
}
4129

4230
func (cmd *rm) Description() string {
43-
return `Removes a vSphere Namespace Supervisor Service.
31+
return `Removes a vSphere Supervisor Service.
32+
Note that a service must be deactivated and all versions must be removed before being deleted.
4433
4534
Examples:
4635
govc namespace.service.rm my-supervisor-service other-supervisor-service`
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 version
6+
7+
import (
8+
"context"
9+
"flag"
10+
11+
"github.com/vmware/govmomi/cli"
12+
"github.com/vmware/govmomi/cli/flags"
13+
"github.com/vmware/govmomi/vapi/namespace"
14+
)
15+
16+
type activate struct {
17+
*flags.ClientFlag
18+
}
19+
20+
func init() {
21+
cli.Register("namespace.service.version.activate", &activate{})
22+
}
23+
24+
func (cmd *activate) Register(ctx context.Context, f *flag.FlagSet) {
25+
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
26+
cmd.ClientFlag.Register(ctx, f)
27+
}
28+
29+
func (cmd *activate) Description() string {
30+
return `Activates a vSphere Supervisor Service version.
31+
32+
Examples:
33+
govc namespace.service.version.activate my-supervisor-service 1.0.0`
34+
}
35+
36+
func (cmd *activate) Usage() string {
37+
return "NAME VERSION"
38+
}
39+
40+
func (cmd *activate) Run(ctx context.Context, f *flag.FlagSet) error {
41+
service := f.Arg(0)
42+
if len(service) == 0 {
43+
return flag.ErrHelp
44+
}
45+
version := f.Arg(1)
46+
if len(version) == 0 {
47+
return flag.ErrHelp
48+
}
49+
50+
c, err := cmd.RestClient()
51+
if err != nil {
52+
return err
53+
}
54+
55+
m := namespace.NewManager(c)
56+
return m.ActivateSupervisorServiceVersion(ctx, service, version)
57+
}
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 version
6+
7+
import (
8+
"context"
9+
"encoding/base64"
10+
"flag"
11+
"fmt"
12+
"os"
13+
14+
"github.com/vmware/govmomi/cli"
15+
"github.com/vmware/govmomi/cli/flags"
16+
"github.com/vmware/govmomi/cli/namespace/service"
17+
"github.com/vmware/govmomi/vapi/namespace"
18+
)
19+
20+
type create struct {
21+
*flags.ClientFlag
22+
*service.ServiceVersionFlag
23+
}
24+
25+
func init() {
26+
cli.Register("namespace.service.version.create", &create{})
27+
}
28+
29+
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
30+
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
31+
cmd.ClientFlag.Register(ctx, f)
32+
33+
cmd.ServiceVersionFlag = &service.ServiceVersionFlag{}
34+
cmd.ServiceVersionFlag.Register(ctx, f)
35+
}
36+
37+
func (cmd *create) Process(ctx context.Context) error {
38+
if err := cmd.ServiceVersionFlag.Process(ctx); err != nil {
39+
return err
40+
}
41+
return cmd.ClientFlag.Process(ctx)
42+
}
43+
44+
func (cmd *create) Description() string {
45+
return `Registers a new version for a registered vSphere Supervisor Service.
46+
47+
Examples:
48+
govc namespace.service.create my-service manifest-2.0.0.yaml`
49+
}
50+
51+
func (cmd *create) Usage() string {
52+
return "SERVICE MANIFEST"
53+
}
54+
55+
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
56+
if f.NArg() != 2 {
57+
return flag.ErrHelp
58+
}
59+
60+
id := f.Arg(0)
61+
manifestFile := f.Arg(1)
62+
manifest, err := os.ReadFile(manifestFile)
63+
if err != nil {
64+
return fmt.Errorf("failed to read manifest file: %s", err)
65+
}
66+
67+
content := base64.StdEncoding.EncodeToString(manifest)
68+
serviceVersion := namespace.SupervisorServiceVersion{}
69+
if cmd.ServiceVersionFlag.SpecType == "carvel" {
70+
serviceVersion.CarvelService = &namespace.CarvelVersionCreateSpec{
71+
Content: content,
72+
}
73+
} else {
74+
serviceVersion.VsphereService = &namespace.SupervisorServicesVSphereVersionCreateSpec{
75+
Content: content,
76+
AcceptEula: cmd.ServiceVersionFlag.AcceptEULA,
77+
TrustedProvider: cmd.ServiceVersionFlag.TrustedProvider,
78+
}
79+
}
80+
c, err := cmd.RestClient()
81+
if err != nil {
82+
return err
83+
}
84+
85+
m := namespace.NewManager(c)
86+
return m.CreateSupervisorServiceVersion(ctx, id, &serviceVersion)
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 version
6+
7+
import (
8+
"context"
9+
"flag"
10+
11+
"github.com/vmware/govmomi/cli"
12+
"github.com/vmware/govmomi/cli/flags"
13+
"github.com/vmware/govmomi/vapi/namespace"
14+
)
15+
16+
type deactivate struct {
17+
*flags.ClientFlag
18+
}
19+
20+
func init() {
21+
cli.Register("namespace.service.version.deactivate", &deactivate{})
22+
}
23+
24+
func (cmd *deactivate) Register(ctx context.Context, f *flag.FlagSet) {
25+
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
26+
cmd.ClientFlag.Register(ctx, f)
27+
}
28+
29+
func (cmd *deactivate) Description() string {
30+
return `Deactivates a vSphere Supervisor Service version.
31+
32+
Examples:
33+
govc namespace.service.version.deactivate my-supervisor-service 1.0.0`
34+
}
35+
36+
func (cmd *deactivate) Usage() string {
37+
return "NAME VERSION"
38+
}
39+
40+
func (cmd *deactivate) Run(ctx context.Context, f *flag.FlagSet) error {
41+
service := f.Arg(0)
42+
if len(service) == 0 {
43+
return flag.ErrHelp
44+
}
45+
version := f.Arg(1)
46+
if len(version) == 0 {
47+
return flag.ErrHelp
48+
}
49+
50+
c, err := cmd.RestClient()
51+
if err != nil {
52+
return err
53+
}
54+
55+
m := namespace.NewManager(c)
56+
return m.DeactivateSupervisorServiceVersion(ctx, service, version)
57+
}

‎cli/namespace/service/version/info.go

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 version
6+
7+
import (
8+
"context"
9+
"encoding/json"
10+
"flag"
11+
"fmt"
12+
"io"
13+
"os"
14+
"text/tabwriter"
15+
16+
"github.com/vmware/govmomi/cli"
17+
"github.com/vmware/govmomi/cli/flags"
18+
"github.com/vmware/govmomi/vapi/namespace"
19+
)
20+
21+
type info struct {
22+
*flags.ClientFlag
23+
*flags.OutputFlag
24+
}
25+
26+
func init() {
27+
cli.Register("namespace.service.version.info", &info{})
28+
}
29+
30+
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
31+
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
32+
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
33+
cmd.ClientFlag.Register(ctx, f)
34+
cmd.OutputFlag.Register(ctx, f)
35+
36+
}
37+
38+
func (cmd *info) Process(ctx context.Context) error {
39+
if err := cmd.ClientFlag.Process(ctx); err != nil {
40+
return err
41+
}
42+
return cmd.OutputFlag.Process(ctx)
43+
}
44+
45+
func (cmd *info) Description() string {
46+
return `Gets information of a specific vSphere Supervisor Service version.
47+
48+
Examples:
49+
govc namespace.service.version.info my-supervisor-service 2.0.0
50+
govc namespace.service.version.info -json my-supervisor-service 2.0.0 | jq .`
51+
}
52+
53+
type infoWriter struct {
54+
cmd *info
55+
Service namespace.SupervisorServiceVersionInfo `json:"service"`
56+
}
57+
58+
func (r *infoWriter) Write(w io.Writer) error {
59+
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
60+
61+
fmt.Fprintf(tw, "%s", r.Service.Name)
62+
fmt.Fprintf(tw, "\t%s", r.Service.State)
63+
fmt.Fprintf(tw, "\t%s", r.Service.Description)
64+
65+
fmt.Fprintf(tw, "\n")
66+
67+
return tw.Flush()
68+
}
69+
70+
func (r *infoWriter) MarshalJSON() ([]byte, error) {
71+
return json.Marshal(r.Service)
72+
}
73+
74+
func (r *infoWriter) Dump() interface{} {
75+
return r.Service
76+
}
77+
78+
func (cmd *info) Usage() string {
79+
return "NAME VERSION"
80+
}
81+
82+
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
83+
service := f.Arg(0)
84+
if len(service) == 0 {
85+
return flag.ErrHelp
86+
}
87+
version := f.Arg(1)
88+
if len(version) == 0 {
89+
return flag.ErrHelp
90+
}
91+
92+
c, err := cmd.RestClient()
93+
if err != nil {
94+
return err
95+
}
96+
97+
m := namespace.NewManager(c)
98+
serviceVersion, err := m.GetSupervisorServiceVersion(ctx, service, version)
99+
if err != nil {
100+
return err
101+
}
102+
103+
return cmd.WriteResult(&infoWriter{cmd, serviceVersion})
104+
}

‎cli/namespace/service/version/ls.go

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 version
6+
7+
import (
8+
"context"
9+
"encoding/json"
10+
"flag"
11+
"fmt"
12+
"io"
13+
"os"
14+
"text/tabwriter"
15+
16+
"github.com/vmware/govmomi/cli"
17+
"github.com/vmware/govmomi/cli/flags"
18+
"github.com/vmware/govmomi/vapi/namespace"
19+
)
20+
21+
type ls struct {
22+
*flags.ClientFlag
23+
*flags.OutputFlag
24+
25+
long bool
26+
}
27+
28+
func init() {
29+
cli.Register("namespace.service.version.ls", &ls{})
30+
}
31+
32+
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
33+
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
34+
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
35+
cmd.ClientFlag.Register(ctx, f)
36+
cmd.OutputFlag.Register(ctx, f)
37+
38+
f.BoolVar(&cmd.long, "l", false, "Long listing format")
39+
}
40+
41+
func (cmd *ls) Process(ctx context.Context) error {
42+
if err := cmd.ClientFlag.Process(ctx); err != nil {
43+
return err
44+
}
45+
return cmd.OutputFlag.Process(ctx)
46+
}
47+
48+
func (cmd *ls) Description() string {
49+
return `List all registered versions for a given vSphere Supervisor Service.
50+
51+
Examples:
52+
govc namespace.service.version.ls my-service
53+
govc namespace.service.version.ls -l my-service
54+
govc namespace.service.version.ls -json my-service | jq .`
55+
}
56+
57+
func (cmd *ls) Usage() string {
58+
return "NAME"
59+
}
60+
61+
type lsWriter struct {
62+
cmd *ls
63+
service string
64+
Versions []namespace.SupervisorServiceVersionSummary `json:"versions"`
65+
}
66+
67+
func (r *lsWriter) Write(w io.Writer) error {
68+
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
69+
fmt.Fprintf(tw, "%s:\n", r.service)
70+
for _, svc := range r.Versions {
71+
fmt.Fprintf(tw, "%s", svc.Version)
72+
if r.cmd.long {
73+
fmt.Fprintf(tw, "\t%s", svc.Name)
74+
fmt.Fprintf(tw, "\t%s", svc.State)
75+
fmt.Fprintf(tw, "\t%s", svc.Description)
76+
}
77+
fmt.Fprintf(tw, "\n")
78+
}
79+
return tw.Flush()
80+
}
81+
82+
func (r *lsWriter) MarshalJSON() ([]byte, error) {
83+
return json.Marshal(r.Versions)
84+
}
85+
86+
func (r *lsWriter) Dump() interface{} {
87+
return r.Versions
88+
}
89+
90+
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
91+
service := f.Arg(0)
92+
if len(service) == 0 {
93+
return flag.ErrHelp
94+
}
95+
c, err := cmd.RestClient()
96+
if err != nil {
97+
return err
98+
}
99+
100+
m := namespace.NewManager(c)
101+
versions, err := m.ListSupervisorServiceVersions(ctx, service)
102+
if err != nil {
103+
return err
104+
}
105+
106+
return cmd.WriteResult(&lsWriter{cmd, service, versions})
107+
}

‎cli/namespace/service/version/rm.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 version
6+
7+
import (
8+
"context"
9+
"flag"
10+
11+
"github.com/vmware/govmomi/cli"
12+
"github.com/vmware/govmomi/cli/flags"
13+
"github.com/vmware/govmomi/vapi/namespace"
14+
)
15+
16+
type rm struct {
17+
*flags.ClientFlag
18+
}
19+
20+
func init() {
21+
cli.Register("namespace.service.version.rm", &rm{})
22+
}
23+
24+
func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
25+
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
26+
cmd.ClientFlag.Register(ctx, f)
27+
}
28+
29+
func (cmd *rm) Description() string {
30+
return `Removes a vSphere Supervisor Service version.
31+
Note that a service version must be deactivated before being deleted.
32+
33+
Examples:
34+
govc namespace.service.version.rm my-supervisor-service 1.0.0`
35+
}
36+
37+
func (cmd *rm) Usage() string {
38+
return "NAME VERSION"
39+
}
40+
41+
func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
42+
service := f.Arg(0)
43+
if len(service) == 0 {
44+
return flag.ErrHelp
45+
}
46+
version := f.Arg(1)
47+
if len(version) == 0 {
48+
return flag.ErrHelp
49+
}
50+
51+
c, err := cmd.RestClient()
52+
if err != nil {
53+
return err
54+
}
55+
56+
m := namespace.NewManager(c)
57+
return m.RemoveSupervisorServiceVersion(ctx, service, version)
58+
}

‎govc/USAGE.md

+104-9
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ but appear via `govc $cmd -h`:
285285
- [namespace.service.info](#namespaceserviceinfo)
286286
- [namespace.service.ls](#namespaceservicels)
287287
- [namespace.service.rm](#namespaceservicerm)
288+
- [namespace.service.version.activate](#namespaceserviceversionactivate)
289+
- [namespace.service.version.create](#namespaceserviceversioncreate)
290+
- [namespace.service.version.deactivate](#namespaceserviceversiondeactivate)
291+
- [namespace.service.version.info](#namespaceserviceversioninfo)
292+
- [namespace.service.version.ls](#namespaceserviceversionls)
293+
- [namespace.service.version.rm](#namespaceserviceversionrm)
288294
- [namespace.update](#namespaceupdate)
289295
- [namespace.vmclass.create](#namespacevmclasscreate)
290296
- [namespace.vmclass.info](#namespacevmclassinfo)
@@ -4736,7 +4742,7 @@ Options:
47364742
```
47374743
Usage: govc namespace.service.activate [OPTIONS] NAME...
47384744
4739-
Activates a vSphere Namespace Supervisor Service.
4745+
Activates a vSphere Supervisor Service (and all its versions).
47404746
47414747
Examples:
47424748
govc namespace.service.activate my-supervisor-service other-supervisor-service
@@ -4749,23 +4755,25 @@ Options:
47494755
```
47504756
Usage: govc namespace.service.create [OPTIONS] MANIFEST
47514757
4752-
Creates a vSphere Namespace Supervisor Service.
4758+
Registers a vSphere Supervisor Service version on vCenter for a new service.
4759+
A service version can be registered once on vCenter and then be installed on multiple vSphere Supervisors managed by this vCenter.
4760+
A vSphere Supervisor Service contains a list of service versions; this call will create a service and its first version.
47534761
47544762
Examples:
47554763
govc namespace.service.create manifest.yaml
47564764
47574765
Options:
4758-
-accept-eula=false Auto accept EULA
4759-
-spec-type=vsphere Type of Spec: only vsphere is supported right now
4760-
-trusted=false Define if this is a trusted provider
4766+
-accept-eula=false Auto accept EULA (only required for vSphere spec type)
4767+
-spec-type=carvel Type of Spec: vsphere (deprecated) or carvel
4768+
-trusted=false Define if this is a trusted provider (only applicable for vSphere spec type)
47614769
```
47624770

47634771
## namespace.service.deactivate
47644772

47654773
```
47664774
Usage: govc namespace.service.deactivate [OPTIONS] NAME...
47674775
4768-
Deactivates a vSphere Namespace Supervisor Service.
4776+
Deactivates a vSphere Supervisor Service (and all its versions).
47694777
47704778
Examples:
47714779
govc namespace.service.deactivate my-supervisor-service other-supervisor-service
@@ -4778,7 +4786,7 @@ Options:
47784786
```
47794787
Usage: govc namespace.service.info [OPTIONS] NAME
47804788
4781-
Gets information of a specific supervisor service.
4789+
Gets information of a specific vSphere Supervisor Service.
47824790
47834791
Examples:
47844792
govc namespace.service.info my-supervisor-service
@@ -4792,7 +4800,7 @@ Options:
47924800
```
47934801
Usage: govc namespace.service.ls [OPTIONS]
47944802
4795-
List namepace registered supervisor services.
4803+
List all registered vSphere Supervisor Services.
47964804
47974805
Examples:
47984806
govc namespace.service.ls
@@ -4808,14 +4816,101 @@ Options:
48084816
```
48094817
Usage: govc namespace.service.rm [OPTIONS] NAME...
48104818
4811-
Removes a vSphere Namespace Supervisor Service.
4819+
Removes a vSphere Supervisor Service.
4820+
Note that a service must be deactivated and all versions must be removed before being deleted.
48124821
48134822
Examples:
48144823
govc namespace.service.rm my-supervisor-service other-supervisor-service
48154824
48164825
Options:
48174826
```
48184827

4828+
## namespace.service.version.activate
4829+
4830+
```
4831+
Usage: govc namespace.service.version.activate [OPTIONS] NAME VERSION
4832+
4833+
Activates a vSphere Supervisor Service version.
4834+
4835+
Examples:
4836+
govc namespace.service.version.activate my-supervisor-service 1.0.0
4837+
4838+
Options:
4839+
```
4840+
4841+
## namespace.service.version.create
4842+
4843+
```
4844+
Usage: govc namespace.service.version.create [OPTIONS] SERVICE MANIFEST
4845+
4846+
Registers a new version for a registered vSphere Supervisor Service.
4847+
4848+
Examples:
4849+
govc namespace.service.create my-service manifest-2.0.0.yaml
4850+
4851+
Options:
4852+
-accept-eula=false Auto accept EULA (only required for vSphere spec type)
4853+
-spec-type=carvel Type of Spec: vsphere (deprecated) or carvel
4854+
-trusted=false Define if this is a trusted provider (only applicable for vSphere spec type)
4855+
```
4856+
4857+
## namespace.service.version.deactivate
4858+
4859+
```
4860+
Usage: govc namespace.service.version.deactivate [OPTIONS] NAME VERSION
4861+
4862+
Deactivates a vSphere Supervisor Service version.
4863+
4864+
Examples:
4865+
govc namespace.service.version.deactivate my-supervisor-service 1.0.0
4866+
4867+
Options:
4868+
```
4869+
4870+
## namespace.service.version.info
4871+
4872+
```
4873+
Usage: govc namespace.service.version.info [OPTIONS] NAME VERSION
4874+
4875+
Gets information of a specific vSphere Supervisor Service version.
4876+
4877+
Examples:
4878+
govc namespace.service.version.info my-supervisor-service 2.0.0
4879+
govc namespace.service.version.info -json my-supervisor-service 2.0.0 | jq .
4880+
4881+
Options:
4882+
```
4883+
4884+
## namespace.service.version.ls
4885+
4886+
```
4887+
Usage: govc namespace.service.version.ls [OPTIONS] NAME
4888+
4889+
List all registered versions for a given vSphere Supervisor Service.
4890+
4891+
Examples:
4892+
govc namespace.service.version.ls my-service
4893+
govc namespace.service.version.ls -l my-service
4894+
govc namespace.service.version.ls -json my-service | jq .
4895+
4896+
Options:
4897+
-l=false Long listing format
4898+
```
4899+
4900+
## namespace.service.version.rm
4901+
4902+
```
4903+
Usage: govc namespace.service.version.rm [OPTIONS] NAME VERSION
4904+
4905+
Removes a vSphere Supervisor Service version.
4906+
Note that a service version must be deactivated before being deleted.
4907+
4908+
Examples:
4909+
govc namespace.service.version.rm my-supervisor-service 1.0.0
4910+
4911+
Options:
4912+
```
4913+
48194914
## namespace.update
48204915

48214916
```

‎govc/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import (
8787
_ "github.com/vmware/govmomi/cli/namespace"
8888
_ "github.com/vmware/govmomi/cli/namespace/cluster"
8989
_ "github.com/vmware/govmomi/cli/namespace/service"
90+
_ "github.com/vmware/govmomi/cli/namespace/service/version"
9091
_ "github.com/vmware/govmomi/cli/namespace/vmclass"
9192
_ "github.com/vmware/govmomi/cli/object"
9293
_ "github.com/vmware/govmomi/cli/option"

‎govc/test/namespace.bats

+44-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ load test_helper
9999
assert_success
100100
assert_matches ACTIVATED
101101
assert_matches mock-service-1
102+
assert_matches mock-service-2
103+
assert_matches DEACTIVATED
104+
}
105+
106+
@test "namespace.service.info notfound" {
107+
vcsim_env
108+
109+
run govc namespace.service.info non-existing-service
110+
assert_failure
111+
assert_matches "404 Not Found"
102112
}
103113

104114
@test "namespace.service.info" {
@@ -108,10 +118,40 @@ load test_helper
108118
assert_success
109119
assert_matches mock-service-1
110120
assert_matches ACTIVATED
111-
assert_matches "Description of service1"
112121

113122
run govc namespace.service.info -json service2
114-
assert_matches DE-ACTIVATED
123+
assert_matches DEACTIVATED
124+
}
125+
126+
@test "namespace.service.version.ls" {
127+
vcsim_env
128+
129+
versions=$(govc namespace.service.version.ls -json service1)
130+
assert_equal "2" $(echo $versions | jq '. | length')
131+
132+
run govc namespace.service.version.ls service1
133+
assert_success
134+
assert_matches "1.0.0"
135+
assert_matches "2.0.0"
136+
}
137+
138+
@test "namespace.service.version.info notfound" {
139+
vcsim_env
140+
141+
run govc namespace.service.version.info service2 9.9.9
142+
assert_failure
143+
assert_matches "404 Not Found"
144+
}
145+
146+
@test "namespace.service.version.info" {
147+
vcsim_env
148+
149+
v=$(govc namespace.service.version.info -json service2 1.1.0 | jq)
150+
151+
assert_equal "ACTIVATED" $(echo $v | jq -r .state)
152+
assert_equal "This is service 2 version 1.1.0" "$(echo $v | jq -r .description)"
153+
assert_equal "CARVEL_APPS_YAML" $(echo $v | jq -r .content_type)
154+
assert_equal "abc" $(echo $v | jq -r .content)
115155
}
116156

117157
@test "namespace.create" {
@@ -335,3 +375,5 @@ load test_helper
335375
run govc namespace.registervm -vm $vm test-namespace-1
336376
assert_success
337377
}
378+
379+

‎vapi/namespace/internal/internal.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2020-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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package internal
186

@@ -22,6 +10,7 @@ const (
2210
NamespaceDistributedSwitchCompatibility = "/api/vcenter/namespace-management/distributed-switch-compatibility"
2311
NamespaceEdgeClusterCompatibility = "/api/vcenter/namespace-management/edge-cluster-compatibility"
2412
SupervisorServicesPath = "/api/vcenter/namespace-management/supervisor-services"
13+
SupervisorServicesVersionsPath = "/versions"
2514

2615
NamespacesPath = "/api/vcenter/namespaces/instances"
2716
VmClassesPath = "/api/vcenter/namespace-management/virtual-machine-classes"

‎vapi/namespace/simulator/simulator.go

+98-29
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2020-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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator
186

@@ -48,7 +36,7 @@ func init() {
4836
})
4937
}
5038

51-
// Handler implements the Cluster Modules API simulator
39+
// Handler implements the Namespace Management Modules API simulator
5240
type Handler struct {
5341
URL *url.URL
5442
}
@@ -72,6 +60,8 @@ func (h *Handler) Register(s *simulator.Service, r *simulator.Registry) {
7260

7361
s.HandleFunc(internal.SupervisorServicesPath, h.listServices)
7462
s.HandleFunc(internal.SupervisorServicesPath+"/", h.getService)
63+
s.HandleFunc(internal.SupervisorServicesPath+"/{id}"+internal.SupervisorServicesVersionsPath, h.versionsForService)
64+
s.HandleFunc(internal.SupervisorServicesPath+"/{id}"+internal.SupervisorServicesVersionsPath+"/{version}", h.getServiceVersion)
7565

7666
s.HandleFunc(internal.VmClassesPath, h.vmClasses)
7767
s.HandleFunc(internal.VmClassesPath+"/", h.vmClasses)
@@ -209,22 +199,61 @@ func (h *Handler) listCompatibleEdgeClusters(w http.ResponseWriter, r *http.Requ
209199
}
210200
}
211201

212-
var supervisorServices []namespace.SupervisorServiceSummary = []namespace.SupervisorServiceSummary{
213-
{
202+
// Some fake services, service 1 has 2 versions, service 2 has 1 version
203+
// Summary for services
204+
var supervisorServicesMap = map[string]namespace.SupervisorServiceSummary{
205+
"service1": {
214206
ID: "service1",
215207
Name: "mock-service-1",
216208
State: "ACTIVATED",
217209
},
218-
{
210+
"service2": {
219211
ID: "service2",
220212
Name: "mock-service-2",
221-
State: "DE-ACTIVATED",
213+
State: "DEACTIVATED",
214+
},
215+
}
216+
217+
// Summary for service versions
218+
var supervisorServiceVersionsMap = map[string][]namespace.SupervisorServiceVersionSummary{
219+
"service1": {
220+
{
221+
SupervisorServiceInfo: namespace.SupervisorServiceInfo{
222+
Name: "mock-service-1 v1 display name",
223+
State: "ACTIVATED",
224+
Description: "This is service 1 version 1.0.0",
225+
},
226+
Version: "1.0.0",
227+
},
228+
{
229+
SupervisorServiceInfo: namespace.SupervisorServiceInfo{
230+
Name: "mock-service-1 v2 display name",
231+
State: "DEACTIVATED",
232+
Description: "This is service 1 version 2.0.0",
233+
},
234+
Version: "2.0.0",
235+
}},
236+
"service2": {
237+
{
238+
SupervisorServiceInfo: namespace.SupervisorServiceInfo{
239+
Name: "mock-service-2 v1 display name",
240+
State: "ACTIVATED",
241+
Description: "This is service 2 version 1.1.0",
242+
},
243+
Version: "1.1.0",
244+
},
222245
},
223246
}
224247

225248
func (h *Handler) listServices(w http.ResponseWriter, r *http.Request) {
226249
switch r.Method {
227250
case http.MethodGet:
251+
supervisorServices := make([]namespace.SupervisorServiceSummary, len(supervisorServicesMap))
252+
i := 0
253+
for _, service := range supervisorServicesMap {
254+
supervisorServices[i] = service
255+
i++
256+
}
228257
vapi.StatusOK(w, supervisorServices)
229258
}
230259
}
@@ -233,18 +262,58 @@ func (h *Handler) getService(w http.ResponseWriter, r *http.Request) {
233262
id := path.Base(r.URL.Path)
234263
switch r.Method {
235264
case http.MethodGet:
236-
for _, svc := range supervisorServices {
237-
if svc.ID == id {
238-
svcInfo := namespace.SupervisorServiceInfo{
239-
Name: svc.Name,
240-
State: svc.State,
241-
Description: fmt.Sprintf("Description of %s", svc.ID),
265+
if result, contains := supervisorServicesMap[id]; contains {
266+
vapi.StatusOK(w, result)
267+
} else {
268+
vapi.ApiErrorNotFound(w)
269+
}
270+
return
271+
}
272+
}
273+
274+
// versionsForService returns the list of versions for a particular service
275+
func (h *Handler) versionsForService(w http.ResponseWriter, r *http.Request) {
276+
fmt.Printf("In versionsForService: %v\n", r.URL.Path)
277+
id := r.PathValue("id")
278+
switch r.Method {
279+
case http.MethodGet:
280+
if result, contains := supervisorServiceVersionsMap[id]; contains {
281+
vapi.StatusOK(w, result)
282+
} else {
283+
vapi.ApiErrorNotFound(w)
284+
}
285+
return
286+
}
287+
}
288+
289+
// getServiceVersion returns info on a particular service version
290+
func (h *Handler) getServiceVersion(w http.ResponseWriter, r *http.Request) {
291+
id := r.PathValue("id")
292+
version := r.PathValue("version")
293+
294+
switch r.Method {
295+
case http.MethodGet:
296+
if versions, contains := supervisorServiceVersionsMap[id]; contains {
297+
for _, v := range versions {
298+
if v.Version == version {
299+
info := namespace.SupervisorServiceVersionInfo{
300+
SupervisorServiceInfo: namespace.SupervisorServiceInfo{
301+
Description: v.Description,
302+
State: v.State,
303+
Name: v.Name,
304+
},
305+
ContentType: "CARVEL_APPS_YAML", // return Carvel by default
306+
Content: "abc", // in reality this is base 64 encoded of content
307+
}
308+
vapi.StatusOK(w, info)
309+
return
242310
}
243-
vapi.StatusOK(w, svcInfo)
244-
return
245311
}
312+
vapi.ApiErrorNotFound(w)
313+
} else {
314+
vapi.ApiErrorNotFound(w)
246315
}
247-
w.WriteHeader(http.StatusNotFound)
316+
return
248317
}
249318
}
250319

‎vapi/namespace/supervisorsvc.go

+99-27
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2021 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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package namespace
186

@@ -33,14 +21,43 @@ type SupervisorServiceSummary struct {
3321

3422
// SupervisorServiceInfo for a supervisor service existent in vSphere.
3523
type SupervisorServiceInfo struct {
36-
Name string `json:"display_name"`
37-
State string `json:"state"`
38-
Description string `json:"description"`
24+
Name string `json:"display_name"`
25+
State string `json:"state"`
26+
Description string `json:"description"`
27+
MustBeInstalled bool `json:"must_be_installed"`
28+
HasDefaultVersionsRegistered bool `json:"has_default_versions_registered"`
29+
}
30+
31+
// SupervisorServiceVersionSummary describes a vSphere Supervisor Service version.
32+
type SupervisorServiceVersionSummary struct {
33+
SupervisorServiceInfo
34+
Version string `json:"version"`
35+
}
36+
37+
// SupervisorServiceVersionInfo details a vSphere Supervisor Service version.
38+
type SupervisorServiceVersionInfo struct {
39+
SupervisorServiceInfo
40+
Eula string `json:"EULA"`
41+
Content string `json:"content"`
42+
ContentType string `json:"content_type"`
43+
TrustVerified bool `json:"trust_verified"`
44+
RegisteredByDefault bool `json:"registered_by_default"`
3945
}
4046

4147
// SupervisorService defines a new SupervisorService specification
4248
type SupervisorService struct {
43-
VsphereService SupervisorServicesVSphereSpec `json:"vsphere_spec,omitempty"`
49+
// The specification required to create a Supervisor Service with a version from inline content that is based on the vSphere application service format.
50+
VsphereService *SupervisorServicesVSphereSpec `json:"vsphere_spec,omitempty"`
51+
// The specification required to create a Supervisor Service with a version from inline content that is based on the Carvel application package format.
52+
CarvelService *SupervisorServicesCarvelSpec `json:"carvel_spec,omitempty"`
53+
}
54+
55+
// SupervisorServiceVersion defines a new SupervisorService version specification
56+
type SupervisorServiceVersion struct {
57+
// The specification required to create a Supervisor Service with a version from inline content that is based on the vSphere application service format.
58+
VsphereService *SupervisorServicesVSphereVersionCreateSpec `json:"vsphere_spec,omitempty"`
59+
// The specification required to create a Supervisor Service with a version from inline content that is based on the Carvel application package format.
60+
CarvelService *CarvelVersionCreateSpec `json:"carvel_spec,omitempty"`
4461
}
4562

4663
// SupervisorServicesVSphereSpec defines a new SupervisorService specification of vSphere type
@@ -55,20 +72,32 @@ type SupervisorServicesVSphereVersionCreateSpec struct {
5572
AcceptEula bool `json:"accept_EULA,omitempty"`
5673
}
5774

58-
// CreateSupervisorService creates a new Supervisor Service on vSphere Namespaces endpoint.
75+
// The “SupervisorServicesCarvelSpec“ class provides a specification required to create a Supervisor Service with a version from Carvel application package format (Package and PackageMetadata resources should be declared).
76+
type SupervisorServicesCarvelSpec struct {
77+
// Supervisor service version specification that provides the service definitions for one Supervisor Service version.
78+
VersionSpec CarvelVersionCreateSpec `json:"version_spec"`
79+
}
80+
81+
// The “CarvelVersionCreateSpec“ class provides a specification required to create a Supervisor Service version from Carvel application package format (Package and PackageMetadata resources should be declared).
82+
type CarvelVersionCreateSpec struct {
83+
// Inline content that contains all service definition of the version in Carvel application package format, which shall be base64 encoded.
84+
Content string `json:"content"`
85+
}
86+
87+
// CreateSupervisorService creates a new Supervisor Service on vCenter.
5988
func (c *Manager) CreateSupervisorService(ctx context.Context, service *SupervisorService) error {
6089
url := c.Resource(internal.SupervisorServicesPath)
6190
return c.Do(ctx, url.Request(http.MethodPost, service), nil)
6291
}
6392

64-
// ListSupervisorServices returns a summary of all clusters with vSphere Namespaces enabled.
93+
// ListSupervisorServices returns a summary of registered Supervisor Services.
6594
func (c *Manager) ListSupervisorServices(ctx context.Context) ([]SupervisorServiceSummary, error) {
6695
var res []SupervisorServiceSummary
6796
url := c.Resource(internal.SupervisorServicesPath)
6897
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
6998
}
7099

71-
// GetSupervisorService gets the information of a specific supervisor service.
100+
// GetSupervisorService gets the information of a specific Supervisor Service.
72101
func (c *Manager) GetSupervisorService(ctx context.Context, id string) (SupervisorServiceInfo, error) {
73102
var res SupervisorServiceInfo
74103
url := c.Resource(path.Join(internal.SupervisorServicesPath, id))
@@ -78,20 +107,63 @@ func (c *Manager) GetSupervisorService(ctx context.Context, id string) (Supervis
78107
// ActivateSupervisorServices activates a previously registered Supervisor Service.
79108
func (c *Manager) ActivateSupervisorServices(ctx context.Context, id string) error {
80109
url := c.Resource(path.Join(internal.SupervisorServicesPath, id)).WithParam("action", "activate")
81-
err := c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
82-
return err
110+
return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
83111
}
84112

85113
// DeactivateSupervisorServices deactivates a previously registered Supervisor Service.
86114
func (c *Manager) DeactivateSupervisorServices(ctx context.Context, id string) error {
87115
url := c.Resource(path.Join(internal.SupervisorServicesPath, id)).WithParam("action", "deactivate")
88-
err := c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
89-
return err
116+
return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
90117
}
91118

92-
// RemoveSupervisorService removes a previously deactivated supervisor service.
119+
// RemoveSupervisorService removes a previously deactivated Supervisor Service.
93120
func (c *Manager) RemoveSupervisorService(ctx context.Context, id string) error {
94121
url := c.Resource(path.Join(internal.SupervisorServicesPath, id))
95122
err := c.Do(ctx, url.Request(http.MethodDelete, nil), nil)
96123
return err
97124
}
125+
126+
// ListSupervisorServiceVersions lists all versions of the given Supervisor Service.
127+
// https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/get/
128+
func (c *Manager) ListSupervisorServiceVersions(ctx context.Context, id string) ([]SupervisorServiceVersionSummary, error) {
129+
var res []SupervisorServiceVersionSummary
130+
url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath))
131+
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
132+
}
133+
134+
// RemoveSupervisorServiceVersion removes a previously deactivated Supervisor Service version.
135+
// https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/version/delete/
136+
func (c *Manager) RemoveSupervisorServiceVersion(ctx context.Context, id string, version string) error {
137+
url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version))
138+
err := c.Do(ctx, url.Request(http.MethodDelete, nil), nil)
139+
return err
140+
}
141+
142+
// CreateSupervisorServiceVersion creates a new version for an existing Supervisor Service.
143+
// https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/post/
144+
func (c *Manager) CreateSupervisorServiceVersion(ctx context.Context, id string, service *SupervisorServiceVersion) error {
145+
url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath))
146+
return c.Do(ctx, url.Request(http.MethodPost, service), nil)
147+
}
148+
149+
// DeactivateSupervisorServiceVersion deactivates a version of an existing Supervisor Service.
150+
// https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/versionactiondeactivate/patch/
151+
func (c *Manager) DeactivateSupervisorServiceVersion(ctx context.Context, id string, version string) error {
152+
url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version)).WithParam("action", "deactivate")
153+
return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
154+
}
155+
156+
// ActivateSupervisorServiceVersion activates a version of an existing Supervisor Service.
157+
// https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/versionactiondeactivate/patch/
158+
func (c *Manager) ActivateSupervisorServiceVersion(ctx context.Context, id string, version string) error {
159+
url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version)).WithParam("action", "activate")
160+
return c.Do(ctx, url.Request(http.MethodPatch, nil), nil)
161+
}
162+
163+
// GetSupervisorServiceVersion gets the information of a specific Supervisor Service version.
164+
// https://developer.broadcom.com/xapis/vsphere-automation-api/8.0.3/vcenter/api/vcenter/namespace-management/supervisor-services/supervisor_service/versions/version/get/
165+
func (c *Manager) GetSupervisorServiceVersion(ctx context.Context, id string, version string) (SupervisorServiceVersionInfo, error) {
166+
var res SupervisorServiceVersionInfo
167+
url := c.Resource(path.Join(internal.SupervisorServicesPath, id, internal.SupervisorServicesVersionsPath, version))
168+
return res, c.Do(ctx, url.Request(http.MethodGet, nil), &res)
169+
}

‎vapi/simulator/simulator.go

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018-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-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator
186

@@ -503,8 +491,8 @@ func (s *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
503491
return
504492
}
505493

506-
h, _ := s.ServeMux.Handler(r)
507-
h.ServeHTTP(w, r)
494+
// Use ServeHTTP directly and not via handler otherwise the path values like "{id}" are not set
495+
s.ServeMux.ServeHTTP(w, r)
508496
}
509497

510498
func (s *handler) decode(r *http.Request, w http.ResponseWriter, val interface{}) bool {

0 commit comments

Comments
 (0)
Please sign in to comment.