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

Add VAPI bindings for guest namespaces and virtual machine classes #3397

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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
166 changes: 166 additions & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,23 @@ but appear via `govc $cmd -h`:
- [namespace.cluster.disable](#namespaceclusterdisable)
- [namespace.cluster.enable](#namespaceclusterenable)
- [namespace.cluster.ls](#namespaceclusterls)
- [namespace.create](#namespacecreate)
- [namespace.info](#namespaceinfo)
- [namespace.logs.download](#namespacelogsdownload)
- [namespace.ls](#namespacels)
- [namespace.rm](#namespacerm)
- [namespace.service.activate](#namespaceserviceactivate)
- [namespace.service.create](#namespaceservicecreate)
- [namespace.service.deactivate](#namespaceservicedeactivate)
- [namespace.service.info](#namespaceserviceinfo)
- [namespace.service.ls](#namespaceservicels)
- [namespace.service.rm](#namespaceservicerm)
- [namespace.update](#namespaceupdate)
- [namespace.vmclass.create](#namespacevmclasscreate)
- [namespace.vmclass.info](#namespacevmclassinfo)
- [namespace.vmclass.ls](#namespacevmclassls)
- [namespace.vmclass.rm](#namespacevmclassrm)
- [namespace.vmclass.update](#namespacevmclassupdate)
- [object.collect](#objectcollect)
- [object.destroy](#objectdestroy)
- [object.method](#objectmethod)
Expand Down Expand Up @@ -4271,6 +4281,41 @@ Options:
-l=false Long listing format
```

## namespace.create

```
Usage: govc namespace.create [OPTIONS]

Creates a new vSphere Namespace on a Supervisor.

Examples:
govc namespace.create -namespace=test-namespace -supervisor=domain-c1
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7,dca9cc16-9460-4da0-802c-4aa148ac6cf7
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -vm-classes=best-effort-2xlarge
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -vm-classes=best-effort-2xlarge,best-effort-4xlarge
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7,dca9cc16-9460-4da0-802c-4aa148ac6cf7 -vm-classes=best-effort-2xlarge,best-effort-4xlarge

Options:
-content-libraries= The identifiers of the content libraries to associate with the vSphere Namespace.
-namespace= The name of the vSphere Namespace.
-supervisor= The identifier of the Supervisor.
-vm-classes= The identifiers of the virtual machine classes to associate with the vSphere Namespace.
```

## namespace.info

```
Usage: govc namespace.info [OPTIONS] NAME

Displays the details of a vSphere Namespace.

Examples:
govc namespace.info test-namespace

Options:
```

## namespace.logs.download

```
Expand All @@ -4291,6 +4336,32 @@ Options:
-cluster= Cluster [GOVC_CLUSTER]
```

## namespace.ls

```
Usage: govc namespace.ls [OPTIONS]

Displays the list of vSphere Namespaces.

Examples:
govc namespace.ls

Options:
```

## namespace.rm

```
Usage: govc namespace.rm [OPTIONS] NAME

Deletes a vSphere Namespace.

Examples:
govc namespace.rm test-namespace

Options:
```

## namespace.service.activate

```
Expand Down Expand Up @@ -4373,6 +4444,101 @@ Examples:
Options:
```

## namespace.update

```
Usage: govc namespace.update [OPTIONS] NAME

Modifies an existing vSphere Namespace on a Supervisor.

Examples:
govc namespace.update -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7 test-namespace
govc namespace.update -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7,617a3ee3-a2ff-4311-9a7c-0016ccf958bd test-namespace
govc namespace.update -vm-classes=best-effort-2xlarge test-namespace
govc namespace.update -vm-classes=best-effort-2xlarge,best-effort-4xlarge test-namespace
govc namespace.update -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7,617a3ee3-a2ff-4311-9a7c-0016ccf958bd -vm-classes=best-effort-2xlarge,best-effort-4xlarge test-namespace

Options:
-content-libraries= The list of content libraries to associate with the vSphere Namespace.
-vm-classes= The list of virtual machine classes to associate with the vSphere Namespace.
```

## namespace.vmclass.create

```
Usage: govc namespace.vmclass.create [OPTIONS]

Creates a new virtual machine class.

The name of the virtual machine class has DNS_LABEL restrictions
as specified in "https://tools.ietf.org/html/rfc1123". It
must be an alphanumeric (a-z and 0-9) string and with maximum length
of 63 characters and with the '-' character allowed anywhere except
the first or last character. This name is unique in this vCenter server.

Examples:
govc namespace.vmclass.create -name=test-class-01 -cpus=8 -memory=8192

Options:
-cpus=0 The number of CPUs.
-memory=0 The amount of memory (in MB).
-name= The name of the virtual machine class.
```

## namespace.vmclass.info

```
Usage: govc namespace.vmclass.info [OPTIONS] NAME

Displays the details of a virtual machine class.

Examples:
govc namespace.vmclass.info test-class

Options:
```

## namespace.vmclass.ls

```
Usage: govc namespace.vmclass.ls [OPTIONS]

Displays the list of virtual machine classes.

Examples:
govc namespace.vmclass.ls

Options:
```

## namespace.vmclass.rm

```
Usage: govc namespace.vmclass.rm [OPTIONS] NAME

Deletes a virtual machine class.

Examples:
govc namespace.vmclass.rm test-class

Options:
```

## namespace.vmclass.update

```
Usage: govc namespace.vmclass.update [OPTIONS] NAME

Modifies an existing virtual machine class.

Examples:
govc namespace.vmclass.update -cpus=8 -memory=8192 test-class

Options:
-cpus=0 The number of CPUs.
-memory=0 The amount of memory (in MB).
```

## object.collect

```
Expand Down
2 changes: 2 additions & 0 deletions govc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ import (
_ "github.com/vmware/govmomi/govc/ls"
_ "github.com/vmware/govmomi/govc/metric"
_ "github.com/vmware/govmomi/govc/metric/interval"
_ "github.com/vmware/govmomi/govc/namespace"
_ "github.com/vmware/govmomi/govc/namespace/cluster"
_ "github.com/vmware/govmomi/govc/namespace/service"
_ "github.com/vmware/govmomi/govc/namespace/vmclass"
_ "github.com/vmware/govmomi/govc/object"
_ "github.com/vmware/govmomi/govc/option"
_ "github.com/vmware/govmomi/govc/permissions"
Expand Down
83 changes: 83 additions & 0 deletions govc/namespace/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
spacegospod marked this conversation as resolved.
Show resolved Hide resolved

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.
*/

package namespace

import (
"context"
"flag"
"strings"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vapi/namespace"
)

type create struct {
*flags.ClientFlag

libraries string
vmClasses string
spec namespace.NamespacesInstanceCreateSpec
}

func init() {
cli.Register("namespace.create", &create{})
}

func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
cmd.ClientFlag.Register(ctx, f)

f.StringVar(&cmd.spec.Cluster, "supervisor", "", "The identifier of the Supervisor.")
f.StringVar(&cmd.spec.Namespace, "namespace", "", "The name of the vSphere Namespace.")
f.StringVar(&cmd.libraries, "content-libraries", "", "The identifiers of the content libraries to associate with the vSphere Namespace.")
f.StringVar(&cmd.vmClasses, "vm-classes", "", "The identifiers of the virtual machine classes to associate with the vSphere Namespace.")
}

func (cmd *create) Process(ctx context.Context) error {
if len(cmd.libraries) > 0 {
cmd.spec.VmServiceSpec.ContentLibraries = strings.Split(cmd.libraries, ",")
}
if len(cmd.vmClasses) > 0 {
cmd.spec.VmServiceSpec.VmClasses = strings.Split(cmd.vmClasses, ",")
}
return cmd.ClientFlag.Process(ctx)
}

func (cmd *create) Description() string {
return `Creates a new vSphere Namespace on a Supervisor.

Examples:
govc namespace.create -namespace=test-namespace -supervisor=domain-c1
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7,dca9cc16-9460-4da0-802c-4aa148ac6cf7
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -vm-classes=best-effort-2xlarge
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -vm-classes=best-effort-2xlarge,best-effort-4xlarge
govc namespace.create -namespace=test-namespace -supervisor=domain-c1 -content-libraries=dca9cc16-9460-4da0-802c-4aa148ac6cf7,dca9cc16-9460-4da0-802c-4aa148ac6cf7 -vm-classes=best-effort-2xlarge,best-effort-4xlarge`
}

func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
rc, err := cmd.RestClient()

if err != nil {
return err
}

nm := namespace.NewManager(rc)

return nm.CreateNamespace(ctx, cmd.spec)
}
91 changes: 91 additions & 0 deletions govc/namespace/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright (c) 2024-2024 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.
*/

package namespace

import (
"context"
"flag"
"io"

"github.com/vmware/govmomi/vapi/namespace"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
)

type infoResult namespace.NamespacesInstanceInfo

func (r infoResult) Write(w io.Writer) error {
return nil
}

type info struct {
*flags.ClientFlag
*flags.OutputFlag
}

func init() {
cli.Register("namespace.info", &info{})
}

func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
cmd.ClientFlag.Register(ctx, f)

cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
}

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

return nil
}

func (cmd *info) Usage() string {
return "NAME"
}

func (cmd *info) Description() string {
return `Displays the details of a vSphere Namespace.

Examples:
govc namespace.info test-namespace`
}

func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
rc, err := cmd.RestClient()

if err != nil {
return err
}

nm := namespace.NewManager(rc)

d, err := nm.GetNamespace(ctx, f.Arg(0))

if err != nil {
return err
}

cmd.JSON = !cmd.All()
return cmd.WriteResult(infoResult(d))
}
Loading
Loading