Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

govc: add proper VAPI for vSphere Supervisor Services #3674

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions cli/namespace/service/activate.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2021 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package service

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

func (cmd *activate) Description() string {
return `Activates a vSphere Namespace Supervisor Service.
return `Activates a vSphere Supervisor Service (and all its versions).

Examples:
govc namespace.service.activate my-supervisor-service other-supervisor-service`
68 changes: 32 additions & 36 deletions cli/namespace/service/create.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2021 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package service

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

type create struct {
*flags.ClientFlag

specType string
trustedProvider bool
acceptEULA bool
*ServiceVersionFlag
}

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

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

func (cmd *create) Description() string {
return `Creates a vSphere Namespace Supervisor Service.
return `Registers a vSphere Supervisor Service version on vCenter for a new service.
A service version can be registered once on vCenter and then be installed on multiple vSphere Supervisors managed by this vCenter.
A vSphere Supervisor Service contains a list of service versions; this call will create a service and its first version.

Examples:
govc namespace.service.create manifest.yaml`
@@ -60,30 +46,41 @@ func (cmd *create) Usage() string {
return "MANIFEST"
}

func (cmd *create) Process(ctx context.Context) error {
if err := cmd.ServiceVersionFlag.Process(ctx); err != nil {
return err
}
return cmd.ClientFlag.Process(ctx)
}

func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
manifest := f.Args()
if len(manifest) != 1 {
if f.NArg() != 1 {
return flag.ErrHelp
}

if cmd.specType != "vsphere" {
return fmt.Errorf("only vsphere specs are accepted right now")
}
manifestFile := f.Arg(0)

manifestFile, err := os.ReadFile(manifest[0])
manifest, err := os.ReadFile(manifestFile)
if err != nil {
return fmt.Errorf("failed to read manifest file: %s", err)
}
content := base64.StdEncoding.EncodeToString(manifest)

content := base64.StdEncoding.EncodeToString(manifestFile)
service := namespace.SupervisorService{
VsphereService: namespace.SupervisorServicesVSphereSpec{
service := namespace.SupervisorService{}
if cmd.ServiceVersionFlag.SpecType == "carvel" {
service.CarvelService = &namespace.SupervisorServicesCarvelSpec{
VersionSpec: namespace.CarvelVersionCreateSpec{
Content: content,
},
}
} else {
service.VsphereService = &namespace.SupervisorServicesVSphereSpec{
VersionSpec: namespace.SupervisorServicesVSphereVersionCreateSpec{
Content: content,
AcceptEula: cmd.acceptEULA,
TrustedProvider: cmd.trustedProvider,
AcceptEula: cmd.ServiceVersionFlag.AcceptEULA,
TrustedProvider: cmd.ServiceVersionFlag.TrustedProvider,
},
},
}
}

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

m := namespace.NewManager(c)
return m.CreateSupervisorService(ctx, &service)

}
20 changes: 4 additions & 16 deletions cli/namespace/service/deactivate.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2021 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package service

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

func (cmd *deactivate) Description() string {
return `Deactivates a vSphere Namespace Supervisor Service.
return `Deactivates a vSphere Supervisor Service (and all its versions).

Examples:
govc namespace.service.deactivate my-supervisor-service other-supervisor-service`
63 changes: 63 additions & 0 deletions cli/namespace/service/flag.go
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
}
21 changes: 4 additions & 17 deletions cli/namespace/service/info.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2021-2023 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package service

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

func (cmd *info) Description() string {
return `Gets information of a specific supervisor service.
return `Gets information of a specific vSphere Supervisor Service.

Examples:
govc namespace.service.info my-supervisor-service
@@ -73,7 +61,6 @@ func (r *infoWriter) Write(w io.Writer) error {
fmt.Fprintf(tw, "%s", r.Service.Name)
fmt.Fprintf(tw, "\t%s", r.Service.State)
fmt.Fprintf(tw, "\t%s", r.Service.Description)

fmt.Fprintf(tw, "\n")

return tw.Flush()
20 changes: 4 additions & 16 deletions cli/namespace/service/ls.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2021-2023 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package service

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

func (cmd *ls) Description() string {
return `List namepace registered supervisor services.
return `List all registered vSphere Supervisor Services.

Examples:
govc namespace.service.ls
21 changes: 5 additions & 16 deletions cli/namespace/service/rm.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*
Copyright (c) 2021 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: Apache-2.0

package service

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

func (cmd *rm) Description() string {
return `Removes a vSphere Namespace Supervisor Service.
return `Removes a vSphere Supervisor Service.
Note that a service must be deactivated and all versions must be removed before being deleted.

Examples:
govc namespace.service.rm my-supervisor-service other-supervisor-service`
57 changes: 57 additions & 0 deletions cli/namespace/service/version/activate.go
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)
}
Loading