Skip to content

Commit

Permalink
Merge pull request #3377 from stoyanzhelyazkov/feature/cluster-enable…
Browse files Browse the repository at this point in the history
…-lcm

Add APIs for vLCM enablement on a cluster and base ESXi image selection
  • Loading branch information
spacegospod authored Mar 5, 2024
2 parents c676481 + 7550554 commit ce4bd63
Show file tree
Hide file tree
Showing 11 changed files with 742 additions and 57 deletions.
80 changes: 80 additions & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ but appear via `govc $cmd -h`:
- [cluster.add](#clusteradd)
- [cluster.change](#clusterchange)
- [cluster.create](#clustercreate)
- [cluster.draft.baseimage.info](#clusterdraftbaseimageinfo)
- [cluster.draft.baseimage.set](#clusterdraftbaseimageset)
- [cluster.draft.commit](#clusterdraftcommit)
- [cluster.draft.component.add](#clusterdraftcomponentadd)
- [cluster.draft.component.info](#clusterdraftcomponentinfo)
Expand Down Expand Up @@ -70,6 +72,8 @@ but appear via `govc $cmd -h`:
- [cluster.rule.remove](#clusterruleremove)
- [cluster.stretch](#clusterstretch)
- [cluster.usage](#clusterusage)
- [cluster.vlcm.enable](#clustervlcmenable)
- [cluster.vlcm.info](#clustervlcminfo)
- [datacenter.create](#datacentercreate)
- [datacenter.info](#datacenterinfo)
- [datastore.cluster.change](#datastoreclusterchange)
Expand Down Expand Up @@ -343,6 +347,7 @@ but appear via `govc $cmd -h`:
- [vcsa.shutdown.poweroff](#vcsashutdownpoweroff)
- [vcsa.shutdown.reboot](#vcsashutdownreboot)
- [version](#version)
- [vlcm.depot.baseimages.ls](#vlcmdepotbaseimagesls)
- [vlcm.depot.offline.create](#vlcmdepotofflinecreate)
- [vlcm.depot.offline.info](#vlcmdepotofflineinfo)
- [vlcm.depot.offline.ls](#vlcmdepotofflinels)
Expand Down Expand Up @@ -502,6 +507,37 @@ Options:
-folder= Inventory folder [GOVC_FOLDER]
```

## cluster.draft.baseimage.info

```
Usage: govc cluster.draft.baseimage.info [OPTIONS] CLUSTER
Displays the base image version of a software draft.
Examples:
govc cluster.draft.baseimage.info -cluster-id=domain-c21 -draft-id=13
Options:
-cluster-id= The identifier of the cluster.
-draft-id= The identifier of the software draft.
```

## cluster.draft.baseimage.set

```
Usage: govc cluster.draft.baseimage.set [OPTIONS] CLUSTER
Sets the ESXi base image on the software draft.
Examples:
govc cluster.draft.baseimage.set -cluster-id=domain-c21 -draft-id=31
Options:
-cluster-id= The identifier of the cluster.
-draft-id= The identifier of the software draft.
-version= The identifier of the ESXi image version.
```

## cluster.draft.commit

```
Expand Down Expand Up @@ -1019,6 +1055,37 @@ Options:
-S=false Exclude host local storage
```

## cluster.vlcm.enable

```
Usage: govc cluster.vlcm.enable [OPTIONS] CLUSTER
Enables vLCM on the provided cluster
This operation is irreversible
Examples:
govc cluster.vlcm.enable -cluster-id=domain-c21
Options:
-cluster-id= The identifier of the cluster.
-skip-check=false Whether to skip the software check after enabling vLCM
```

## cluster.vlcm.info

```
Usage: govc cluster.vlcm.info [OPTIONS] CLUSTER
Displays the software management status of a cluster.
Examples:
govc cluster.vlcm.info -cluster-id=domain-c21
Options:
-cluster-id= The identifier of the cluster.
```

## datacenter.create

```
Expand Down Expand Up @@ -5815,6 +5882,19 @@ Options:
-require= Require govc version >= this value
```

## vlcm.depot.baseimages.ls

```
Usage: govc vlcm.depot.baseimages.ls [OPTIONS] VLCM
Displays the list of available ESXi base images.
Examples:
govc vlcm.depot.baseimages.ls
Options:
```

## vlcm.depot.offline.create

```
Expand Down
95 changes: 95 additions & 0 deletions govc/cluster/draft/baseimage/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
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 draft

import (
"context"
"flag"
"io"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vapi/esx/settings/clusters"
)

type infoResult clusters.SettingsBaseImageInfo

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

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

clusterId string
draftId string
}

func init() {
cli.Register("cluster.draft.baseimage.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)

f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.")
}

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 "CLUSTER"
}

func (cmd *info) Description() string {
return `Displays the base image version of a software draft.
Examples:
govc cluster.draft.baseimage.info -cluster-id=domain-c21 -draft-id=13`
}

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

if err != nil {
return err
}

dm := clusters.NewManager(rc)

if d, err := dm.GetSoftwareDraftBaseImage(cmd.clusterId, cmd.draftId); err != nil {
return err
} else {
if !cmd.All() {
cmd.JSON = true
}
return cmd.WriteResult(infoResult(d))
}
}
74 changes: 74 additions & 0 deletions govc/cluster/draft/baseimage/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
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 draft

import (
"context"
"flag"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vapi/esx/settings/clusters"
)

type set struct {
*flags.ClientFlag

clusterId string
draftId string
version string
}

func init() {
cli.Register("cluster.draft.baseimage.set", &set{})
}

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

f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
f.StringVar(&cmd.draftId, "draft-id", "", "The identifier of the software draft.")
f.StringVar(&cmd.version, "version", "", "The identifier of the ESXi image version.")
}

func (cmd *set) Process(ctx context.Context) error {
return cmd.ClientFlag.Process(ctx)
}

func (cmd *set) Usage() string {
return "CLUSTER"
}

func (cmd *set) Description() string {
return `Sets the ESXi base image on the software draft.
Examples:
govc cluster.draft.baseimage.set -cluster-id=domain-c21 -draft-id=31`
}

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

if err != nil {
return err
}

dm := clusters.NewManager(rc)

return dm.SetSoftwareDraftBaseImage(cmd.clusterId, cmd.draftId, cmd.version)
}
82 changes: 82 additions & 0 deletions govc/cluster/vlcm/enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
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 vlcm

import (
"context"
"flag"

"github.com/vmware/govmomi/vapi/cis/tasks"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vapi/esx/settings/clusters"
)

type enable struct {
*flags.ClientFlag

clusterId string
skipCheck bool
}

func init() {
cli.Register("cluster.vlcm.enable", &enable{})
}

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

f.StringVar(&cmd.clusterId, "cluster-id", "", "The identifier of the cluster.")
f.BoolVar(&cmd.skipCheck, "skip-check", false, "Whether to skip the software check after enabling vLCM")
}

func (cmd *enable) Process(ctx context.Context) error {
return cmd.ClientFlag.Process(ctx)
}

func (cmd *enable) Usage() string {
return "CLUSTER"
}

func (cmd *enable) Description() string {
return `Enables vLCM on the provided cluster
This operation is irreversible
Examples:
govc cluster.vlcm.enable -cluster-id=domain-c21`
}

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

if err != nil {
return err
}

dm := clusters.NewManager(rc)

if taskId, err := dm.EnableSoftwareManagement(cmd.clusterId, cmd.skipCheck); err != nil {
return err
} else if _, err := tasks.NewManager(rc).WaitForCompletion(ctx, taskId); err != nil {
return err
} else {
return nil
}
}
Loading

0 comments on commit ce4bd63

Please sign in to comment.