-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3377 from stoyanzhelyazkov/feature/cluster-enable…
…-lcm Add APIs for vLCM enablement on a cluster and base ESXi image selection
- Loading branch information
Showing
11 changed files
with
742 additions
and
57 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
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)) | ||
} | ||
} |
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,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) | ||
} |
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,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 | ||
} | ||
} |
Oops, something went wrong.