Skip to content

Commit 81828ed

Browse files
committed
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 <[email protected]>
1 parent 8eb362f commit 81828ed

File tree

20 files changed

+941
-216
lines changed

20 files changed

+941
-216
lines changed

cli/namespace/service/activate.go

Lines changed: 4 additions & 16 deletions
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

Lines changed: 32 additions & 36 deletions
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

Lines changed: 4 additions & 16 deletions
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

Lines changed: 63 additions & 0 deletions
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

Lines changed: 4 additions & 17 deletions
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

Lines changed: 4 additions & 16 deletions
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

Lines changed: 5 additions & 16 deletions
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`
Lines changed: 57 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)