-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 check` 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" } ```
- Loading branch information
Showing
20 changed files
with
898 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// © Broadcom. All Rights Reserved. | ||
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package service | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/vmware/govmomi/vapi/namespace" | ||
) | ||
|
||
// Common processing of flags for service and service versions creation/update commands. | ||
type ServiceVersionFlag struct { | ||
SpecType string | ||
TrustedProvider bool | ||
AcceptEULA bool | ||
content string | ||
} | ||
|
||
func (svf *ServiceVersionFlag) Register(ctx context.Context, f *flag.FlagSet) { | ||
f.StringVar(&svf.SpecType, "spec-type", "carvel", "Type of Spec: vsphere (deprecated) or carvel") | ||
f.BoolVar(&svf.TrustedProvider, "trusted", false, "Define if this is a trusted provider (only applicable for vSphere spec type)") | ||
f.BoolVar(&svf.AcceptEULA, "accept-eula", false, "Auto accept EULA (only required for vSphere spec type)") | ||
} | ||
|
||
func (svf *ServiceVersionFlag) Process(ctx context.Context) error { | ||
if svf.SpecType != "vsphere" && svf.SpecType != "carvel" { | ||
return fmt.Errorf("Invalid type: '%v', only 'vsphere' and 'carvel' specs are supported", svf.SpecType) | ||
} | ||
return nil | ||
} | ||
|
||
// SupervisorServiceVersionSpec returns a spec for a supervisor service version definition | ||
func (svf *ServiceVersionFlag) SupervisorServiceVersionSpec(manifestFile string) (namespace.SupervisorService, error) { | ||
service := namespace.SupervisorService{} | ||
manifest, err := os.ReadFile(manifestFile) | ||
if err != nil { | ||
return service, fmt.Errorf("failed to read manifest file: %s", err) | ||
} | ||
|
||
content := base64.StdEncoding.EncodeToString(manifest) | ||
if svf.SpecType == "carvel" { | ||
service.CarvelService = &namespace.SupervisorServicesCarvelSpec{ | ||
VersionSpec: namespace.CarvelVersionCreateSpec{ | ||
Content: content, | ||
}, | ||
} | ||
} else { | ||
service.VsphereService = &namespace.SupervisorServicesVSphereSpec{ | ||
VersionSpec: namespace.SupervisorServicesVSphereVersionCreateSpec{ | ||
Content: content, | ||
AcceptEula: svf.AcceptEULA, | ||
TrustedProvider: svf.TrustedProvider, | ||
}, | ||
} | ||
} | ||
return service, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// © Broadcom. All Rights Reserved. | ||
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package version | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"github.com/vmware/govmomi/cli" | ||
"github.com/vmware/govmomi/cli/flags" | ||
"github.com/vmware/govmomi/vapi/namespace" | ||
) | ||
|
||
type activate struct { | ||
*flags.ClientFlag | ||
} | ||
|
||
func init() { | ||
cli.Register("namespace.service.version.activate", &activate{}) | ||
} | ||
|
||
func (cmd *activate) Register(ctx context.Context, f *flag.FlagSet) { | ||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) | ||
cmd.ClientFlag.Register(ctx, f) | ||
} | ||
|
||
func (cmd *activate) Description() string { | ||
return `Activates a vSphere Supervisor Service version. | ||
Examples: | ||
govc namespace.service.version.activate my-supervisor-service 1.0.0` | ||
} | ||
|
||
func (cmd *activate) Usage() string { | ||
return "NAME VERSION" | ||
} | ||
|
||
func (cmd *activate) Run(ctx context.Context, f *flag.FlagSet) error { | ||
service := f.Arg(0) | ||
if len(service) == 0 { | ||
return flag.ErrHelp | ||
} | ||
version := f.Arg(1) | ||
if len(version) == 0 { | ||
return flag.ErrHelp | ||
} | ||
|
||
c, err := cmd.RestClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
m := namespace.NewManager(c) | ||
return m.ActivateSupervisorServiceVersion(ctx, service, version) | ||
} |
Oops, something went wrong.